useAccessibleNameWarning
Warns in development when an element with role="dialog" or role="alertdialog" has no accessible name. Call it as useAccessibleNameWarning(node, component, titlePart?). Does nothing in production.
Use for
- a dev warning when an overlay part renders a dialog without a title
- checking that
aria-labelledbypoints at an element with text
Practices
| Guidance | Practice |
|---|---|
| Do | Pass titlePart when the name comes from a part other than <component>.Title, as Dialog does with Card.Title. |
| Do | Pass the mounted node, such as from a callback ref held in state, so the check runs once the element exists. |
Examples
In an overlay popup
useAccessibleNameWarning(node, 'Popover');