Skip to content

Dialogs aria-labelledby#278

Merged
devongovett merged 10 commits into
masterfrom
dialogs-aria-labelledby
Mar 17, 2020
Merged

Dialogs aria-labelledby#278
devongovett merged 10 commits into
masterfrom
dialogs-aria-labelledby

Conversation

@snowystinger
Copy link
Copy Markdown
Member

@snowystinger snowystinger commented Mar 13, 2020

pass an id through slots to the header, if it successfully renders into the dom, label the dialog with that same id

Closes https://jira.corp.adobe.com/browse/RSP-1583

✅ Pull Request Checklist:

  • Included link to corresponding Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

Run storybook, go to dialog stories
Inspect the title of the dialog and verify that it's id is the same as the role=dialog aria-labelledby

🧢 Your Team:

…to the dom, label the dialog with that same id

export function useSlotId(): string {
let [id, setId] = useState(useId());
useLayoutEffect(() => {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is one of those times where this is the more appropriate of the two. We can change the id back to null if it isn't in the dom before the repaint. I don't know how it affects voice over though, this may still be an unnecessary optimization.

@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉

@majornista majornista self-requested a review March 13, 2020 21:01
useLayoutEffect(() => {
let setCurr = map.get(id);
if (setCurr && !document.getElementById(id)) {
setId(null);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if the id does not find a home in the DOM, we set it back to null?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

{[`spectrum-Dialog--${sizeVariant}`]: sizeVariant},
otherProps.className
)}
aria-labelledby={titleId}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the Dialog be labelled using aria-label or and explicit aria-labelledby prop, without it being overwritten as null? I'm thinking of the DatePicker use case where the DialogTrigger supplies the label for the Dialog.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this, how would it work and when would we do one vs the other?
What if there is a DialogTrigger that supplies a labelled by AND there is a title in the dialog, do we want both?
I don't think this is currently interfering with aria-label, it's only forcing aria-labelledby

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicitly setting aria-labelledby on the Dialog should take precedence.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, aria-labelledby will take precedence over aria-label, so the internally set aria-labelledby referring to the slot, will override an explicitly set aria-label on the Dialog itself.

@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉

@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉

@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉

function BaseDialog({children, slots, size, role, ...otherProps}: SpectrumBaseDialogProps) {
let ref = useRef();
let titleId = useSlotId();
titleId = otherProps['aria-label'] ? undefined : titleId;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here and below (setting aria-labelledby) should go in useDialog.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, thanks

hero: {UNSAFE_className: styles['spectrum-Dialog-hero']},
header: {UNSAFE_className: styles['spectrum-Dialog-header']},
heading: {UNSAFE_className: styles['spectrum-Dialog-heading']},
heading: {UNSAFE_className: styles['spectrum-Dialog-heading'], id: titleId},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return titleProps from useDialog with this id

ktabors
ktabors previously approved these changes Mar 16, 2020
Copy link
Copy Markdown
Collaborator

@ktabors ktabors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ktabors ktabors dismissed their stale review March 16, 2020 22:24

mistake

@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉

Copy link
Copy Markdown
Collaborator

@ktabors ktabors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉

@devongovett devongovett merged commit 1a0065d into master Mar 17, 2020
@devongovett devongovett deleted the dialogs-aria-labelledby branch March 17, 2020 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants