Skip to content

TabPanel ID's are partially undefined when rendered before TabList #8453

Open
@rvanlaarhoven

Description

@rvanlaarhoven

Provide a general summary of the issue here

When rendering the <TabPanel> components before the <TabList>, the ID's of the TabPanel mismatch the aria-controls properties of the Tab's, because they don't receive the Tabs identifier as part of the ID.
Instead, it passes undefined-tabpanel-* as the id and undefined-tab-* as the aria-labelledby on the tab panels.
Users can still interact with the tabs, so the issue is hard to spot, but it will result in incorrect aria references.

It seems like currently useTabsPanel depends on the TabListState here:

export function useTabPanel<T>(props: AriaTabPanelProps, state: TabListState<T> | null, ref: RefObject<Element | null>): TabPanelAria {

🤔 Expected Behavior?

Not sure if the strict order of the components is expected behavior, but I'd expect the "tabs identifier" to be generated in the parent Tabs component and passed down to both the TabPanels and the TabList, so that the order doesn't really matter.

If it is expected to have this strict order, I'd expect some kind of notification (e.g. a console warning) saying the order is incorrect.

😯 Current Behavior

So the following example results in the correct state:

<Tabs>
  <TabList aria-label="History of Ancient Rome">
    <Tab id="FoR">Founding of Rome</Tab>
    <Tab id="MaR">Monarchy and Republic</Tab>
  </TabList>
  <TabPanel id="FoR">Arma virumque cano, Troiae qui primus ab oris.</TabPanel>
  <TabPanel id="MaR">Senatus Populusque Romanus.</TabPanel>
</Tabs>

while the following example will result in an incorrect state:

<Tabs>
  <TabPanel id="FoR">Arma virumque cano, Troiae qui primus ab oris.</TabPanel>
  <TabPanel id="MaR">Senatus Populusque Romanus.</TabPanel>
  <TabList aria-label="History of Ancient Rome">
    <Tab id="FoR">Founding of Rome</Tab>
    <Tab id="MaR">Monarchy and Republic</Tab>
  </TabList>
</Tabs>

💁 Possible Solution

No response

🔦 Context

No response

🖥️ Steps to Reproduce

See a reproduction here: https://codesandbox.io/p/devbox/quirky-cloud-yxs4vl. The tab panel elements receive id="undefined-tabpanel-FoR" aria-labelledby="undefined-tab-FoR"

Version

react-aria-components@v1.10.1

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

MacOS

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

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