Skip to content

Commit fa5cf0e

Browse files
authored
fix(AlertDialog): preserve pointer events lock (#2692)
- πŸ› Keep absent disableOutsidePointerEvents undefined when AlertDialogContent forwards props - βœ… Add coverage for interactive alert dialog content while body is locked
1 parent eb746ad commit fa5cf0e

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

β€Žpackages/core/src/AlertDialog/AlertDialog.test.tsβ€Ž

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { VueWrapper } from '@vue/test-utils'
2-
import { findAllByText, findByText, fireEvent } from '@testing-library/vue'
2+
import { findAllByText, findByRole, findByText, fireEvent } from '@testing-library/vue'
33
import { mount } from '@vue/test-utils'
4-
import { beforeEach, describe, expect, it } from 'vitest'
4+
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
55
import { axe } from 'vitest-axe'
66
import { nextTick } from 'vue'
77
import AlertDialog from './story/_AlertDialog.vue'
@@ -15,6 +15,12 @@ describe('given a default Dialog', async () => {
1515
trigger = await findByText(wrapper.element as HTMLElement, 'Open')
1616
})
1717

18+
afterEach(() => {
19+
wrapper.unmount()
20+
document.body.innerHTML = ''
21+
document.body.style.cssText = ''
22+
})
23+
1824
it('should pass axe accessibility tests', async () => {
1925
expect(await axe(document.body)).toHaveNoViolations()
2026

@@ -37,5 +43,12 @@ describe('given a default Dialog', async () => {
3743
const cancelButton = await findAllByText(document.body, 'Cancel')
3844
expect(cancelButton.at(-1)).toBe(document.activeElement)
3945
})
46+
47+
it('should keep content interactive while body pointer events are locked', async () => {
48+
const content = await findByRole(document.body, 'alertdialog')
49+
50+
expect(document.body.style.pointerEvents).toBe('none')
51+
expect(content.style.pointerEvents).toBe('auto')
52+
})
4053
})
4154
})

β€Žpackages/core/src/AlertDialog/AlertDialogContent.vueβ€Ž

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ export interface AlertDialogContentProps extends DialogContentProps {}
2020
import { nextTick, ref } from 'vue'
2121
import { DialogContent } from '@/Dialog'
2222
23-
const props = defineProps<AlertDialogContentProps>()
23+
const props = withDefaults(defineProps<AlertDialogContentProps>(), {
24+
// Keep `undefined` (instead of Vue's boolean coercion to `false`) so
25+
// DialogContent can preserve the modal default while still honoring an
26+
// explicit `:disable-outside-pointer-events="false"`.
27+
disableOutsidePointerEvents: undefined,
28+
})
2429
const emits = defineEmits<AlertDialogContentEmits>()
2530
2631
const emitsAsProps = useEmitAsProps(emits)

0 commit comments

Comments
Β (0)