-
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
Update HeightControl component to label inputs #63761
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @andrew-palapa. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Hey folks, while going through my old notifications I found #48498, which was approved but never got merged. I made a clone of it, so that we can take another look and merge if necessary. Not sure if @alexstine is still around to confirm his original approving review — tagging also @WordPress/gutenberg-components @afercia and @joedolson for some feedback |
Size Change: +84 B (0%) Total Size: 1.75 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.
Looking good from my perspective and testing well.
Thanks to all contributors who helped with it, and for you taking care of it @ciampo 👍 🚀
function useUniqueId( idProp?: string ) { | ||
const id = useInstanceId( | ||
UnforwardedRangeControl, | ||
'inspector-range-control' |
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.
I wonder what this component has to do with inspector
though. Maybe not much anymore.
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.
I think that's the instance ID prefix that many components in the package adopt 😓 Not sure how easy it would be to refactor away from it, but probably not in the scope for this PR ('inspector-range-control'
is already used in trunk
and in this PR it was moved to the useUniqueId
function)
'inspector-range-control' | ||
); | ||
|
||
return idProp || id; |
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.
Do we mean to use ||
or ??
?
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.
I had that same question when reviewing the original PR, and at the time we agreed that ||
was a good choice because empty strings would not make a good id
. #48498 (comment)
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.
Also, reminder that the useInstanceId()
util supports preferredId
as the third argument. (I guess it didn't before, hence the custom logic like this in some of these older components.)
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.
I forgot about it — thank you for pointing it out!
The current method of using a fieldset for the HeightControl inputs leaves neither of them with a functioning accessible name. This change ensures both the text field and the range slider are named, and semantically linked (with the caveat that aria-controls has little support as of now).
4f55a17
to
9a97781
Compare
@ciampo I was just testing this PR while it was merged. I'm a little confused, what I see now is:
In the screenshot below I made the visually hidden labels visible to better illustrate: The range input has now: an aria-labelledby, an aria-label, and an associated label element; Aria-labelledby overrides the other twos so the accessible name is not doubled. But 3 labeling are a bit redundant: On trunk, I don't see missing labeling; Boht controls have a
Maybe a source of confusion is that a fieldset legend is not meant to label the input fields. It's meant to label the group reprezented by the fieldset. |
<fieldset className="block-editor-height-control"> | ||
<BaseControl.VisualLabel as="legend"> | ||
<div className="block-editor-height-control" id={ id }> | ||
<BaseControl.VisualLabel as="label" for={ inputId } id={ labelId }> |
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.
I guess this for
should have been htmlFor
. Getting this in the condole:
Warning: Invalid DOM property `for`. Did you mean `htmlFor`?
at label
at div
at HeightControl
etc...
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.
Yup - I must have let my guard down knowing that this PR had been reviewed before. Thank you for pointing it out
Came here to report the same warning. |
Revert PR ready #63839 The original PR had been approved and never merged, and so I thought it would been good to go. I'm fine just reverting and keeping things as before, for the time being. |
Thanks for reporting, folks, I missed the warning initially 🤔 . Fine with reverting for now. |
This is a copy of #48498 from @andrewhayward , moved to a branch on this repo (instead than a fork).
What?
Adds accessible names to both inputs in the
HeightControl
component, replacing thefieldset
wrapper and usingaria-controls
instead.Why?
Currently,
HeightControl
uses a<fieldset>
to label the input fields, but this doesn't provide an accessible name for either. Both fields should have an appropriate name.How?
RangeControl
component to accept an optional ID.<fieldset>
/<legend>
combination with a<label>
, pointing at the text input, to ensure it has an accessible name.<label>
with anaria-labelledby
to get its own accessible name.aria-controls
attribute, pointing at the text input (while acknowledging thataria-controls
has little support at the time of writing).Testing Instructions
npm run storybook:dev
HeightControl
componentTesting Instructions for Keyboard
Nothing has functionally changed, so both inputs should remain as expected