feat(aria-snapshot): expose aria-invalid in ARIA snapshots#40966
Conversation
Form-validation tests with ARIA snapshots could not assert on the invalid state of an input, because `aria-invalid` was not surfaced in the snapshot at all. Add an `invalid` boolean prop mirroring the existing `checked` / `disabled` / `expanded` / `level` / `pressed` shape, and emit `[invalid]` next to the role for elements whose role appears in the WAI-ARIA 1.2 list of roles that support `aria-invalid`. Treats `aria-invalid="true" | "grammar" | "spelling"` as `true` for snapshot purposes; the distinct values are still available through the existing `getAriaInvalid` helper for accessibility tree consumers. Fixes: microsoft#34839
Skn0tt
left a comment
There was a problem hiding this comment.
aria-invalid="true" | "grammar" | "spelling"all map to the boolean flag for snapshot purposes
I think we should expose the underlying range of values here, look at the pressed: true | false | mixed attribute for reference.
…hots Mirror the pressed (true/false/mixed) precedent instead of collapsing aria-invalid to a single boolean. The snapshot now surfaces the real token: a true value renders as [invalid], grammar and spelling render as [invalid=grammar] and [invalid=spelling], and a false value is omitted. The template parser, matcher, types, docs, and tests are updated to match.
|
Good call. I now expose the underlying value instead of collapsing it to a boolean, mirroring the pressed (true/false/mixed) precedent. A true value renders as [invalid], grammar and spelling render as [invalid=grammar] and [invalid=spelling], and a false value is omitted (same as pressed=false). The template parser accepts true, false, grammar, and spelling, and any other non-false value still falls back to true per the ARIA spec. I updated the types, the matcher, the docs, and extended the test to cover the grammar and spelling tokens plus the false/omitted case. I ran the aria-snapshot suite locally on chromium and all 109 tests pass (to-match-aria-snapshot.spec.ts and page-aria-snapshot.spec.ts), including the existing pressed/checked/selected tests. |
Test results for "tests others"19 flaky19863 passed, 660 skipped Merge workflow run. |
Test results for "tests 2"1 fatal errors, not part of any test 69 flaky278251 passed, 11799 skipped Merge workflow run. |
…cer microsoft#1157 / Unit L) (#8) Extends Playwright's ARIA snapshot output with two fields so an agent can distinguish "menu collapsed" from "no popup at all" and reason about MUI / Angular CDK overlay menus: haspopup Rendered as bare `[haspopup]` for `aria-haspopup="menu"` (the default value, per W3C ARIA 1.2 where `"true"` is an alias for `"menu"`). Rendered as `[haspopup=<kind>]` for `listbox`, `tree`, `grid`, `dialog`. expanded=false Explicitly rendered when `aria-expanded="false"`. The previous default omitted false-state, only emitting `[expanded]` for true — agents couldn't distinguish a collapsed disclosure from a widget with no expand/collapse affordance at all. Match templates resolve correctly: - `[haspopup]` matches an element with `aria-haspopup="menu"`. - `[haspopup=listbox]` matches only `aria-haspopup="listbox"`. - `[haspopup=true]` is normalized to `[haspopup=menu]` at parse time, matching the runtime normalization in `getAriaHaspopup()`. - Negative case: `[haspopup=menu]` does NOT match `aria-haspopup="listbox"`. Upstream's existing `[invalid]` rendering (added by microsoft#40966) is preserved — `kAriaHaspopupRoles` is gated by role, mirroring `kAriaInvalidRoles`. The `[invalid]` test suite passes unchanged. `<details>` elements (which map to `role="group"`) intentionally remain outside the explicit `[expanded=false]` rendering — `group` is not in `kAriaExpandedRoles`. The new behavior applies to widgets that genuinely have an expand/collapse affordance (button, combobox, treeitem, etc.). Test plan: - `haspopup attribute renders kind` (3 cases — bare for menu, value-suffixed for non-default kinds). - `expanded=false rendering is explicit` (button with aria-expanded="false" renders [expanded=false]). - `haspopup match-template positive and negative`. - Existing `invalid attribute` test still passes (no regression). - Existing `expanded attribute` test still passes (no regression). `npm run flint` clean. 39 / 39 in `to-match-aria-snapshot.spec.ts` pass. Independent of other Sapoto units — can land any time per PRD's implementation order. Part of Sapoto-Health/automatic-document-fetcher#1150. Closes Sapoto-Health/automatic-document-fetcher#1157.
Summary
aria-invalidin ARIA snapshots so form-validation tests can assert on the invalid state. Adds aninvalidboolean prop next to the existingchecked/disabled/expanded/level/pressedshape, and emits[invalid]for elements whose role is in the WAI-ARIA 1.2 list (textbox,combobox,checkbox,radiogroup,spinbutton, etc.).aria-invalid="true" | "grammar" | "spelling"all map to the boolean flag for snapshot purposes; the distinct values remain available through the existinggetAriaInvalidhelper for accessibility consumers.Fixes #34839