charlie-yao / react-aria-widgets

Implementations of WAI-ARIA widgets and design patterns in React.
MIT License
2 stars 0 forks source link

Check for bad IDs in an accordion's initialExpanded/initialDisabled #166

Open charlie-yao opened 1 year ago

charlie-yao commented 1 year ago

Right now, we can't really check if an accordion's initialExpanded or initialDisabled contain strings that don't actually pertain to an accordion section ID.

The issue is, right now, useAccordion doesn't know who its accordion sections are during the initial render. It only has some recognition of them once they are individually mounted and run the callback ref. Hypothetically, useAccordion could have some array in React's state and push to that array every time a section is mounted and runs the callback. But that would mean re-rendering the entire accordion each time a section is mounted, which seems not ideal.

Because we don't know who the sections are, we can't check for bad IDs when using initialExpanded or initialDisabled. Say allowMultiple === true and someone passes in an initialExpanded with multiple strings. Right now, we simply initialize the state by getting rid of all of the elements except for the first one. If someone accidentally passes in bad IDs, whichever section they wanted to be expanded won't be.