Skip to content

Commit

Permalink
fix(Menu): stop propagation onEscape only if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
kelsos committed Jun 20, 2024
1 parent fe86af2 commit 959e741
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/components/forms/select/RuiMenuSelect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ import { type ComponentMountingOptions, mount } from '@vue/test-utils';
import RuiMenuSelect from '@/components/forms/select/RuiMenuSelect.vue';
import { options } from '@/__test__/options';

vi.spyOn(window, 'requestAnimationFrame').mockImplementation((cb) => {
const now = Date.now();
cb(now);
return now;
});

function createWrapper<T extends string | object>(options?: ComponentMountingOptions<typeof RuiMenuSelect<T>>) {
const opts: ComponentMountingOptions<typeof RuiMenuSelect<T>> = {
...options,
global: {
stubs: ['RuiProgress'],
stubs: {
RuiProgress: true,
TransitionGroup: false,
},
},
};
return mount(RuiMenuSelect, opts);
Expand Down
7 changes: 5 additions & 2 deletions src/components/overlays/menu/RuiMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ const { width } = useElementSize(activator);
const click = ref<boolean>(false);
function onLeave() {
function onLeave(event?: KeyboardEvent) {
if (!get(open))
return;
onClose();
set(click, false);
event?.stopPropagation();
}
function checkClick() {
Expand Down Expand Up @@ -142,7 +145,7 @@ const { hasError, hasSuccess } = useFormTextDetail(
</script>

<template>
<div @keydown.esc.exact.stop="onLeave()">
<div @keydown.esc="onLeave()">
<div
ref="activator"
:class="[css.wrapper, wrapperClass, { 'w-full': fullWidth }]"
Expand Down

0 comments on commit 959e741

Please sign in to comment.