tannerlinsley / react-show

⚛️ A 3kb css animation component for React.
https://codesandbox.io/s/2v66j7pm8y
402 stars 30 forks source link

Not possible to know when children are mounted for a11y focus-management #15

Open chrisjpatty opened 5 years ago

chrisjpatty commented 5 years ago

When expanding or collapsing elements which contain inputs, it's a common accessibility pattern to focus the first focusable element. However, when I set the state to show, even when using the setState callback, the elements still haven't been mounted. This makes it not possible to reliably focus the first element. Can I propose an onMount event prop of some kind, that signals the parent component when the children have actually been mounted? If that sounds acceptable I'd be happy to look at creating a pull request myself. Thanks for all the hard work on this package!

chrisjpatty commented 5 years ago

BTW, the workaround for this was to put an arbitrary component inside the html of the children that calls an event handler when it mounts. That works for this case, but it would be nice to have that API exposed by the Animate component itself.