fix: select the default option across optgroups
For a dropdown whose first option is inside an <optgroup>, :selected and :checked currently miss that option, or choose a later direct option instead. An explicit selection inside a group can also incorrectly leave the first direct option selected.
Replace the selected alias with a runtime pseudo that examines direct options and options inside direct optgroups in tree order. A selected attribute anywhere in that list suppresses the implicit default. Keep explicit selected attributes, multiple-select behavior, custom pseudo overrides and adapter equality intact. No dependencies, exports, workflows or generated files change.
Add 11 regression cases covering grouped-only and mixed lists, empty groups, explicit selections in later groups, multiple selects, detached selected options and queries rooted inside an optgroup. This is one focused correction to default selection across optgroups.
Validation on macOS arm64, Node.js 24.18.1 / npm 11.16.0:
- New tests with pristine upstream implementation: 5 failed, 40 passed in the focused file.
npm test: 228 passed, 1 existing skip across 8 files; full ESLint, TypeScript and Biome checks pass.npm run buildandgit diff --check: pass.- Independent Chromium 155 checks confirm grouped-only, group-before-direct, empty-group and explicit-selection cases. Firefox and WebKit were not run.
The implementation preserves existing static behavior outside this fix. It still does not model all browser selectedness: disabled options/optgroups and size > 1 retain their existing limitations, and multiple explicit selected attributes remain matched rather than enforcing a single select's live last-selected state. General wrappers inside a select and malformed nested groups are outside this patch's direct option/optgroup traversal.
AI assistance: OpenAI Codex assisted with investigation, implementation, tests and an independent AI review. A human review has not been performed by this tool. The requested model was gpt-6.1-sol with medium reasoning; runtime metadata was not available to independently verify the actual model configuration. Hosted CI and maintainer acceptance remain pending.