An open source design system that's fully customizable and agent ready
TypeScript
fix(ProgressBar): name focusable target marks (#9276)
zakelstorm6b48c6851294
diff --git a/.changeset/tidy-progress-marks.md b/.changeset/tidy-progress-marks.mdnew file mode 100644index 0000000000..7f4a87f068--- /dev/null+++ b/.changeset/tidy-progress-marks.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] ProgressBar target marks expose their label as an accessible name before the tooltip loads, while keeping keyboard focus and hover/focus tooltips.+@korkt-kimdiff --git a/packages/core/src/ProgressBar/ProgressBar.test.tsx b/packages/core/src/ProgressBar/ProgressBar.test.tsxindex 5e1e0ab6ee..257f5bd472 100644--- a/packages/core/src/ProgressBar/ProgressBar.test.tsx+++ b/packages/core/src/ProgressBar/ProgressBar.test.tsx@@ -566,7 +566,7 @@ describe('ProgressBar', () => {expect(styleClasses(accentMarks[1])).toBe(styleClasses(errorMarks[1]));});- it('renders every mark as a focusable trigger (label is required, never decorative)', () => {+ it('renders every mark as a named, focusable image before its tooltip opens', () => {const {container} = render(<ProgressBarvalue={50}@@ -579,10 +579,8 @@ describe('ProgressBar', () => {// aria-hidden and is always keyboard-focusable to reveal its label.expect(mark).not.toHaveAttribute('aria-hidden');expect(mark).toHaveAttribute('tabindex', '0');- // The name comes from the Tooltip (aria-describedby), not a role/label on- // the tick itself, so the progressbar's own subtree stays clean.- expect(mark).not.toHaveAttribute('role');- expect(mark).not.toHaveAttribute('aria-label');+ expect(mark).toHaveAttribute('role', 'img');+ expect(mark).toHaveAttribute('aria-label', 'Goal');});it('reveals a labeled mark via a focusable Tooltip trigger', async () => {@@ -593,8 +591,8 @@ describe('ProgressBar', () => {marks={[{value: 80, label: 'Goal'}]}/>,);- // Focusable so keyboard users can reveal the label; named via the- // Tooltip's aria-describedby rather than a labeled child of the bar.+ // Focusable so keyboard users can reveal the label visually; the tick+ // itself owns its name independently of the Tooltip's description.// The Tooltip loads lazily (Suspense), so re-query the live element and// wait for it to attach aria-describedby.const mark0 = container.querySelector<HTMLElement>(MARK)!;diff --git a/packages/core/src/ProgressBar/ProgressBar.tsx b/packages/core/src/ProgressBar/ProgressBar.tsxindex 12305887fd..50ca143e31 100644--- a/packages/core/src/ProgressBar/ProgressBar.tsx+++ b/packages/core/src/ProgressBar/ProgressBar.tsx@@ -611,7 +611,7 @@ export function ProgressBar({{resolvedMarks.map(mark => {// The tick element. It is both the Tooltip's anchor and the Suspense// fallback shown while the lazy Tooltip chunk loads, so the tick is- // always visible and the label attaches once ready. The list `key`+ // always visible and the tooltip attaches once ready. The list `key`// lives on the mapped <Suspense>, not here.//// `placement` is reflected as `data-placement` (and a class) so a@@ -620,6 +620,8 @@ export function ProgressBar({// for the same reason.const markEl = (<span+ role="img"+ aria-label={mark.label}tabIndex={0}{...mergeProps(themeProps('progress-bar-mark', {diff --git a/packages/core/src/ProgressBar/__tests__/ProgressBar.a11y.chromium.spec.ts b/packages/core/src/ProgressBar/__tests__/ProgressBar.a11y.chromium.spec.tsindex b4616631a2..673838700d 100644--- a/packages/core/src/ProgressBar/__tests__/ProgressBar.a11y.chromium.spec.ts+++ b/packages/core/src/ProgressBar/__tests__/ProgressBar.a11y.chromium.spec.ts@@ -87,6 +87,93 @@ async function runState(});}+test('ProgressBar marks have a name before the tooltip loads', async ({+ page,+}) => {+ let releaseTooltip!: () => void;+ const tooltipReady = new Promise<void>(resolve => {+ releaseTooltip = resolve;+ });+ const chunkPattern = /\/ProgressBarMarkTooltip-[^/]+\.js$/;+ const chunkRequested = page.waitForRequest(chunkPattern);+ await page.route(chunkPattern, async route => {+ await tooltipReady;+ await route.continue();+ });++ try {+ await page.goto(storyUrl('core-progressbar--with-target-mark'), {+ waitUntil: 'domcontentloaded',+ });+ await chunkRequested;+ const mark = page.locator('#storybook-root .astryx-progress-bar-mark');+ await expect(mark).toBeVisible();+ await expect(mark).not.toHaveAttribute('aria-describedby');+ const cdp = await page.context().newCDPSession(page);+ const subject = await createChromiumHarness({+ page,+ cdp,+ subject: mark,+ }).subject();+ expect(await subject.computed()).toMatchObject({+ role: 'image',+ name: 'Goal',+ description: '',+ });+ await page.keyboard.press('Tab');+ await expect(mark).toBeFocused();+ expect(await subject.computed()).toMatchObject({+ role: 'image',+ name: 'Goal',+ });+ } finally {+ releaseTooltip();+ await page.unrouteAll({behavior: 'wait'});+ }+});++test('ProgressBar marks keep their names when tabbed to or hovered', async ({+ page,+}) => {+ await page.goto(storyUrl('core-progressbar--with-multiple-marks'));+ const marks = page.locator('#storybook-root .astryx-progress-bar-mark');+ const labels = ['Q1 target', 'Q2 target', 'Stretch goal'];+ await expect(marks).toHaveCount(labels.length);+ const cdp = await page.context().newCDPSession(page);++ for (const [index, label] of labels.entries()) {+ const mark = marks.nth(index);+ await expect(mark).toHaveAttribute('aria-describedby', /.+/);+ const subject = await createChromiumHarness({+ page,+ cdp,+ subject: mark,+ }).subject();+ expect(await subject.computed()).toMatchObject({+ role: 'image',+ name: label,+ });+ await page.keyboard.press('Tab');+ await expect(mark).toBeFocused();+ const tooltip = page.getByRole('tooltip').filter({hasText: label});+ await expect(tooltip).toBeVisible();+ expect(await subject.computed()).toMatchObject({+ role: 'image',+ name: label,+ });+ await page.keyboard.press('Escape');+ await expect(tooltip).not.toBeVisible();+ await expect(mark).toBeFocused();+ }++ await page.getByText('Quarterly milestones', {exact: true}).click();+ await marks.first().hover();+ const tooltip = page.getByRole('tooltip').filter({hasText: labels[0]});+ await expect(tooltip).toBeVisible();+ await page.keyboard.press('Escape');+ await expect(tooltip).not.toBeVisible();+});+// Checking coverage runs every state again, which on a loaded runner nears// the per-test timeout as one test. It runs as one serial part per state,// sharing their results, then one check over all of them.