Skip to content

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

TypeScript

fix(Token): a disabled token exposes its state, and a disabled link token stays a focusable link (#9037)

Cindy Zhanga9c205da8631
diff --git a/.changeset/token-disabled-state.md b/.changeset/token-disabled-state.md
new file mode 100644
index 0000000000..78d519e113
--- /dev/null
+++ b/.changeset/token-disabled-state.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] A disabled `Token` reflects its state on the `token` theme target (`data-disabled`) in every structure, so a theme can style it. A disabled link token keeps a focusable link announced as disabled (`aria-disabled="true"`, no `href`), instead of becoming plain text with no tab stop.
+
+@cixzhang @duytbp
diff --git a/packages/core/src/Token/Token.doc.mjs b/packages/core/src/Token/Token.doc.mjs
index c78a1fd96d..8dac949a04 100644
--- a/packages/core/src/Token/Token.doc.mjs
+++ b/packages/core/src/Token/Token.doc.mjs
@@ -88,7 +88,7 @@ export const docs = {
},
], theming: {
targets: [
- {className: 'astryx-token', visualProps: ['color', 'size']},
+ {className: 'astryx-token', visualProps: ['color', 'size'], states: ['disabled']},
],
},
usage: {
@@ -193,7 +193,7 @@ export const docsZh = {
],
theming: {
targets: [
- {className: 'astryx-token', visualProps: ['color', 'size']},
+ {className: 'astryx-token', visualProps: ['color', 'size'], states: ['disabled']},
],
},
usage: {
diff --git a/packages/core/src/Token/Token.spec.md b/packages/core/src/Token/Token.spec.md
index 6b7b454def..5ef81f6532 100644
--- a/packages/core/src/Token/Token.spec.md
+++ b/packages/core/src/Token/Token.spec.md
@@ -41,7 +41,7 @@ system_specs: [spec:AST-005, spec:AST-009, spec:AST-085]
| Behavior | `href` renders a link, `onClick` (or an enclosing trigger context) renders a container whose inner button wraps the label, and `onRemove` adds a separate remove button beside, never inside, them. |
| End-user impact | Pointer users can activate the whole chip; keyboard and screen-reader users reach the chip's action and its remove action as separate, named controls. |
| Builder impact | None; the record describes shipped behavior. |
-| Compatibility/readiness | Released behavior recorded as current; no API, default, or output changes. Six implementation gaps are listed under Current-state impact. |
+| Compatibility/readiness | Released behavior recorded as current; no API, default, or output changes. Four implementation gaps are listed under Current-state impact. |
| Review checks | Reject a remove button nested in the link or the inner button, a remove target smaller than 24 by 24 CSS pixels, a native `disabled` attribute, or a token that navigates around the shared destination rule. |
| Governing rules | `family:navigation-destinations`; `spec:AST-005`; `spec:AST-085/FR1,FR2,FR5`; `architecture:public-component-api/INV5,INV6,INV8`; `architecture:component-theming-surface/INV6,INV14`. |
@@ -66,10 +66,6 @@ Consumer migration instructions belong in consumer docs and release notes.
## Current-state impact
-- **Disabled link token (FR5, AR5).** A disabled token with `href` and no
- `onClick` renders a static `span`: it loses its tab stop and exposes no
- disabled state, where `spec:AST-085` FR1 and FR5 keep a disabled control
- focusable and announced.
- **`onClick` with `href` (FR3).** When a token renders as a link, a supplied
`onClick` is not attached or called, where
`architecture:public-component-api` INV5 preserves accepted event inputs.
@@ -77,10 +73,6 @@ Consumer migration instructions belong in consumer docs and release notes.
static, clickable, or link-and-remove token puts `aria-label` on a `span` that
has no role, where WAI-ARIA 1.2 prohibits naming the generic role. The
visually hidden label text still reaches assistive technology.
-- **Disabled state not reflected on the target (FR5).** No structure reflects
- `isDisabled` on the `token` target, so a theme cannot style the disabled state
- through it, where `architecture:component-theming-surface` INV6 keeps state on
- the owning target.
- **Two focus indicators on Remove (AR4).** In clickable and link-and-remove
tokens, keyboard focus on the Remove button draws the token's outline and the
button's own, where `architecture:interaction-modality` INV3 allows one
@@ -116,29 +108,29 @@ Consumer migration instructions belong in consumer docs and release notes.
## Public concepts
-| Concept | Closed values or states | Meaning | Availability by variant/orientation/state | Default | Owner | Stability | Invalid-value behavior |
-| ---------------- | ---------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- | ------------------------------------------------------------------------------- | --------- | ----------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
-| Structure | static; clickable; link; link-and-remove | Which element owns the token's own action (FR2–FR4). | Resolved from `href`, `onClick`, `isDisabled`, and an enclosing trigger context | static | `component:Token` | Stable | A disabled link token stays a focusable control that exposes its disabled state (FR5); today it resolves to the static structure, the FR5 gap. |
-| Size | `sm`, `md`, `lg` | Selects the block size. | All structures | `md` | `component:Token` | Stable | TypeScript rejects other values. |
-| Tone (`color`) | `default`, `red`, `orange`, `yellow`, `green`, `teal`, `cyan`, `blue`, `purple`, `pink`, `gray`; theme additions | Selects fill and text color. | All structures | `default` | `component:Token` | Stable | A theme-added value is reflected on `token` and receives no component fill or color; TypeScript rejects unregistered values. |
-| Removable | present when `onRemove` is supplied; absent | Adds the Remove button after the label and end content. | All structures | absent | `component:Token` | Stable | — |
-| Label visibility | visible; visually hidden | Hides the label visually while keeping it as the token's name. | All structures | visible | `component:Token` | Stable | — |
-| Disabled | enabled; disabled | Blocks every token and remove action. | All structures | enabled | `component:Token` | Stable | — |
+| Concept | Closed values or states | Meaning | Availability by variant/orientation/state | Default | Owner | Stability | Invalid-value behavior |
+| ---------------- | ---------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- | ------------------------------------------------------------------------------- | --------- | ----------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------- |
+| Structure | static; clickable; link; link-and-remove | Which element owns the token's own action (FR2–FR4). | Resolved from `href`, `onClick`, `isDisabled`, and an enclosing trigger context | static | `component:Token` | Stable | A disabled link token stays a focusable control that exposes its disabled state (FR5). |
+| Size | `sm`, `md`, `lg` | Selects the block size. | All structures | `md` | `component:Token` | Stable | TypeScript rejects other values. |
+| Tone (`color`) | `default`, `red`, `orange`, `yellow`, `green`, `teal`, `cyan`, `blue`, `purple`, `pink`, `gray`; theme additions | Selects fill and text color. | All structures | `default` | `component:Token` | Stable | A theme-added value is reflected on `token` and receives no component fill or color; TypeScript rejects unregistered values. |
+| Removable | present when `onRemove` is supplied; absent | Adds the Remove button after the label and end content. | All structures | absent | `component:Token` | Stable | — |
+| Label visibility | visible; visually hidden | Hides the label visually while keeping it as the token's name. | All structures | visible | `component:Token` | Stable | — |
+| Disabled | enabled; disabled | Blocks every token and remove action. | All structures | enabled | `component:Token` | Stable | — |
## Behavioral and layout contract
-| ID | Invariant | Basis |
-| ---- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
-| FR1 | Content renders in logical inline order: Icon, Label, End content, Remove button. The root is inline-flex with `--spacing-1` gaps, inline padding `--spacing-2`, `--radius-inner` corners, `--text-supporting-size` type at `--font-weight-medium`, and a minimum block size of `--size-element-sm`, `-md`, or `-lg` minus 8px for `sm`, `md`, and `lg`. That size grows with a set text size under `spec:AST-102` FR4; today's fixed size is a gap. | Current source and tests |
-| FR2 | With no `href`, `onClick`, or enclosing trigger context, the token is a static `span` holding its content directly. | Current source and tests |
-| FR3 | With an enabled `href` and no `onRemove`, the token root is the shared link component carrying the destination; it takes the root ref, passthrough props, and its own focus-visible outline. A supplied `onClick`, as an accepted event input, reaches the element that owns the contract (`architecture:public-component-api` INV5). Implementation gap: in both link structures `onClick` is not attached or called (Current-state impact). | Current source and tests |
-| FR4 | With `onClick`, or an enclosing trigger context that resolves the token to a button, the root is a `span` container holding an inner `button` that wraps only the Label and calls `onClick`; a click on the container outside any nested button or link also calls `onClick`. With an enabled `href` and `onRemove`, the container instead holds an inner link wrapping only the Label; a plain click on the surface outside the Remove button follows that link, and a Cmd/Ctrl-click or middle click on the surface opens it in a new tab. A caller `onMouseUp` on the link-and-remove container runs before its delegation. | Current source and tests |
-| FR5 | A disabled token renders at half opacity with pointer events off and fires neither `onClick` nor `onRemove` from pointer, Enter, or Space; inner and Remove buttons stay focusable with `aria-disabled="true"` and never receive native `disabled`. A disabled control keeps its tab stop and exposes its disabled state (`spec:AST-085` FR1, FR5), and the disabled state is reflected on the owning target (`architecture:component-theming-surface` INV6). Implementation gap: a disabled token with `href` and no `onClick` or trigger context renders as a static `span` with no tab stop and no disabled state, and no structure reflects the disabled state on the `token` target (Current-state impact). | Current source and tests |
-| FR6 | `onRemove` renders a `type="button"` Remove button holding a close glyph; a click stops propagation before `onRemove` runs, so it never triggers the token's own action or link. The button is a sibling of the inner button or link, never nested in it. | Current source and tests |
-| FR7 | The label never wraps: the root is capped at its container's inline size and clips overflow. In the static and link structures the Label ends in an ellipsis; in the clickable and link-and-remove structures the inner control clips the Label without an ellipsis. `isLabelHidden` keeps the Label in the DOM with a visually hidden clip treatment. | Current source and tests |
-| FR8 | `color` defaults to `default`, painting `--color-neutral` with primary text; every other built-in tone paints its tinted background with its matching colored text. The `token` target reflects the resolved `color` and `size` for every value, including a theme-added color, which receives no component fill or text color until a theme paints it. | Current source and tests |
-| FR9 | Clickable and link structures paint the shared hover overlay under a hover-capable pointer and the shared pressed overlay for mouse and touch presses; the static structure paints neither. | Current source |
-| FR10 | `ref` reaches the root element of every structure. Supported DOM, ARIA, data, and event props reach the root; `data-testid` reaches the root; `xstyle`, `className`, and `style` merge in that order after component styles. | Current source and tests |
+| ID | Invariant | Basis |
+| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
+| FR1 | Content renders in logical inline order: Icon, Label, End content, Remove button. The root is inline-flex with `--spacing-1` gaps, inline padding `--spacing-2`, `--radius-inner` corners, `--text-supporting-size` type at `--font-weight-medium`, and a minimum block size of `--size-element-sm`, `-md`, or `-lg` minus 8px for `sm`, `md`, and `lg`. That size grows with a set text size under `spec:AST-102` FR4; today's fixed size is a gap. | Current source and tests |
+| FR2 | With no `href`, `onClick`, or enclosing trigger context, the token is a static `span` holding its content directly. | Current source and tests |
+| FR3 | With an enabled `href` and no `onRemove`, the token root is the shared link component carrying the destination; it takes the root ref, passthrough props, and its own focus-visible outline. A supplied `onClick`, as an accepted event input, reaches the element that owns the contract (`architecture:public-component-api` INV5). Implementation gap: in both link structures `onClick` is not attached or called (Current-state impact). | Current source and tests |
+| FR4 | With `onClick`, or an enclosing trigger context that resolves the token to a button, the root is a `span` container holding an inner `button` that wraps only the Label and calls `onClick`; a click on the container outside any nested button or link also calls `onClick`. With an enabled `href` and `onRemove`, the container instead holds an inner link wrapping only the Label; a plain click on the surface outside the Remove button follows that link, and a Cmd/Ctrl-click or middle click on the surface opens it in a new tab. A caller `onMouseUp` on the link-and-remove container runs before its delegation. | Current source and tests |
+| FR5 | A disabled token renders at half opacity with pointer events off and fires neither `onClick` nor `onRemove` from pointer, Enter, or Space; inner and Remove buttons stay focusable with `aria-disabled="true"` and never receive native `disabled`. A disabled control keeps its tab stop and exposes its disabled state (`spec:AST-085` FR1, FR5), and the disabled state is reflected on the owning target (`architecture:component-theming-surface` INV6). A disabled token with `href` and no `onClick` or trigger context renders a focusable link with `aria-disabled="true"` and no `href`, and every structure reflects the disabled state on the `token` target. | Current source and tests |
+| FR6 | `onRemove` renders a `type="button"` Remove button holding a close glyph; a click stops propagation before `onRemove` runs, so it never triggers the token's own action or link. The button is a sibling of the inner button or link, never nested in it. | Current source and tests |
+| FR7 | The label never wraps: the root is capped at its container's inline size and clips overflow. In the static and link structures the Label ends in an ellipsis; in the clickable and link-and-remove structures the inner control clips the Label without an ellipsis. `isLabelHidden` keeps the Label in the DOM with a visually hidden clip treatment. | Current source and tests |
+| FR8 | `color` defaults to `default`, painting `--color-neutral` with primary text; every other built-in tone paints its tinted background with its matching colored text. The `token` target reflects the resolved `color` and `size` for every value, including a theme-added color, which receives no component fill or text color until a theme paints it. | Current source and tests |
+| FR9 | Clickable and link structures paint the shared hover overlay under a hover-capable pointer and the shared pressed overlay for mouse and touch presses; the static structure paints neither. | Current source |
+| FR10 | `ref` reaches the root element of every structure. Supported DOM, ARIA, data, and event props reach the root; `data-testid` reaches the root; `xstyle`, `className`, and `style` merge in that order after component styles. | Current source and tests |
### Allowed variation
@@ -163,11 +155,11 @@ Consumer migration instructions belong in consumer docs and release notes.
### Transformation and precedence order
- **ORD1 — Structure.** Enabled `href` → `onClick` → enclosing trigger context →
- static. `onRemove` with an enabled `href` selects the link-and-remove
- container. A disabled `href` is skipped, so a disabled link token falls
- through to `onClick`, a trigger context, or static; the static fall-through is
- the FR5 gap.
-- **ORD2 — Root attributes.** Component class and `data-color`/`data-size` →
+ disabled `href` → static. `onRemove` with an `href` that wins selects the
+ link-and-remove container. A disabled `href` yields to `onClick` and a
+ trigger context; otherwise it keeps the link structure, rendered disabled
+ (FR5).
+- **ORD2 — Root attributes.** Component class and `data-color`/`data-size`/`data-disabled` →
component styles → `xstyle` → `className` → `style` → caller props → `data-testid`, hidden-label
`aria-label`, and `aria-description`. A hidden label's `aria-label` replaces
a caller `aria-label`.
@@ -204,9 +196,7 @@ Consumer migration instructions belong in consumer docs and release notes.
those structures shows the container outline and the button's own.
- **AR5 — Disabled.** A disabled token's controls stay focusable, expose
`aria-disabled="true"`, and ignore pointer, Enter, and Space (`spec:AST-085`
- FR1, FR2, FR5); the inner and Remove buttons do. Implementation gap: a
- disabled link token renders as a static `span` with no tab stop and no
- disabled state.
+ FR1, FR2, FR5), the disabled link included.
- **AR6 — Remove target size.** The Remove button's glyph box is 16 by 16 CSS
pixels and its hit area extends 4 pixels on every side to 24 by 24 at `md`
and `lg`, meeting WCAG 2.2 2.5.8, while a press on the adjacent label still
@@ -224,7 +214,7 @@ Consumer migration instructions belong in consumer docs and release notes.
| End content | Optional trailing content such as a count or status dot. | Current source and docs | Supporting | FR1 |
| Remove button | A trailing close control that dismisses the token. | Current source and docs | Supporting | FR6, AR1, AR2, AR6 |
-Theming: the root is the single `token` target and reflects `color` and `size`.
+Theming: the root is the single `token` target and reflects `color`, `size`, and the disabled state.
The Label, End content, and Icon add no targets; the Remove button inherits the
token's text color.
@@ -234,7 +224,7 @@ token's text color.
for both link structures, including delegated surface clicks; Token adopts
them through the shared link component and clickable-container delegation.
- `spec:AST-085` owns focusable disabled controls; FR5 and AR5 record Token's
- conformance and its one gap.
+ conformance.
- `architecture:public-component-api` owns ref, passthrough, and styling-input
rules; FR3 records one gap against INV5.
- `architecture:component-theming-surface` owns the `token` target and the
@@ -244,18 +234,18 @@ token's text color.
## Verification map
-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
-| ------------------ | -------------------------------------------------------------------------------------- | ------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- |
-| FR2, FR10 | `Token.test.tsx` render, ref, and pass-through suites | Static, clickable, and link roots; caller props | A wrong root element, a detached ref, or a dropped caller prop fails DOM assertions. Gap: no test covers the ref on the link-and-remove container. | `audit:Token/behavior` |
-| FR1, FR7 | `Token.stories.tsx` size, icon, and end-content fixtures in a browser | Sizes, icon and end content | Gap: the size and overflow unit tests assert presence only, and no story renders a long label; slot order and block size are visible only in the rendered fixtures, and the ellipsis has no check. | `audit:Token/layout` |
-| FR3, FR4, FR6, AR1 | `Token.test.tsx` link, clickable, and link-with-remove suites | Link, clickable, link and remove, modified and middle clicks | Nesting the Remove button, firing the token action from Remove, or losing delegation fails. Gap: no test asserts that `onClick` is dropped with `href`. | `audit:Token/behavior` |
-| FR5, AR5 | `Token.test.tsx` disabled tests | Disabled clickable with remove | A native `disabled`, a lost tab stop on a button, or a fired callback fails. Gap: no test covers a disabled link token. | `audit:Token/a11y` |
-| AR2, AR3, AR7 | `Token.test.tsx` accessibility suite | Remove name, hidden label, description | A missing remove name, lost hidden label, or missing description fails. Gap: no test asserts the link structure's content-derived name. | `audit:Token/a11y` |
-| AR6 | `TokenRemoveTarget.a11y.chromium.spec.ts` | Pre-set filter tokens (default size), LTR and RTL | A remove target that misses its X edge or swallows a label press fails in real Chromium. Gap: the `sm` clipping is not covered. | `audit:Token/a11y` |
-| FR8 | `Token.test.tsx` custom-color test; `extensibleAxes.test.ts`; `themingTargets.test.ts` | Theme-added color; map wiring | Dropping the `color` reflection fails. Gap: no test asserts `data-size` or any tone's paint; those are visible only in `Token.stories.tsx`. | `audit:Token/theming` |
-| FR9, AR4 | `Token.stories.tsx` clickable and link fixtures in a browser | Hover, press, keyboard focus on the token | Gap: no automated check covers overlays or indicators, and no story renders a clickable or link token with Remove, so the double indicator on Remove has no fixture. | `audit:Token/design` |
-| PR1 | Source review | Every structure | Gap: no automated check fails if Token adds a per-token listener, observer, or timer. | `audit:Token/behavior` |
-| AR2, AR3, AR5, AR7 | Accessibility-tree evidence (`spec:AST-009` FR3) | Every structure; hidden label; description; disabled | Gap: no accessibility-tree check proves the computed names, the hidden-label name, the description, or the disabled state; the unit tests assert DOM attributes only. | `audit:Token/a11y` |
+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
+| ------------------ | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- |
+| FR2, FR10 | `Token.test.tsx` render, ref, and pass-through suites | Static, clickable, and link roots; caller props | A wrong root element, a detached ref, or a dropped caller prop fails DOM assertions. Gap: no test covers the ref on the link-and-remove container. | `audit:Token/behavior` |
+| FR1, FR7 | `Token.stories.tsx` size, icon, and end-content fixtures in a browser | Sizes, icon and end content | Gap: the size and overflow unit tests assert presence only, and no story renders a long label; slot order and block size are visible only in the rendered fixtures, and the ellipsis has no check. | `audit:Token/layout` |
+| FR3, FR4, FR6, AR1 | `Token.test.tsx` link, clickable, and link-with-remove suites | Link, clickable, link and remove, modified and middle clicks | Nesting the Remove button, firing the token action from Remove, or losing delegation fails. Gap: no test asserts that `onClick` is dropped with `href`. | `audit:Token/behavior` |
+| FR5, AR5 | `Token.test.tsx` disabled tests | Disabled clickable with remove; disabled static; disabled link with and without remove | A native `disabled`, a lost tab stop, a disabled link with a destination, an unreflected disabled state, or a fired callback fails. | `audit:Token/a11y` |
+| AR2, AR3, AR7 | `Token.test.tsx` accessibility suite | Remove name, hidden label, description | A missing remove name, lost hidden label, or missing description fails. Gap: no test asserts the link structure's content-derived name. | `audit:Token/a11y` |
+| AR6 | `TokenRemoveTarget.a11y.chromium.spec.ts` | Pre-set filter tokens (default size), LTR and RTL | A remove target that misses its X edge or swallows a label press fails in real Chromium. Gap: the `sm` clipping is not covered. | `audit:Token/a11y` |
+| FR8 | `Token.test.tsx` custom-color test; `extensibleAxes.test.ts`; `themingTargets.test.ts` | Theme-added color; map wiring | Dropping the `color` reflection fails. Gap: no test asserts `data-size` or any tone's paint; those are visible only in `Token.stories.tsx`. | `audit:Token/theming` |
+| FR9, AR4 | `Token.stories.tsx` clickable and link fixtures in a browser | Hover, press, keyboard focus on the token | Gap: no automated check covers overlays or indicators, and no story renders a clickable or link token with Remove, so the double indicator on Remove has no fixture. | `audit:Token/design` |
+| PR1 | Source review | Every structure | Gap: no automated check fails if Token adds a per-token listener, observer, or timer. | `audit:Token/behavior` |
+| AR2, AR3, AR5, AR7 | Accessibility-tree evidence (`spec:AST-009` FR3) | Every structure; hidden label; description; disabled | Gap: no accessibility-tree check proves the computed names, the hidden-label name, the description, or the disabled state; the unit tests assert DOM attributes only. | `audit:Token/a11y` |
## Decision log
diff --git a/packages/core/src/Token/Token.test.tsx b/packages/core/src/Token/Token.test.tsx
index 4426fc3867..48c8bf8084 100644
--- a/packages/core/src/Token/Token.test.tsx
+++ b/packages/core/src/Token/Token.test.tsx
@@ -256,6 +256,73 @@ describe('Token accessibility', () => {
).toBeInTheDocument();
});
+ it('reflects the disabled state on the token target in every structure (theming-surface INV6)', () => {
+ render(
+ <>
+ <Token label="Static" isDisabled data-testid="static" />
+ <Token
+ label="Clickable"
+ onClick={() => {}}
+ isDisabled
+ data-testid="clickable"
+ />
+ <Token label="Link" href="/docs" isDisabled data-testid="link" />
+ <Token
+ label="Link with remove"
+ href="/docs"
+ onRemove={() => {}}
+ isDisabled
+ data-testid="link-and-remove"
+ />
+ <Token label="Enabled" href="/docs" data-testid="enabled" />
+ </>,
+ );
+ for (const id of ['static', 'clickable', 'link', 'link-and-remove']) {
+ expect(screen.getByTestId(id), id).toHaveAttribute(
+ 'data-disabled',
+ 'disabled',
+ );
+ }
+ expect(screen.getByTestId('enabled')).not.toHaveAttribute('data-disabled');
+ });
+
+ it('keeps a disabled link token a focusable link with no destination (spec:AST-085 FR1, FR5)', async () => {
+ const user = userEvent.setup();
+ const onRemove = vi.fn();
+ render(
+ <>
+ <Token label="Docs" href="/docs" isDisabled />
+ <Token label="Guide" href="/guide" isDisabled onRemove={onRemove} />
+ </>,
+ );
+ for (const name of ['Docs', 'Guide']) {
+ const link = screen.getByRole('link', {name});
+ expect(link, name).toHaveAttribute('aria-disabled', 'true');
+ expect(link, name).not.toHaveAttribute('href');
+ }
+ await user.tab();
+ expect(screen.getByRole('link', {name: 'Docs'})).toHaveFocus();
+ await user.tab();
+ expect(screen.getByRole('link', {name: 'Guide'})).toHaveFocus();
+ await user.tab();
+ await user.keyboard('{Enter}');
+ expect(onRemove).not.toHaveBeenCalled();
+ });
+
+ it("passes other keys to a disabled link token's onKeyDown, but not Enter or Space", async () => {
+ const user = userEvent.setup();
+ const onKeyDown = vi.fn();
+ render(
+ <Token label="Docs" href="/docs" isDisabled onKeyDown={onKeyDown} />,
+ );
+ await user.tab();
+ await user.keyboard('{ArrowRight}');
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
+ expect(onKeyDown.mock.calls[0][0].key).toBe('ArrowRight');
+ await user.keyboard('{Enter} ');
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
+ });
+
it('keeps both buttons focusable and inert when isDisabled is true', async () => {
const user = userEvent.setup();
const handleClick = vi.fn();
diff --git a/packages/core/src/Token/Token.tsx b/packages/core/src/Token/Token.tsx
index 57c5b3d6f3..4f288a9495 100644
--- a/packages/core/src/Token/Token.tsx
+++ b/packages/core/src/Token/Token.tsx
@@ -348,7 +348,46 @@ export function Token({
...(description != null ? {'aria-description': description} : {}),
};
- if (role === 'link') {
+ // A disabled link keeps a focusable link with aria-disabled and no
+ // destination, as a disabled Link does (spec:AST-085 FR1, FR5;
+ // component:Link FR5). useInteractiveRole reports no link role once
+ // disabled, so the structure is chosen here.
+ const isDisabledLink = isDisabled && href != null && effectiveOnClick == null;
+
+ if (isDisabledLink && onRemove == null) {
+ // A disabled link is an <a> with no href, as Link renders one: nothing can
+ // navigate, it keeps a Tab stop and the link role (spec:AST-085 FR1, FR5).
+ // The router LinkComponent is skipped, since a custom router link may
+ // require a live href.
+ const DisabledAnchor = 'a';
+ return (
+ <DisabledAnchor
+ ref={ref as React.Ref<HTMLAnchorElement>}
+ role="link"
+ aria-disabled={true}
+ tabIndex={0}
+ {...mergeProps(
+ themeProps('token', {color, size, disabled: 'disabled'}),
+ focusOutlineProps.focusVisible(
+ styles.base,
+ sizeStyles[size],
+ colorStyles[color],
+ styles.interactive,
+ styles.disabled,
+ xstyle,
+ ),
+ className,
+ style,
+ )}
+ {...rest}
+ {...disabledInteractionProps(rest.onKeyDown)}
+ {...sharedProps}>
+ {content}
+ </DisabledAnchor>
+ );
+ }
+
+ if (role === 'link' || isDisabledLink) {
if (onRemove == null) {
return (
<LinkComponent
@@ -356,7 +395,11 @@ export function Token({
href={href as string}
{...pressable}
{...mergeProps(
- themeProps('token', {color, size}),
+ themeProps('token', {
+ color,
+ size,
+ disabled: isDisabled ? 'disabled' : null,
+ }),
focusOutlineProps.focusVisible(
styles.base,
sizeStyles[size],
@@ -405,7 +448,11 @@ export function Token({
</span>
}
{...mergeProps(
- themeProps('token', {color, size}),
+ themeProps('token', {
+ color,
+ size,
+ disabled: isDisabled ? 'disabled' : null,
+ }),
focusOutlineProps.focusWithin(
styles.base,
sizeStyles[size],
@@ -439,7 +486,11 @@ export function Token({
onClick={isDisabled ? undefined : handleContainerClick}
{...pressable}
{...mergeProps(
- themeProps('token', {color, size}),
+ themeProps('token', {
+ color,
+ size,
+ disabled: isDisabled ? 'disabled' : null,
+ }),
focusOutlineProps.focusWithin(
styles.base,
sizeStyles[size],
@@ -479,7 +530,11 @@ export function Token({
<span
ref={ref}
{...mergeProps(
- themeProps('token', {color, size}),
+ themeProps('token', {
+ color,
+ size,
+ disabled: isDisabled ? 'disabled' : null,
+ }),
stylex.props(
styles.base,
sizeStyles[size],
diff --git a/packages/core/src/Token/TokenLink.tsx b/packages/core/src/Token/TokenLink.tsx
index 9a0b9d637e..9a895ed568 100644
--- a/packages/core/src/Token/TokenLink.tsx
+++ b/packages/core/src/Token/TokenLink.tsx
@@ -32,6 +32,7 @@ import type {LinkComponentType} from '../Link/types';
import {composeEventHandlers} from '../utils';
import {useMergedRefs} from '../hooks/useMergedRefs';
+import {disabledInteractionProps} from '../utils/disabledInteraction';
export interface TokenLinkProps extends HTMLAttributes<HTMLElement> {
/** Ref forwarded to the container element. */
ref?: Ref<HTMLElement>;
@@ -100,13 +101,26 @@ export function TokenLink({
: composeEventHandlers(onMouseUpProp, onMouseUp)
}>
{icon}
- <LinkComponent
- ref={linkRef as Ref<HTMLAnchorElement>}
- href={href}
- aria-disabled={isDisabled || undefined}
- {...linkStyleProps}>
- {labelContent}
- </LinkComponent>
+ {isDisabled ? (
+ // A disabled link stays a focusable link with no destination, as a
+ // disabled Link does (spec:AST-085 FR1, FR5; component:Link FR5).
+ <a
+ ref={linkRef as Ref<HTMLAnchorElement>}
+ role="link"
+ aria-disabled={true}
+ tabIndex={0}
+ {...linkStyleProps}
+ {...disabledInteractionProps()}>
+ {labelContent}
+ </a>
+ ) : (
+ <LinkComponent
+ ref={linkRef as Ref<HTMLAnchorElement>}
+ href={href}
+ {...linkStyleProps}>
+ {labelContent}
+ </LinkComponent>
+ )}
{endContent}
{removeButton}
</span>