Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(Stepper): keep a clickable step's number and label apart in its text reading (#8016)

Ojas Mutrejabc40b8065f95
diff --git a/.changeset/step-indicator-label-gap.md b/.changeset/step-indicator-label-gap.md
new file mode 100644
index 0000000000..fd4d312232
--- /dev/null
+++ b/.changeset/step-indicator-label-gap.md
@@ -0,0 +1,9 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Step: a clickable step's number badge and label are no longer adjacent text, so a text reading of the button no longer joins them as "1Account" (axe-core 4.14's Label in Name rule reported every clickable numbered step). A whitespace node now separates them in all four layouts; the rows are flex containers, so nothing changes on screen. A step's `description` inside the button is a separate Label in Name case and is unchanged.
+
+Fixes #7966.
+
+@HelloOjasMutreja
diff --git a/packages/core/src/Stepper/Step.tsx b/packages/core/src/Stepper/Step.tsx
index 23264ca57c..bd353a5450 100644
--- a/packages/core/src/Stepper/Step.tsx
+++ b/packages/core/src/Stepper/Step.tsx
@@ -1316,6 +1316,10 @@ export function Step({
const iconLabelNode = (
<div {...stylex.props(styles.iconLabelRow)}>
{(!isCompact || indicatorPosition !== 'on-track') && indicatorNode}
+ {/* A space between the indicator and the label: the row is a flex
+ container, which drops whitespace-only text, so nothing changes on
+ screen, but a text reading of the button then keeps "1 Account" as two
+ words instead of "1Account". */}{' '}
<span
{...mergeProps(
labelThemeProps,
@@ -1576,6 +1580,8 @@ export function Step({
)}
/>
</div>
+ {/* Whitespace between the indicator column and the label, as in
+ iconLabelNode. */}{' '}
<div {...stylex.props(styles.otBodyV)}>
{labelLineNode}
{otDescriptionNode}
@@ -1658,6 +1664,7 @@ export function Step({
)}
/>
</div>
+ {/* Whitespace between the rail and the label, as in iconLabelNode. */}{' '}
{/* The on-track indicator remains visible as a node on the rail at
compact widths, but the wrapper becomes presentational with its
label. Navigation moves to the named controls in the summary row. */}
diff --git a/packages/core/src/Stepper/Stepper.test.tsx b/packages/core/src/Stepper/Stepper.test.tsx
index 6c7ece4fc6..7261406784 100644
--- a/packages/core/src/Stepper/Stepper.test.tsx
+++ b/packages/core/src/Stepper/Stepper.test.tsx
@@ -2016,3 +2016,36 @@ describe('step-label and step-description theme targets', () => {
);
});
});
+
+describe('clickable step text reading', () => {
+ // axe-core's Label in Name rule joins a button's text nodes with nothing
+ // between them, aria-hidden ones included, so a number badge next to a label
+ // reads as one word ("1Account") that the step's name does not contain.
+ // Whitespace between them changes nothing on screen (the rows are flex
+ // containers) and keeps the two words apart.
+ it.each([
+ ['vertical', 'separated'],
+ ['horizontal', 'separated'],
+ ['vertical', 'on-track'],
+ ['horizontal', 'on-track'],
+ ] as const)(
+ 'keeps the number and label apart in a %s %s step',
+ (orientation, indicatorPosition) => {
+ render(
+ <Stepper
+ orientation={orientation}
+ indicatorPosition={indicatorPosition}
+ activeStep={0}
+ label="Steps"
+ onStepClick={() => {}}>
+ <Step step={0} label="Account" indicator="number" />
+ <Step step={1} label="Payment" indicator="number" />
+ </Stepper>,
+ );
+
+ const button = screen.getByRole('button', {name: /Account/});
+ expect(button.textContent).toMatch(/1\s+Account/);
+ expect(button.textContent).not.toMatch(/1Account/);
+ },
+ );
+});