Repository navigation
test(text-field): add gen2 a11y spec and dedicated VRT stories #6797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aramos-adobe
merged 6 commits into
miwha/swc-2323-text-field-migration
from
miwha/swc-2328-textfield-test
Oct 7, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
33e4ab2
test(text-field): add gen2 a11y spec and dedicated VRT stories
aramos-adobe f98a5e8
test(text-field): update vrt and a11y specs
aramos-adobe 7a91e4d
test(text-field): add descriptive assertion messages
aramos-adobe 5c52092
test(text-field): avoid unsupported required ARIA state
aramos-adobe 83f9bc4
test(text-field): adding vrt cases and distinguish disabled states
aramos-adobe a83f208
test(text-field): update custom properties and vrt test cases
aramos-adobe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
276 changes: 276 additions & 0 deletions
276
gen2/packages/swc/components/text-field/test/text-field.a11y.spec.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,276 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { expect, test } from '@playwright/test'; | ||
|
|
||
| import { gotoStory } from '../../../utils/a11y-helpers.js'; | ||
|
|
||
| /** | ||
| * Accessibility tests for the gen2 Text Field component. | ||
| * | ||
| * ARIA snapshot tests validate the accessibility tree (the `textbox` role, | ||
| * its accessible name, and its description) across every labelling source, | ||
| * size, label position, necessity indicator, prefix, and state the stories | ||
| * cover. aXe WCAG compliance and color-contrast checks run via | ||
| * test-storybook (see .storybook/test-runner.ts). | ||
| * | ||
| * The component sets `delegatesFocus: true`, so tab focus lands on the | ||
| * internal `<input>`. Keyboard-interaction tests exercise that contract | ||
| * with real trusted input. | ||
| */ | ||
|
|
||
| test.describe('Text field - ARIA Snapshots', () => { | ||
| test('exposes a textbox with the slotted label as its name', async ({ | ||
| page, | ||
| }) => { | ||
| const root = await gotoStory( | ||
| page, | ||
| 'components-text-field--overview', | ||
| 'swc-text-field' | ||
| ); | ||
| await expect(root).toMatchAriaSnapshot(` | ||
| - textbox "Favorite food" | ||
| `); | ||
| }); | ||
|
|
||
| test('names each anatomy variation (description and error-text)', async ({ | ||
| page, | ||
| }) => { | ||
| const root = await gotoStory( | ||
| page, | ||
| 'components-text-field--anatomy', | ||
| 'swc-text-field' | ||
| ); | ||
| await expect(root).toMatchAriaSnapshot(` | ||
| - textbox "Email address" | ||
| - textbox "Email address" | ||
| `); | ||
| }); | ||
|
|
||
| test('resolves each accessible name source (slot, accessible-label, accessible-labelledby)', async ({ | ||
| page, | ||
| }) => { | ||
| const root = await gotoStory( | ||
| page, | ||
| 'components-text-field--labelling', | ||
| 'swc-text-field' | ||
| ); | ||
| const fields = root.locator('swc-text-field'); | ||
| await expect(fields.nth(0)).toMatchAriaSnapshot(` | ||
| - textbox "Email address" | ||
| `); | ||
| await expect(fields.nth(1)).toMatchAriaSnapshot(` | ||
| - textbox "Email address" | ||
| `); | ||
| // Chromium's `ariaLabelledByElements` getter enforces a same-tree | ||
| // check, so a cross-root labelling reference does not compute a name | ||
| // for `toHaveAccessibleName` / `toMatchAriaSnapshot`. Real browsers | ||
| // and AT still announce it. Assert the mixin's actual contract: the | ||
| // referenced elements are set on the input. | ||
| const labelledbyRefText = await fields.nth(2).evaluate((field) => { | ||
| const input = (field as HTMLElement).shadowRoot?.querySelector('input'); | ||
| const refs = | ||
| (input as HTMLInputElement & { ariaLabelledByElements?: Element[] }) | ||
| ?.ariaLabelledByElements ?? null; | ||
| return refs?.map((element) => element.textContent?.trim() ?? '') ?? null; | ||
| }); | ||
| expect(labelledbyRefText).toEqual(['Billing', 'Street address']); | ||
| }); | ||
|
|
||
| test('names each textbox across sizes', async ({ page }) => { | ||
| const root = await gotoStory( | ||
| page, | ||
| 'components-text-field--sizes', | ||
| 'swc-text-field' | ||
| ); | ||
| await expect(root).toMatchAriaSnapshot(` | ||
| - textbox "Small" | ||
| - textbox "Medium" | ||
| - textbox "Large" | ||
| - textbox "Extra-large" | ||
| `); | ||
| }); | ||
|
|
||
| test('names each textbox across label positions (identical semantics)', async ({ | ||
| page, | ||
| }) => { | ||
| const root = await gotoStory( | ||
| page, | ||
| 'components-text-field--label-positions', | ||
| 'swc-text-field' | ||
| ); | ||
| await expect(root).toMatchAriaSnapshot(` | ||
| - textbox "Label on top" | ||
| - textbox "Label on side" | ||
| `); | ||
| }); | ||
|
|
||
| test('exposes an identical accessible name across necessity-indicator modes', async ({ | ||
| page, | ||
| }) => { | ||
| const root = await gotoStory( | ||
| page, | ||
| 'components-text-field--necessity-indicator', | ||
| 'swc-text-field' | ||
| ); | ||
| // The necessity-indicator span is `aria-hidden="true"` (see | ||
| // `renderNecessityIndicator` in `render-label.ts`), so the "(required)" | ||
| // and "(optional)" text is excluded from the accessible name. All three | ||
| // fields expose the same name; the mode only affects visible presentation. | ||
| await expect(root).toMatchAriaSnapshot(` | ||
| - textbox "Email address" | ||
| - textbox "Email address" | ||
| - textbox "Email address" | ||
| `); | ||
| const fields = root.locator('swc-text-field'); | ||
| await expect(fields.nth(0).locator('input')).toHaveAttribute( | ||
| 'required', | ||
| '' | ||
| ); | ||
| await expect(fields.nth(1).locator('input')).toHaveAttribute( | ||
| 'required', | ||
| '' | ||
| ); | ||
| }); | ||
|
|
||
| test('names each textbox with a leading prefix affix', async ({ page }) => { | ||
| const root = await gotoStory( | ||
| page, | ||
| 'components-text-field--prefix', | ||
| 'swc-text-field' | ||
| ); | ||
| // Prefix content is non-interactive and not part of the accessible name. | ||
| await expect(root).toMatchAriaSnapshot(` | ||
| - textbox "URL" | ||
| - textbox "Mention" | ||
| - textbox "User Email" | ||
|
nikkimk marked this conversation as resolved.
|
||
| `); | ||
| }); | ||
|
|
||
| test('reflects native form states (required / readonly / disabled / invalid)', async ({ | ||
| page, | ||
| }) => { | ||
| const root = await gotoStory( | ||
| page, | ||
| 'components-text-field--states', | ||
| 'swc-text-field' | ||
| ); | ||
| await expect(root).toMatchAriaSnapshot(` | ||
| - text: Default | ||
| - textbox "Default" | ||
| - text: Full name | ||
| - textbox "Full name" | ||
| - textbox "Read-only": Read-only value | ||
| - text: Disabled | ||
| - textbox "Disabled" [disabled]: Disabled value | ||
| - textbox "Disabled placeholder" [disabled] | ||
| - textbox "Email address" | ||
| - text: Enter a valid email address. Email address | ||
| - textbox "Email address" [disabled] | ||
| - text: We'll never share your email. | ||
|
nikkimk marked this conversation as resolved.
|
||
| `); | ||
| await expect( | ||
| root.locator('swc-text-field').nth(1).locator('input') | ||
| ).toHaveAttribute('required', ''); | ||
| }); | ||
|
|
||
| test('associates description text via aria-describedby', async ({ page }) => { | ||
| const root = await gotoStory( | ||
| page, | ||
| 'components-text-field--accessibility', | ||
| 'swc-text-field' | ||
| ); | ||
| await expect(root).toMatchAriaSnapshot(` | ||
| - text: Slotted | ||
| - code: description | ||
| - textbox "Comments" | ||
| - text: Optional; visible to your team only. | ||
| - code: accessible-describedby | ||
| - text: ": described by another element" | ||
| - paragraph: Describe the issue in as much detail as possible. | ||
| - textbox "Issue details" | ||
|
nikkimk marked this conversation as resolved.
|
||
| `); | ||
| const describedByIds = await root | ||
| .locator('swc-text-field') | ||
| .nth(1) | ||
| .locator('input') | ||
| .evaluate((input) => | ||
| (input as HTMLInputElement).ariaDescribedByElements?.map( | ||
| (element) => element.id | ||
| ) | ||
| ); | ||
| expect(describedByIds).toEqual(['accessibility-external-description']); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('Text field - Keyboard interactions', () => { | ||
| test('tab focus lands on the internal input via delegatesFocus', async ({ | ||
| page, | ||
| }) => { | ||
| await gotoStory(page, 'components-text-field--overview', 'swc-text-field'); | ||
|
|
||
| await page.keyboard.press('Tab'); | ||
|
|
||
| // The host reports as active; shadow-active is the delegated `<input>`. | ||
| const focus = await page.evaluate(() => { | ||
| const host = document.querySelector('swc-text-field'); | ||
| const shadowActive = host?.shadowRoot?.activeElement; | ||
| return { | ||
| activeTag: document.activeElement?.tagName.toLowerCase() ?? '', | ||
| shadowActiveTag: shadowActive?.tagName.toLowerCase() ?? '', | ||
| }; | ||
| }); | ||
| expect(focus.activeTag).toBe('swc-text-field'); | ||
| expect(focus.shadowActiveTag).toBe('input'); | ||
| }); | ||
|
|
||
| test('typing into the focused field updates the host value', async ({ | ||
| page, | ||
| }) => { | ||
| await gotoStory(page, 'components-text-field--overview', 'swc-text-field'); | ||
|
|
||
| // Trusted keyboard input exercises the platform's own input dispatch, | ||
| // catching regressions in the `@input` bridge that play functions | ||
| // (synthetic events) can miss. | ||
| await page.keyboard.press('Tab'); | ||
| await page.keyboard.type('hello'); | ||
|
|
||
| const value = await page.evaluate(() => { | ||
| const host = document.querySelector('swc-text-field') as HTMLElement & { | ||
| value: string; | ||
| }; | ||
| return host.value; | ||
| }); | ||
| expect(value).toBe('hello'); | ||
| }); | ||
|
|
||
| test('a disabled field is not reachable via Tab', async ({ page }) => { | ||
| await gotoStory(page, 'components-text-field--states', 'swc-text-field'); | ||
|
|
||
| for (let i = 0; i < 10; i++) { | ||
| await page.keyboard.press('Tab'); | ||
| const active = await page.evaluate(() => { | ||
| const host = document.activeElement as HTMLElement | null; | ||
| return { | ||
| tag: host?.tagName.toLowerCase() ?? '', | ||
| disabled: host?.hasAttribute('disabled') ?? false, | ||
| }; | ||
| }); | ||
| if (active.tag === 'swc-text-field') { | ||
| expect( | ||
| active.disabled, | ||
| 'Tab must never land on a disabled swc-text-field' | ||
| ).toBe(false); | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.