Notes: make the collapsed note state accessible to screen reader and keyboard users - #81459
Open
adamsilverstein wants to merge 1 commit into
Open
Notes: make the collapsed note state accessible to screen reader and keyboard users#81459adamsilverstein wants to merge 1 commit into
adamsilverstein wants to merge 1 commit into
Conversation
The "Show more" collapse used `line-clamp`, whose exposure to the accessibility tree varies between screen readers, and the toggle never announced its state. Links clipped by the collapse also stayed in the tab order, so Tab moved focus to invisible content and scrolled the clamped container out of sync with the toggle label. Swap `line-clamp` for a `max-height` clamp, give the toggle `aria-expanded` and `aria-controls`, and expand the note when focus reaches content hidden by the collapse.
|
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 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. |
|
Size Change: +434 B (+0.01%) Total Size: 7.71 MB 📦 View Changed
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Fixes #81458
Makes the collapsed state of a long note behave predictably for screen reader and keyboard users, following up on @joedolson's feedback in #72822 (comment).
Why?
The "Show more" / "Show less" collapse added in #77446 used CSS
line-clamp, and that turned up three separate problems:line-clamphides text visually but leaves it in the accessibility tree. Dumping Chromium's tree over a clamped container returned 1418 characters against 1418 characters of DOM text, so nothing was actually hidden - a screen reader reads the whole note and then meets a toggle that changes nothing it can perceive. How far a given reader gets varies, which is the unpredictability @joedolson saw in NVDA.aria-expandedand noaria-controls, so its state was never announced.kses, and a link clipped by the collapse stayed in the tab order. In a reduced case the link laid out 1131px below the clamp boundary,document.elementFromPointat its center returnednull, and one Tab press moved focus to it anyway - which then setscrollTop: 1152on theoverflow: hiddencontainer. Focus landed on invisible content and the note quietly scrolled to an arbitrary middle slice while the button still read "Show more". That part reproduces with no assistive tech at all.How?
Keeps the collapse as a visual affordance, which is what it always was, but makes it honest about that and stops it trapping focus.
line-clampfor amax-heightclamp.calc(3 * 1lh)lands exactly on three line boxes so there is no half-cut line, with a4.5emfallback for browsers without thelhunit. This also drops the dependency on a property whose accessibility-tree exposure is still settling.aria-expandedandaria-controlsto the toggle, with auseInstanceIdid on the note content it controls.focusinwithin collapsed content, so focus never rests on something clipped out of view.margin-topon the first paragraph, mirroring the existingp:last-childrule, so the clamp height lines up with three lines in both states.One tradeoff worth flagging:
-webkit-line-clampappended an ellipsis at the cut andmax-heightdoes not. Since the "Show more" button sits directly beneath the clamp, the affordance is still explicit - but that is a visible change, and reverting to an ellipsis would mean bringingline-clampback.Testing shows the AX tree was only checked in Chromium. Gecko and WebKit native trees are not reachable from Playwright, so the JAWS / VoiceOver / Orca passes @joedolson asked for still need someone with those readers.
Testing Instructions
aria-expandedand anaria-controlspointing at the note content element.New e2e coverage:
Testing Instructions for Keyboard
https://wordpress.org, so the rendered note contains a link below the collapse boundary.Screenshots or screencast
Use of AI Tools
Claude Code did the digging and the typing here, I did the asking. I will review and test.