Skip to content

Incorrect aria-labelledby in useDropdownMenu() #50

Open
@catamphetamine

Description

@catamphetamine

https://github.com/react-restart/ui/blob/main/src/DropdownMenu.tsx

  const menuProps: UserDropdownMenuProps = {
    ref: setMenu || noop,
    'aria-labelledby': toggleElement?.id,
    ...popper.attributes.popper,
    style: popper.styles.popper as any,
  };

aria-labelledby is forced to be the id of the toggle element.
But that's not correct.

Consider a color selector with options:

  • Red
  • Green
  • Blue

Initially the toggler button's text is: "Select a color".

After the user selects "Green" color, the toggler button's background color becomes green and the text inside the button says: "Green".

Then the user focuses out of the toggler button, and then focuses back in.
A screen reader says: "Green".
"Green" what?

Suppose option labels are "A", "B", "X123".

A correct way would be somehow allowing a custom arial-labelledby property/option, or maybe just an addAriaLabelledBy: false opt-out flag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions