Font Library: Fix checkboxes labeling in the Fonts modal dialog #58299
Labels
[Feature] Font Library
[Feature] Typography
Font and typography-related issues and PRs
[Focus] Accessibility (a11y)
Changes that impact accessibility and need corresponding review (e.g. markup changes).
[Type] Bug
An existing feature does not function as intended
Description
Noticed while reviewing #58212
To recap some HTML basics:
The HTML
<label>
element can be associated to a form control in two ways:for
attribute that references theid
attribute of the form control. This is sometimes called 'explicit labeling'.<label>
element. This is sometimes called 'imnplicit labeling'.It's a either / or. Never do both things.
The WordPress accessibility best practices recommend explicit labeling with for / id attributes. See https://make.wordpress.org/accessibility/handbook/markup/core-accessibility-standards/#labeling
In the Fonts modal the checkboxes for the fonts use both explicit and implicit label, that is: the
<label>
element wraps the checkbox and also used for / id attributes. I do realie the intent was to make the entire font row clickable but this needs to be changed.Also, the editor components come with built-in handling of labeling mechanism. I'm not sure altering the default behavior of the components in such a way is in line with the whole purpose of using reusable components. This kind of override of the default behavior should not be allowed. Moreover, setting the label prop to false
label={ false }
seems to me something that should not be allowed. I could find only two occurrences oflabel={ false }
in the codebase, both in the fonts modal dialog, plus a related test.Cc @ciampo I'm not sure I understand why a
false
value is allowed, it doesn't seem to me the best way to make sure inputs are properly labeled. This issue proves that if we make the component accept a false value, there are chances that developers will end up using the component in incorrect ways. Not to mention theBaseControl
andInputControl
label prop is typed toReactNode
and instead accepts alsofalse
?Related code to fix:
gutenberg/packages/edit-site/src/components/global-styles/font-library-modal/collection-font-variant.js
Lines 38 to 52 in ddde310
and
gutenberg/packages/edit-site/src/components/global-styles/font-library-modal/library-font-variant.js
Lines 48 to 62 in ddde310
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: