From ac718c6cd6256737db2d1cfd6576f8d6c1eb2901 Mon Sep 17 00:00:00 2001 From: Matt Van Horn Date: Wed, 1 Apr 2026 12:15:46 -0700 Subject: [PATCH] fix: add dev warning when dialog has no accessible title (#9819) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: add dev warning when dialog has no accessible title When a dialog is rendered without an aria-label, aria-labelledby, or a visible title element, emit a console.warn in development mode to help developers catch this common accessibility mistake early. The warning fires once per dialog instance and is tree-shaken in production builds. Co-Authored-By: Claude Opus 4.6 * fix(dialog): resolve test failures in dialog title dev warning Check the DOM element directly for aria-label/aria-labelledby attributes instead of relying on hook props, since wrapper components (e.g. RAC Dialog) may add aria-labelledby from context after useDialog runs. Add the warning pattern to the allowed warnings list in setupTests.js so existing tests that render dialogs without accessible labels are not broken. * fix: address review feedback - remove setupTests allowlist entry, drop 'visible' from warning Co-Authored-By: Claude Opus 4.6 (1M context) * fix: add aria-label to test dialogs that lack accessible titles Adds aria-label="Test dialog" to Dialog test renders that don't have a heading or aria-labelledby, preventing the new dev warning from failing tests via failTestOnConsoleWarn(). 9 test files fixed. Remaining failures (ContextualHelp, DatePicker, DateRangePicker, Form, ListView) have dialogs rendered indirectly through components — those need source-level changes. Co-Authored-By: Claude Opus 4.6 (1M context) * fix: check props and titleId in addition to DOM attributes for dialog warning The useEffect-based DOM check can race with useSlotId registration, causing false positives in components where a heading exists but hasn't registered yet. Co-Authored-By: Claude Opus 4.6 (1M context) * fix: add aria-label to ContextualHelp dialog and revert ineffective titleId check ContextualHelp renders
(not ), so the Dialog's useSlotId resolves to undefined and the dialog has no accessible title. Pass the variant label ("Help"/"Information") as aria-label. Reverts the !!titleId check in useDialog which didn't work because useSlotId resolves to undefined via useLayoutEffect before the warning's useEffect runs. Co-Authored-By: Claude Opus 4.6 (1M context) * fix contextual help usage --------- Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 Co-authored-by: Robert Snow Co-authored-by: Robert Snow --- .../test/actiongroup/ActionGroup.test.js | 2 +- .../contextualhelp/ContextualHelp.test.js | 18 +++---- .../test/dialog/Dialog.ssr.test.js | 2 +- .../react-spectrum/test/dialog/Dialog.test.js | 6 +-- .../test/dialog/DialogTrigger.test.js | 52 +++++++++---------- .../react-spectrum/test/form/Form.test.js | 4 +- .../react-spectrum/test/menu/Menu.test.js | 2 +- .../test/overlays/Popover.test.js | 2 +- .../react-spectrum/test/overlays/Tray.test.js | 2 +- packages/react-aria/src/dialog/useDialog.ts | 22 ++++++++ .../test/aria-modal-polyfill/index.test.tsx | 8 +-- .../react-aria/test/dialog/useDialog.test.js | 52 ++++++++++++++++--- .../test/interactions/useHover.test.js | 2 +- .../test/interactions/usePress.test.js | 2 +- 14 files changed, 119 insertions(+), 57 deletions(-) diff --git a/packages/@adobe/react-spectrum/test/actiongroup/ActionGroup.test.js b/packages/@adobe/react-spectrum/test/actiongroup/ActionGroup.test.js index 409f2ccc128..9a41b177496 100644 --- a/packages/@adobe/react-spectrum/test/actiongroup/ActionGroup.test.js +++ b/packages/@adobe/react-spectrum/test/actiongroup/ActionGroup.test.js @@ -575,7 +575,7 @@ describe('ActionGroup', function () { Hi - + I'm a dialog diff --git a/packages/@adobe/react-spectrum/test/contextualhelp/ContextualHelp.test.js b/packages/@adobe/react-spectrum/test/contextualhelp/ContextualHelp.test.js index d8b5a2252b6..3f48067ae6b 100644 --- a/packages/@adobe/react-spectrum/test/contextualhelp/ContextualHelp.test.js +++ b/packages/@adobe/react-spectrum/test/contextualhelp/ContextualHelp.test.js @@ -14,7 +14,7 @@ import {act, pointerMap, render, simulateDesktop} from '@react-spectrum/test-uti import {Content} from '../../src/view/Content'; import {ContextualHelp} from '../../src/contextualhelp/ContextualHelp'; import {Footer} from '../../src/view/Footer'; -import {Header} from '../../src/view/Header'; +import {Heading} from '../../src/text/Heading'; import {Link} from '../../src/link/Link'; import {Provider} from '../../src/provider/Provider'; import React from 'react'; @@ -39,7 +39,7 @@ describe('ContextualHelp', function () { let {getByRole, queryByRole} = render( -
Test title
+ Test title
); @@ -56,7 +56,7 @@ describe('ContextualHelp', function () { let {getByRole, queryByRole, getByTestId, getByText} = render( -
Test title
+ Test title
); @@ -84,7 +84,7 @@ describe('ContextualHelp', function () { let {getByRole, getByText} = render( -
Test title
+ Test title Help content
@@ -109,7 +109,7 @@ describe('ContextualHelp', function () { let {getByRole, getByText} = render( -
Test title
+ Test title Help content