diff --git a/packages/ui-a11y-utils/src/FocusRegion.ts b/packages/ui-a11y-utils/src/FocusRegion.ts index 4f0add3680..64c0b54e28 100644 --- a/packages/ui-a11y-utils/src/FocusRegion.ts +++ b/packages/ui-a11y-utils/src/FocusRegion.ts @@ -116,6 +116,14 @@ class FocusRegion { } handleDocumentClick = (event: React.PointerEvent) => { + // Only proceed if we have a valid mouse down target from this interaction. + // This prevents dismissal when a FocusRegion is activated via keyboard + // (e.g., opening a select dropdown with keyboard) and then a click occurs + // in a parent FocusRegion before any mousedown was captured. + if (!this._documentClickTarget) { + return + } + // we used event.pointerType === 'mouse' here, but it is not supported in Safari // https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType // TODO: Check this in the future, because the linked Webkit bug is marked as fixed in 2025-09 diff --git a/packages/ui-a11y-utils/src/__tests__/FocusRegion.test.tsx b/packages/ui-a11y-utils/src/__tests__/FocusRegion.test.tsx index 29d5567308..0ab6de6a51 100644 --- a/packages/ui-a11y-utils/src/__tests__/FocusRegion.test.tsx +++ b/packages/ui-a11y-utils/src/__tests__/FocusRegion.test.tsx @@ -68,6 +68,8 @@ describe('FocusRegion', () => { const outsideElement = document.createElement('div') document.body.appendChild(outsideElement) + // Proper mousedown + click sequence (as happens in real user interactions) + fireEvent.mouseDown(outsideElement) fireEvent.click(outsideElement, { button: 0, detail: 1 }) await waitFor(() => { diff --git a/packages/ui-alerts/src/Alert/README.md b/packages/ui-alerts/src/Alert/README.md index f37010ae23..1b6d8d5e13 100644 --- a/packages/ui-alerts/src/Alert/README.md +++ b/packages/ui-alerts/src/Alert/README.md @@ -14,43 +14,33 @@ space above or below the alert. --- type: example --- -