Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(react/a11y): Tabs primitive uses malformed id values with spaces in them #5220

Open
4 tasks done
hbuchel opened this issue May 6, 2024 · 0 comments
Open
4 tasks done
Labels
accessibility Bugs or features related to accessibility bug Something isn't working good first issue Good for newcomers Primitive An issue or a feature-request for one or more UI Primitive React An issue or a feature-request for React platform

Comments

@hbuchel
Copy link
Contributor

hbuchel commented May 6, 2024

Before creating a new issue, please confirm:

On which framework/platform are you having an issue?

React

Which UI component?

Primitive components

How is your app built?

Next.js

What browsers are you seeing the problem on?

No response

Which region are you seeing the problem in?

No response

Please describe your bug.

The Tabs primitive generates ids with spaces in them.

The tabs primitive generates id attributes for the TabsPanel and TabsItems elements using the value prop which is the name of the Tab. This leads to the following markup (using the docs demo example): Note that the id for the button has a space in it as does the id it references in the aria-controls. Similarly, the id and aria-labelledby attributes have spaces in their values as well.

<div class="amplify-tabs">
  <div
    role="tablist"
    class="amplify-tabs__list"
    style="justify-content: flex-start"
  >
    <button
      role="tab"
      id="Tab 1-tab"
      aria-selected="true"
      aria-controls="Tab 1-panel"
      class="amplify-tabs__item amplify-tabs__item--active"
    >
      Tab 1</button
    >
    // ... other tab buttons
  </div>
  <div
    role="tabpanel"
    id="Tab 1-panel"
    aria-labelledby="Tab 1-tab"
    class="amplify-tabs__panel amplify-tabs__panel--active"
  >
    Tab content #1
  </div>
  // ... other tab panels
</div>

This can cause issues for assistive tech because then the tabs aren't properly associated to each other, and just generally other issues because they are not valid IDs that can be used with other javascript or CSS correctly. For example you can see in the accessibility tab for this tab panel that it can't find the correct element that aria-labelledby references so instead uses "First":

Screenshot 2024-05-06 at 6 40 46 PM

You could probably:

  1. Trim the white space for each instance where the value is used for an id id={${value.trim()}-tab} (just ok)
  2. Generate an id for each item using React.useId() to ensure each Tabs usage has unique ids for it's tab elements (probably better than using just the name of the tab)

What's the expected behaviour?

Tabs ids don't have spaces in them and tabs are programmatically linked to each other correctly

Help us reproduce the bug!

Inspect the markup for Tabs on https://ui.docs.amplify.aws/react/components/tabs

Code Snippet

// Put your code below this line.

Console log output

No response

Additional information and screenshots

No response

@github-actions github-actions bot added the pending-triage Issue is pending triage label May 6, 2024
@hbuchel hbuchel added React An issue or a feature-request for React platform Primitive An issue or a feature-request for one or more UI Primitive accessibility Bugs or features related to accessibility bug Something isn't working and removed pending-triage Issue is pending triage labels May 6, 2024
@reesscot reesscot added the good first issue Good for newcomers label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility Bugs or features related to accessibility bug Something isn't working good first issue Good for newcomers Primitive An issue or a feature-request for one or more UI Primitive React An issue or a feature-request for React platform
Projects
None yet
2 participants