feat : fermeture du MalioDrawer avec la touche Échap
This commit is contained in:
@@ -201,4 +201,17 @@ describe('MalioDrawer', () => {
|
|||||||
const wrapper = mountComponent({ modelValue: true, overlayClass: 'bg-black/70' })
|
const wrapper = mountComponent({ modelValue: true, overlayClass: 'bg-black/70' })
|
||||||
expect(wrapper.find('[data-test="backdrop"]').classes()).toContain('bg-black/70')
|
expect(wrapper.find('[data-test="backdrop"]').classes()).toContain('bg-black/70')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('closes on Escape key when closeOnEscape is true', async () => {
|
||||||
|
const wrapper = mountComponent({ modelValue: true })
|
||||||
|
await wrapper.find('[data-test="panel"]').trigger('keydown', { key: 'Escape' })
|
||||||
|
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([false])
|
||||||
|
expect(wrapper.emitted('close')).toHaveLength(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not close on Escape when closeOnEscape is false', async () => {
|
||||||
|
const wrapper = mountComponent({ modelValue: true, closeOnEscape: false })
|
||||||
|
await wrapper.find('[data-test="panel"]').trigger('keydown', { key: 'Escape' })
|
||||||
|
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
:aria-label="hasHeader ? undefined : (ariaLabel || undefined)"
|
:aria-label="hasHeader ? undefined : (ariaLabel || undefined)"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
data-test="panel"
|
data-test="panel"
|
||||||
|
@keydown="onKeydown"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
v-if="hasHeader || showClose"
|
v-if="hasHeader || showClose"
|
||||||
@@ -142,6 +143,13 @@ function onBackdropClick() {
|
|||||||
if (props.dismissable) close()
|
if (props.dismissable) close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onKeydown(e: KeyboardEvent) {
|
||||||
|
if (e.key === 'Escape' && props.closeOnEscape) {
|
||||||
|
e.stopPropagation()
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function close() {
|
function close() {
|
||||||
if (!isControlled.value) localValue.value = false
|
if (!isControlled.value) localValue.value = false
|
||||||
emit('update:modelValue', false)
|
emit('update:modelValue', false)
|
||||||
|
|||||||
Reference in New Issue
Block a user