Icon-only controls in Core: four ways of naming them #82228
Jiwoon-Kim
started this conversation in
Developer Experience
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Core renders a number of controls whose visible content is an icon and whose
accessible name therefore has to come from somewhere else. I went looking at how
each one does that, expecting small differences, and found that essentially every
one of them was solved separately.
This is an observation rather than a proposal. I have a suggestion at the end, but
the inventory is the part I am confident about.
What is there today
<button>aria-label, added only whenhasIcon<button>aria-label<button>aria-labelfrom the author's button text<a><span>text node<button role="button"><span><button>data-wp-bind--aria-labelfrom Interactivity stateFour mechanisms — a fixed
aria-label, anaria-labelderived from what the authorwrote, a visually hidden text node, and a runtime binding. The rows are rendering
paths rather than controls: Social Link appears twice because the editor and the
front end render it differently, and the lightbox row covers three buttons.
Two of those rows are worth pausing on.
Social Link is an
<a>on the front end and a<button>in the editor. Theeditor needs a button because clicking it opens the URL editor rather than
navigating, so the block renders one and duplicates the styling to keep the two
looking alike. Whatever shape a shared primitive takes, it cannot be a button-only
one.
Navigation Overlay Close ignores the author's text. In icon-only mode the
accessible name is the fixed string "Close" rather than what the author wrote. I
have opened #82227 for that
specific bug; it is small and independent of anything here.
They also disagree about styling
Navigation Overlay Close is an icon-only control that cannot receive
border,dimensionsorshadow— which is to say a theme cannot give it a shape or acontainer size, two common visual properties of an icon-only control. I do not
know whether that is deliberate.
And they disagree about how the icon itself is chosen, too: "does this control show
an icon, text, or both" is spelled
displayMode: icon|text|bothin one block,buttonUseIconin another,hasIconplusiconin a third, andshowIconplusiconPositionin a fourth.None of them use the Icon Registry
Today
wp_get_iconis called by exactly one block,core/icon. Every control inthe table above carries its own SVG. #81225
and #82062 are addressing that
for Core's internal glyphs, which is the layer underneath this discussion rather
than a duplicate of it: once those glyphs have stable identifiers, something still
has to decide what an icon-only control is.
What I think this suggests
Not a new block, at least not first. What seems missing is a shared contract that
the existing controls could adopt, naming:
text, the visible text and the accessible name should be the same value seen
twice, not two strings that can drift. The Navigation Overlay Close bug is
exactly what happens when they drift.
give a later migration stable glyph identifiers to move to; each renderer still
has to be changed to consume them.
hover/pressed/disabled — consistently, rather than whichever subset each block
happened to declare.
controls and are not the same element. Social Link is the case that rules out a
single button-shaped primitive.
Things I deliberately have not included: a tooltip contract, which brings its own
questions about touch, focus timing and
aria-describedbyversusaria-labelledby, and which an icon-only control must be complete without in anycase; and any variant vocabulary (filled, tonal, outlined), which is a design
system's business rather than Core's.
#79057 started from a
linkable Icon block, and the thread suggested shifting the use case toward Button
supporting leading, trailing and icon-only icons, raising the accessibility point
that an icon-only control needs a label. Those are suggestions in that thread
rather than a settled direction; this discussion approaches the same area from the
controls that already exist.
Where I am coming from
I maintain a block theme that implements a design system on top of Core blocks, and
the icon-only controls were where it needed the most private knowledge of Core
markup. The theme separates the three layers this discussion keeps running into —
the glyph, the control that performs an action, and the description of that action
— which is the only reason I noticed they are entangled in Core:
I am not proposing that Core adopt that system. The separation is the point, not
the visual language.
Questions
preference?
or eventually as something authors can insert?
author's own text where that text exists?
All reactions