feat: [#2387] option:checked matches a selected <option> - #2388
Open
marciomazza wants to merge 1 commit into
Open
feat: [#2387] option:checked matches a selected <option>#2388marciomazza wants to merge 1 commit into
option:checked matches a selected <option>#2388marciomazza wants to merge 1 commit into
Conversation
8 tasks
marciomazza
force-pushed
the
feat/pseudo-class-option-checked
branch
from
September 8, 2026 14:03
2bce4b1 to
eabea8b
Compare
Per spec, :checked matches a selected <option> in addition to a checked checkbox/radio <input>, but SelectorItem's 'checked' case only ever checked the INPUT tag. Attribute-driven selection (the "selected" content attribute) invalidates the query selector cache, so "option:checked" queries stay fresh. Selection changed programmatically (option.selected / select.value / select.selectedIndex) does not yet invalidate the cache - a pre-existing gap that also affects select.selectedOptions (capricorn86#1594), fixed separately.
marciomazza
force-pushed
the
feat/pseudo-class-option-checked
branch
from
September 8, 2026 14:19
eabea8b to
ab710f6
Compare
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.
Description
Resolves #2387 —
:checkedis defined to match a selected<option>, not just achecked
<input>, butoption:checkedcurrently matches nothing in happy-dom.Root cause:
SelectorItem.matchPseudoItem'scheckedcase returns a match onlywhen
tagName === 'INPUT', so an<option>always falls through tonull.Fix: the
checkedcase now also returns a match for anOPTIONelement whoseselectedistrue.Depends on #2268: without it, a cached
option:checkedresult goes stale after aprogrammatic selection change (
option.selected/select.value/select.selectedIndex) — the same cache-invalidation gap as #1594. The contentattribute path (
selected) already clears the cache, so it is correct on its own.Tests
Added 1 test in
QuerySelector.test.ts:option[value='b']:checkedis warmed withnothing selected (0 matches), then
setAttribute('selected', ''), then re-queriedand asserted to return the newly selected option — covers the new match and cache
freshness on the attribute path. Fails before, passes after. Full
npm testpasses.AI
I used Claude Code to write this, over multiple iterations. I guided and reviewed
it myself at every step.
Before submitting the PR, please make sure you do the following:
Tests
option:checkedwarmed at 0 matches, thenoption.setAttribute('selected', ''), then re-query returns 1 element with valueb. Matches the fixed behavior.npm testlocally to make sure that all tests pass before submitting the PR.Title
feat,fix,choreorBREAKING CHANGE. The issue is optional and can be omitted if the pull request does not relate to an issue.AI tools