-
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
InputControl: Add help
prop
#45931
InputControl: Add help
prop
#45931
Conversation
Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
Size Change: +20.5 kB (+2%) Total Size: 1.32 MB
ℹ️ View Unchanged
|
Instead of making |
My bad, I was overestimating the effort required to make this happen, at least in the context of this PR. It is still a bit high-effort to consolidate the I changed this PR to use BaseControl 👍 |
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.
Nicely done! Tested in Storybook (both InputControl
/ NumberControl
/ UnitControl
), works as expected 🚀
It would be even better if InputControl
could leverage BaseControl
fully, including label
and hideLabelFromVision
.
Maybe a good follow-up would be to bring the labelPosition
feature to BaseControl
, and then refactor InputControl
removing its custom implementation of label
and using instead BaseControl
?
/** | ||
* An additional description for the control. | ||
*/ | ||
help?: string; |
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.
BaseControl
's help
prop is a ReactNode
— is there any specific reason why we're using string
instead of Pick< BaseControlProps, 'help' >
?
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 was because the help
implementation in BaseControl was not marked up semantically, as @tellthemachines noted. ARIA descriptions actually require plain text. I was kind of considering removing ReactNode
support in BaseControl itself in the process of fixing the markup issue.
However, taking a better look at the codebase, there are already a good number of help
usage that include links in the text. So I'm going to suggest that we mark it up as aria-describedby
when plain text, and fall back to aria-details
when not. e4806bb
I believe it's still preferable to use aria-describedby
because aria-details
support is pretty bad.
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.
Agreed, thank you for the context! Should we mention that a plain string
of text is preferable in the help
prop description in BaseControl
?
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.
Ok, I'll add that in the follow-up when I add the semantics to BaseControl 👍
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.
Thanks for fixing this! I tested it with VoiceOver and the description is being read out correctly when the input is focused, thanks to the use of aria-describedby
✅
While working on #45364, I noticed that when adding help to the ToggleGroupControl
, there is no semantic link between the text and the control. Could we fix that (as a separate task, of course!) so that ToggleGroupControl
also uses aria-describedby
for its help text?
That would be nice, but realistically my current assessment is that it's hard to justify the effort, given our current priorities 🙁 It's not a quick low-risk refactor given the surface area, and the benefits are not very substantial at the moment. Maybe when the |
Yes, this is next on my list 👍 I'll backport the |
Required for #45364 (comment)
What?
Adds a
help
prop, similar to the one for BaseControl, on the InputControl component and friends (NumberControl, UnitControl).Why?
InputControl does not use the standard BaseControl, in order to support the
labelPosition
feature. Therefore, it needs its ownhelp
implementation.How?
Reuse the
StyledHelp
from BaseControl and add semantics.Testing Instructions
npm run storybook:dev
labelPosition
prop's value.Screenshots or screencast