-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
BaseControl: Add convenience hook to generate id-related props #46170
Conversation
We can't put this here because the prop description will be reused in child components like TextControl, where the hook stuff is irrelevant.
Size Change: +1.59 kB (0%) Total Size: 1.32 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a handy addition. Thanks @mirka 👍
✅ Unit tests pass
✅ Storybook examples work as expected
✅ Components leveraging BaseControl continue to render help text appropriately
✅ Existing controls in the editor are unaffected
✅ Readme and types match
LGTM! 🚢
…ress#46170) * Add recommendations to `help` docs * Add `useBaseControlProps` hook to simplify usage * Pass all props through hook * Update docs * Export hook * Update stories * Remove hook details from `help` docs We can't put this here because the prop description will be reused in child components like TextControl, where the hook stuff is irrelevant. * Add jsdoc to hook * Add changelog
Follow-up to #45931
What?
Adds a
useBaseControlProps
to help generate id-related props for both the BaseControl and the inner control itself.See the updated docs for how it's supposed to be used.
Why?
Right now, consumers of BaseControl are forced to generate their own unique ids, and associate the
help
text manually witharia-describedby
in a way that depends on an internal implementation detail (i.e. that thehelp
element has an${id}__help
id).I feel like the only clean way to address this would be to provide a convenience hook that would be responsible for these things. Obviously the manual way would still work, but it would be easier and less hacky if you use this hook instead.
The hook also includes the conditional logic to switch between
aria-describedby
andaria-details
depending on thehelp
value.Next steps
It isn't super high priority to migrate all the existing usage, but it would be nice to use this hook in new components, or when adding better
help
semantics to existing components that don't add anaria-describedby
at the moment (e.g. ToggleGroupControl).Testing Instructions