Repository navigation
Conversation
Browsers treat the summary of a `<details>` element like a button: `Enter` dispatches a `click` after `keypress` and `Space` dispatches a `click` after `keyup`. The `click` toggles the `<details>` element. Only the first `<summary>` child of a `<details>` element is activated. Closes testing-library#1264
Contributor
|
Thanks for the PR. Can you explain why your solution looks different than the suggested solution here #1264 (comment) ? where there places that isClickableInput is called that this shouldn't be included? |
Author
|
Good question. I didn't put it in
If you'd rather keep a single list, I can add a separate |
This branch has not been deployed
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
user.keyboard('{Enter}')anduser.keyboard(' ')on a focused<summary>now dispatch aclickon it, the way they do for a<button>. That toggles the parent<details>.Closes #1264
Why
<details> > <summary>is already focusable in user-event (FOCUSABLE_SELECTORincludesdetails > summary), but pressing Enter or Space on it does nothing, so a disclosure widget can't be tested by keyboard.Event sequence in headless Chromium 153 (Playwright
keyboard.press) on a focused<summary>:Enter:keydown,keypress,click(detail 0),keyup, thentoggleSpace:keydown,keypress,keyup,click(detail 0), thentoggle. Withkeydownonly, nothing toggles; theclickcomes onkeyup.preventDefault()onkeydownsuppresses theclickforEnter.<summary tabindex="0">(not inside a<details>) gets noclickfor either key.That matches the existing button handling:
clickafterkeypressfor Enter,clickafterkeyupfor Space.How
isSummaryForParentDetails()insrc/utils/click/. It matches only the first<summary>child of a<details>, which is the one with activation behavior per the HTML spec ("the summary for its parent details").keypressbehavior: Enter on such a summary dispatchesclick.keyupbehavior: Space on such a summary dispatchesclick.Checklist
New tests:
tests/event/behavior/keypress.tsandkeyup.ts:clickon the summary of a details element, but not on a summary outside a details element or on a second summarytests/keyboard/index.ts:[Enter]opens and[Space]closes the<details>The "on summary of details" cases and the keyboard test fail on
mainand pass with this change.What was run:
npx jest: 55 suites, 527 tests passnpm run validate(typecheck): passeseslinton the changed files: no new warningsprettier --checkon the new and test files: passesnpm run test:toolbox(Node DTL10, Node DTL8, Chrome DTL10): all new tests pass in all three environments. The Chrome conductor's hard-coded/usr/bin/chromiumwas pointed at a local Chrome for Testing build (not committed). The remaining toolbox failures on this macOS machine are the same as onmain.Not run: the CI Linux environment, Firefox/WebKit.