From 9e86180684ae30c13a52104226e71a125d64471b Mon Sep 17 00:00:00 2001 From: Ernest Tien Date: Mon, 23 Nov 2026 16:24:58 -0800 Subject: [PATCH 1/3] feat(SelectableCard, SelectableCardGroup): a card joins its group by value A SelectableCard with a `value` in place of `isSelected` and `onChange` is a member of the SelectableCardGroup around it. The group gives the card its selection, its input (a radio in a single choice, a checkbox in several), its input name and its disabled default, and the card sends the group its selection requests. Membership stops at a layer boundary. The new SelectableCardMemberProps type describes a member. SelectableCardProps stays an interface and gains only `value?: never`, so TypeScript rejects `isSelected` or `onChange` beside `value`. Outside a group, a card with a `value` warns in development and stays unselected. Lab's SelectableCardGroup takes these cards as its children, so SelectableCardGroupItem and SelectableCardGroupItemProps are removed. The `component:SelectableCard` record admits `value` (DEC-1). --- .changeset/selectable-card-group-value.md | 7 + .../stories/SelectableCardGroup.stories.tsx | 46 +-- .../SelectableCard/SelectableCard.spec.md | 143 ++++--- packages/cli/test/swizzle-proof/samples.mjs | 15 +- .../src/SelectableCard/SelectableCard.doc.mjs | 22 +- .../src/SelectableCard/SelectableCard.tsx | 105 +++-- .../SelectableCardRadio.test.tsx | 367 +++++++++++++++--- packages/core/src/SelectableCard/index.ts | 5 +- .../selectableCardGroupContext.ts | 40 ++ .../src/SelectableCard/selectableCardInput.ts | 34 -- packages/core/src/internal/selectable-card.ts | 8 +- .../SelectableCardGroupShippingSpeed.doc.mjs | 1 + .../SelectableCardGroupShippingSpeed.tsx | 7 +- .../SelectableCardGroupShowcase.doc.mjs | 2 +- .../blocks/SelectableCardGroupShowcase.tsx | 7 +- .../SelectableCardGroup.doc.mjs | 8 +- .../SelectableCardGroup.test.tsx | 66 ++-- .../SelectableCardGroup.tsx | 129 +----- packages/lab/src/SelectableCardGroup/index.ts | 10 +- packages/lab/src/index.ts | 2 - 20 files changed, 649 insertions(+), 375 deletions(-) create mode 100644 .changeset/selectable-card-group-value.md create mode 100644 packages/core/src/SelectableCard/selectableCardGroupContext.ts delete mode 100644 packages/core/src/SelectableCard/selectableCardInput.ts diff --git a/.changeset/selectable-card-group-value.md b/.changeset/selectable-card-group-value.md new file mode 100644 index 0000000000000..14bcf225cea11 --- /dev/null +++ b/.changeset/selectable-card-group-value.md @@ -0,0 +1,7 @@ +--- +'@astryxdesign/core': patch +--- + +[feat] `SelectableCard` takes `value`. A card with a `value` in place of `isSelected` and `onChange` is a member of the `SelectableCardGroup` around it, and the group gives the card its selection, its input and its disabled default. In a single-choice group the card is a native radio that selects and never deselects itself; in a multiple-choice group it is a checkbox that submits its `value` under the group's name. The new `SelectableCardMemberProps` type describes a member. `SelectableCardProps` stays the interface it was and gains only `value?: never`, so TypeScript rejects `isSelected` or `onChange` beside `value`. Outside a group, a card with a `value` warns in development and stays unselected. A standalone card does not change. + +@ernestt diff --git a/apps/storybook/stories/SelectableCardGroup.stories.tsx b/apps/storybook/stories/SelectableCardGroup.stories.tsx index 8f36fe6e5c7c2..52be7d843ad36 100644 --- a/apps/storybook/stories/SelectableCardGroup.stories.tsx +++ b/apps/storybook/stories/SelectableCardGroup.stories.tsx @@ -4,10 +4,8 @@ import type {Meta, StoryObj} from '@storybook/react'; import {useState} from 'react'; import {Text} from '@astryxdesign/core/Text'; import {VStack} from '@astryxdesign/core/Layout'; -import { - SelectableCardGroup, - SelectableCardGroupItem, -} from '@astryxdesign/lab/SelectableCardGroup'; +import {SelectableCard} from '@astryxdesign/core/SelectableCard'; +import {SelectableCardGroup} from '@astryxdesign/lab/SelectableCardGroup'; const meta: Meta = { title: 'Lab/SelectableCardGroup', @@ -56,13 +54,9 @@ export const SingleChoice: Story = { value={plan} onChange={setPlan}> {PLANS.map(p => ( - + - + ))} ); @@ -80,13 +74,9 @@ export const MultipleChoice: Story = { value={addOns} onChange={setAddOns}> {PLANS.map(p => ( - + - + ))} ); @@ -103,13 +93,9 @@ export const Vertical: Story = { value={plan} onChange={setPlan}> {PLANS.map(p => ( - + - + ))} ); @@ -124,13 +110,9 @@ export const Disabled: Story = { isDisabled onChange={() => {}}> {PLANS.map(p => ( - + - + ))} ), @@ -150,13 +132,13 @@ export const TwoFormsSharedName: Story = { value={first} onChange={setFirst}> {PLANS.map(p => ( - - + ))} @@ -167,13 +149,13 @@ export const TwoFormsSharedName: Story = { value={second} onChange={setSecond}> {PLANS.map(p => ( - - + ))} diff --git a/docs/specs/components/SelectableCard/SelectableCard.spec.md b/docs/specs/components/SelectableCard/SelectableCard.spec.md index dbaf250804d4a..a56e735220187 100644 --- a/docs/specs/components/SelectableCard/SelectableCard.spec.md +++ b/docs/specs/components/SelectableCard/SelectableCard.spec.md @@ -20,6 +20,9 @@ verified_by: .github/visual-baseline/manifest.json, packages/core/src/SelectableCard/SelectableCard.test.tsx, packages/core/src/SelectableCard/__tests__/SelectableCardAudit.a11y.chromium.spec.ts, + packages/core/src/SelectableCard/SelectableCardRadio.test.tsx, + packages/lab/src/SelectableCardGroup/SelectableCardGroup.test.tsx, + packages/lab/src/SelectableCardGroup/__tests__/SelectableCardGroupRadio.a11y.chromium.spec.ts, packages/core/src/theme/themingTargets.test.ts, apps/storybook/stories/SelectableCard.stories.tsx, scripts/check-knowledge.mjs, @@ -34,30 +37,33 @@ architecture: architecture:public-component-api, ] contributing: [] -system_specs: [spec:AST-009, spec:AST-020, spec:AST-085] +system_specs: + [spec:AST-002, spec:AST-009, spec:AST-020, spec:AST-038, spec:AST-085] --- # SelectableCard component contract ## Contract at a glance -| Area | Contract | -| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Public contract | A Card that toggles a controlled `isSelected` through `onChange`, named by a required `label`, with `isDisabled` and Card's `variant`, `elevation`, `padding`, and sizing. | -| Behavior | A visually hidden native checkbox carries the role, name, and checked state; the whole surface toggles; selection draws an inset ring without moving layout. | -| End-user impact | Screen-reader users hear a named checkbox and its state; pointer users click anywhere on the card; disabled cards stay discoverable by keyboard. | -| Builder impact | At the next minor, a click inside an open layer inside the card (e.g. a Tooltip or HoverCard surface) no longer reaches the caller's `onClick`; a handler that needs those presses moves to the layer content. A theme's exit duration and easing set the touch press release (FR4). | -| Compatibility/readiness | Additive: the `selectable-card` target reflects `disabled` as a theming state; no prop, event or DOM-structure change. One `[breaking]` behavior change is staged for the next minor: `onClick` stops receiving clicks inside an open layer. The current source still delivers them. One implementation gap is listed under Current-state impact. FR4 gap: a mouse or pen press that starts on a nested control still paints the card. The touch press release changes (FR4, `spec:AST-094` FR5). | -| Review checks | Reject a toggle that fires twice for one press, a disabled card that toggles or leaves the tab order, a ring that shifts layout, or a nested control that toggles the card. | -| Governing rules | `spec:AST-085/FR1,FR2,FR5,FR6`; `spec:AST-020/FR9`; `architecture:interaction-modality/INV3`; `architecture:component-theming-surface/INV6,INV14`; `architecture:public-component-api/INV5,INV6,INV7,INV8`; `component:SelectableCard/FR4` (the touch press release); `spec:AST-094/FR5` (the press release's exit tokens). | +| Area | Contract | +| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Public contract | A Card that toggles a controlled `isSelected` through `onChange` (`SelectableCardProps`), or, as a `SelectableCardGroup` member identified by `value` (`SelectableCardMemberProps`), takes its selection from the group; named by a required `label`, with `isDisabled` and Card's `variant`, `elevation`, `padding`, and sizing. | +| Behavior | A visually hidden native checkbox, or a radio in a single-choice group, carries the role, name, and checked state; the whole surface toggles, and a radio only selects; selection draws an inset ring without moving layout. | +| End-user impact | Screen-reader users hear a named checkbox, or a radio in a single-choice group, and its state; pointer users click anywhere on the card; disabled cards stay discoverable by keyboard. | +| Builder impact | At the next minor, a click inside an open layer inside the card (e.g. a Tooltip or HoverCard surface) no longer reaches the caller's `onClick`; a handler that needs those presses moves to the layer content. A theme's exit duration and easing set the touch press release (FR4). In a `SelectableCardGroup`, a card takes `value` in place of `isSelected` and `onChange`. | +| Compatibility/readiness | Additive: `value` makes the card a group member, typed by `SelectableCardMemberProps`; `SelectableCardProps` stays an interface and gains only `value?: never`; the `selectable-card` target reflects `disabled` as a theming state; no event or DOM-structure change for a standalone card. One `[breaking]` behavior change is staged for the next minor: `onClick` stops receiving clicks inside an open layer. The current source still delivers them. One implementation gap is listed under Current-state impact. FR4 gap: a mouse or pen press that starts on a nested control still paints the card. The touch press release changes (FR4, `spec:AST-094` FR5). | +| Review checks | Reject a toggle that fires twice for one press, a disabled card that toggles or leaves the tab order, a ring that shifts layout, a nested control that toggles the card, a group member that takes its own `isSelected` or `onChange`, or a radio card that deselects itself. | +| Governing rules | `spec:AST-085/FR1,FR2,FR5,FR6`; `spec:AST-020/FR9`; `architecture:interaction-modality/INV3`; `architecture:component-theming-surface/INV6,INV14`; `architecture:public-component-api/INV5,INV6,INV7,INV8`; `component:SelectableCard/FR4` (the touch press release); `spec:AST-094/FR5` (the press release's exit tokens); `component:SelectableCard/DEC-1` (group membership by `value`); `spec:AST-002/FR15`; `spec:AST-038/FR8`. | This table is a review projection; the body below is authoritative. ## Intent -SelectableCard turns a Card into one checkbox option for multi-select card -groups; each card is a checkbox, so single-select groups are out of scope. It owns the hidden checkbox semantics, whole-surface -toggling, and the selection ring; the caller owns the selection state. +SelectableCard turns a Card into one selectable option. On its own or in a +multiple-choice `SelectableCardGroup`, it is a checkbox; in a single-choice +group, it is a radio. It owns the hidden input's semantics, whole-surface +toggling, and the selection ring. The caller owns a standalone card's +selection; the group owns a member's. ## Compatibility and migration @@ -67,16 +73,19 @@ toggling, and the selection ring; the caller owns the selection state. follows FR4 for every pointer (`architecture:press-feedback` INV7). Otherwise `yes` until the next minor; then `no` for the caller `onClick` (FR2). -- Compatibility class: no public prop, default or DOM-structure changes; - the `selectable-card` target reflects `disabled` as an additive theming - state; the touch press release is a nonbreaking behavior change; one behavior change staged as `[breaking]` for the next minor +- Compatibility class: additive: the `value` prop and the + `SelectableCardMemberProps` type; `SelectableCardProps` keeps its members + and gains `value?: never`; no default or DOM-structure changes for a + standalone card; the `selectable-card` target reflects `disabled` as an + additive theming state; the touch press release is a nonbreaking behavior change; one behavior change staged as `[breaking]` for the next minor (`CLN-0026`): a click inside an open layer inside the card (e.g. a Tooltip or HoverCard surface) stops at the layer root and no longer reaches the caller's `onClick` (`architecture:layer-runtime` INV17). Until then the caller's `onClick` still runs for those clicks, during capture, so before the layer's own handlers. -- Controlled/uncontrolled behavior: controlled only; `isSelected` and - `onChange` are required +- Controlled/uncontrolled behavior: controlled only: a standalone card + requires `isSelected` and `onChange`; a group member takes `value`, and the + group is controlled - Migration decision: at the next minor, a caller `onClick` handler that needs presses inside an open layer moves to the layer content @@ -110,45 +119,49 @@ Consumer migration instructions belong in consumer docs and release notes. **Owns** -- The hidden native checkbox, its name, checked state, and disabled state. +- The hidden native input (a checkbox, or a radio in a single-choice group), + its name, checked state, and disabled state. - Toggling from the card surface, the checkbox, and Enter, and suppressing toggles from nested interactive content. - The selection ring, the selected border color, hover and pressed overlays, the delegated focus indicator, and the disabled treatment. - The `selectable-card` target and the public `--selectable-card-ring-color` variable. -- Internal note: through an internal channel, Lab's SelectableCardGroup can - render the card's hidden input as a radio in a native radio group. No public - prop exposes this; single-select stays outside the public contract until the - group is promoted to Core. +- As a `SelectableCardGroup` member identified by `value`: reading its + selection, input type (`radio` in a `type="single"` group, `checkbox` in a + `type="multiple"` group), input name, and disabled default from the group, + and sending the group its selection requests. The group provides them + through a private context, which Lab's SelectableCardGroup reaches through + Core's `internal/selectable-card` entry; no public context is exported. **Does not own / non-goals** - Card surface paint, padding, radius, elevation, and sizing — owned by `component:Card`. -- Group semantics and which options are selected — owned by the product - callsite. Single-select groups need a radio pattern, which SelectableCard - does not provide. +- Group semantics, the group label, and which options are selected — owned by + SelectableCardGroup for members and by the product callsite for standalone + cards. - Navigation and one-shot actions — owned by `component:ClickableCard`. ## Public concepts -| Concept | Closed values or states | Meaning | Availability by variant/orientation/state | Default | Owner | Stability | Invalid-value behavior | -| --------- | ------------------------------ | ----------------------------------------------------------------------------------- | ----------------------------------------- | --------- | -------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------- | -| Selection | selected; unselected | Controlled checked state, reflected as `data-selected`. | Always | Required | `component:SelectableCard` | Stable | — | -| Disabled | enabled; disabled | Blocks toggling while keeping the checkbox focusable, reflected as `data-disabled`. | Always | enabled | `component:SelectableCard` | Stable | — | -| Variant | Card variants; theme additions | Card paint and the matching selection ring color. | Always | `default` | `component:Card` | Stable | A theme-added variant rings in `--selectable-card-ring-color` (default `--color-accent`) and keeps its border color. | +| Concept | Closed values or states | Meaning | Availability by variant/orientation/state | Default | Owner | Stability | Invalid-value behavior | +| ----------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------- | ------------------------------------------------ | -------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Selection | selected; unselected | Controlled checked state, reflected as `data-selected`; a member's comes from its group. | Always | Required standalone; from the group for a member | `component:SelectableCard` | Stable | — | +| Disabled | enabled; disabled | Blocks toggling while keeping the input focusable, reflected as `data-disabled`; a group's `isDisabled` disables every member. | Always | enabled | `component:SelectableCard` | Stable | — | +| Variant | Card variants; theme additions | Card paint and the matching selection ring color. | Always | `default` | `component:Card` | Stable | A theme-added variant rings in `--selectable-card-ring-color` (default `--color-accent`) and keeps its border color. | +| Group value | a string | Identifies the card as a `SelectableCardGroup` member; the group's `value` names the selected members. | Inside `SelectableCardGroup` | none | `component:SelectableCard` | Stable | TypeScript rejects `isSelected` or `onChange` beside it (`spec:AST-002` FR15). Outside a group, a card with a `value` warns in development and renders unselected and inert. | ## Behavioral and layout contract -| ID | Invariant | Basis | -| --- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ | -| FR1 | SelectableCard renders `component:Card` with the given `variant`, `elevation`, `padding`, and sizing. The root also carries the `selectable-card` target reflecting `variant`, `selected`, and, while disabled, `disabled`, and the first child is a visually hidden native `input type="checkbox"` named by `label` with `checked` equal to `isSelected`. | Current source and tests | -| FR2 | While enabled, a click on the card surface, a click or Space on the checkbox, or Enter on the checkbox calls `onChange(!isSelected)` exactly once. A click that belongs to nested interactive content, an open Tooltip or HoverCard surface (`component:Tooltip` FR11), or selected text does not toggle. A caller `onClick` runs after the toggle for a surface click, before it for a click or Space on the checkbox, and not at all for Enter; it also runs for clicks that do not toggle, including a click inside an open Tooltip or HoverCard surface. At the next minor, staged as `[breaking]`, a click inside an open layer stops at the layer root and the caller `onClick` no longer receives it (`architecture:layer-runtime` INV17); implementation gap: the current source still delivers that click to `onClick`. A caller `onMouseUp` runs after the card's own handling. | Current source and tests | -| FR3 | Selection adds a 2px inset ring through Card's ring variable, so layout does not move, and composes with any elevation shadow. `default`, `transparent`, and `muted` ring in `--color-accent`; each palette variant rings in its `--color-border-`; a theme-added variant rings in `--selectable-card-ring-color`. Selection also colors the border in the ring color where Card draws one, which is only the `default` variant. Under forced colors, which drop the ring's shadow and repaint the border, a selected card, enabled or disabled, draws a 2px ring in the system `Highlight` color inside its edge instead, on a layer that takes no space and that a theme's border color on the card does not reach, so the selection stays visible, a toggle moves nothing, and the ring keeps `Highlight` under a theme that sets the card's border color; an unselected card draws none. On a fixed-height card whose content scrolls, the ring scrolls with that content and can leave view entirely. | Current source and tests | -| FR4 | While enabled, the surface paints the shared hover overlay under a hover-capable pointer and the pressed overlay for mouse and touch presses; a press from any pointer that starts on a nested interactive element shows no pressed paint on the card, since it does not activate the card (`architecture:press-feedback` INV7). A touch press shows at once. Under the touch presentation, its release fades on the theme's exit motion tokens (`--duration-exit`, `--ease-exit`), per `spec:AST-094` FR5; a mouse press keeps the card's desktop press styling. Keyboard focus on the hidden checkbox shows one indicator on the card root (`architecture:interaction-modality` INV3). | Current source and tests | -| FR5 | `isDisabled` dims the card to half opacity, removes the card's own click and mouseup handling and the caller's `onClick` and `onMouseUp` (other caller event props still reach the root) and the hover and pressed overlays (`spec:AST-085` FR6), and keeps the checkbox focusable with `aria-disabled="true"`; no click, Space, or Enter calls `onChange`. The half opacity also dims a selected disabled card's forced-colors ring (FR3); WCAG 1.4.11 exempts inactive components from its contrast minimum. The disabled state is reflected on the owning target as `data-disabled` (`architecture:component-theming-surface` INV6). | Current source and tests | -| FR6 | `ref` reaches the Card root. Supported DOM, ARIA, data, and event props reach the root; `xstyle`, `className`, and `style` merge after the component's interactive styles. | Current source and tests | +| ID | Invariant | Basis | +| --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ | +| FR1 | SelectableCard renders `component:Card` with the given `variant`, `elevation`, `padding`, and sizing. The root also carries the `selectable-card` target reflecting `variant`, `selected`, and, while disabled, `disabled`, and the first child is a visually hidden native `input` named by `label`: `type="checkbox"`, or `type="radio"` with the group's name for a member of a single-choice group, with `checked` equal to the effective selection. A member's input carries its `value`; a checkbox member's carries the group's form name, and a selected, enabled radio member renders a hidden input after it that submits its `value` under that name. | Current source and tests | +| FR2 | While enabled, a click on the card surface, a click or Space on the input, or Enter on the input requests one change: a standalone card calls `onChange(!isSelected)` exactly once; a member asks its group once to toggle its `value`, or, as a radio, to select it when it is unselected. A click that belongs to nested interactive content, an open Tooltip or HoverCard surface (`component:Tooltip` FR11), or selected text does not toggle. A caller `onClick` runs after the toggle for a surface click, before it for a click or Space on the input, and not at all for Enter; it also runs for clicks that do not toggle, including a click inside an open Tooltip or HoverCard surface. At the next minor, staged as `[breaking]`, a click inside an open layer stops at the layer root and the caller `onClick` no longer receives it (`architecture:layer-runtime` INV17); implementation gap: the current source still delivers that click to `onClick`. A caller `onMouseUp` runs after the card's own handling. | Current source and tests | +| FR3 | Selection adds a 2px inset ring through Card's ring variable, so layout does not move, and composes with any elevation shadow. `default`, `transparent`, and `muted` ring in `--color-accent`; each palette variant rings in its `--color-border-`; a theme-added variant rings in `--selectable-card-ring-color`. Selection also colors the border in the ring color where Card draws one, which is only the `default` variant. Under forced colors, which drop the ring's shadow and repaint the border, a selected card, enabled or disabled, draws a 2px ring in the system `Highlight` color inside its edge instead, on a layer that takes no space and that a theme's border color on the card does not reach, so the selection stays visible, a toggle moves nothing, and the ring keeps `Highlight` under a theme that sets the card's border color; an unselected card draws none. On a fixed-height card whose content scrolls, the ring scrolls with that content and can leave view entirely. | Current source and tests | +| FR4 | While enabled, the surface paints the shared hover overlay under a hover-capable pointer and the pressed overlay for mouse and touch presses; a press from any pointer that starts on a nested interactive element shows no pressed paint on the card, since it does not activate the card (`architecture:press-feedback` INV7). A touch press shows at once. Under the touch presentation, its release fades on the theme's exit motion tokens (`--duration-exit`, `--ease-exit`), per `spec:AST-094` FR5; a mouse press keeps the card's desktop press styling. Keyboard focus on the hidden input shows one indicator on the card root (`architecture:interaction-modality` INV3). | Current source and tests | +| FR5 | `isDisabled`, or the group's `isDisabled`, dims the card to half opacity, removes the card's own click and mouseup handling and the caller's `onClick` and `onMouseUp` (other caller event props still reach the root) and the hover and pressed overlays (`spec:AST-085` FR6), and keeps the input focusable with `aria-disabled="true"`; no click, Space, or Enter requests a change. The half opacity also dims a selected disabled card's forced-colors ring (FR3); WCAG 1.4.11 exempts inactive components from its contrast minimum. The disabled state is reflected on the owning target as `data-disabled` (`architecture:component-theming-surface` INV6). | Current source and tests | +| FR6 | `ref` reaches the Card root. Supported DOM, ARIA, data, and event props reach the root; `xstyle`, `className`, and `style` merge after the component's interactive styles. | Current source and tests | ### Allowed variation @@ -165,15 +178,16 @@ Consumer migration instructions belong in consumer docs and release notes. | Selected | Checked; inset ring in the variant's color, and a matching border on `default`; a `Highlight` ring under forced colors; layout unchanged. | Elevation. | | Keyboard focus | Focus outline on the card root. | — | | Disabled | Focusable checkbox with `aria-disabled`; no toggle; half opacity. | Selection. | +| Radio member | A checked native radio in the group's named set; activating it again changes nothing. | Variant. | | Nested control | Activating the nested control does not toggle the card. | Control type. | ### Transformation and precedence order - **ORD1 — Toggle.** Disabled → nothing runs, caller `onClick` and `onMouseUp` included; nested interactive target or selection → no toggle, - caller handlers still run; otherwise one `onChange(!isSelected)`, with a + caller handlers still run; otherwise one change request (FR2), with a caller `onClick` after it for a surface click, before it for a click or - Space on the checkbox, and not at all for Enter. + Space on the input, and not at all for Enter. - **ORD2 — Ring color.** Built-in variant mapping → `--selectable-card-ring-color` for a theme-added variant. @@ -188,11 +202,13 @@ Consumer migration instructions belong in consumer docs and release notes. ## Accessibility contract -- **AR1 — Native checkbox.** The hidden checkbox supplies the role, name, and - checked state; the card root adds no role or tab stop of its own, except +- **AR1 — Native input.** The hidden checkbox, or the radio in a single-choice + group, supplies the role, name, and checked state; radios that share a + group's name are one tab stop, and the arrow keys move between them; the + card root adds no role or tab stop of its own, except that a fixed-height card whose content overflows is a scroll container that browsers may make an unnamed tab stop (`component:Card` AR1). -- **AR2 — Delegated focus indicator.** Keyboard focus on the hidden checkbox is +- **AR2 — Delegated focus indicator.** Keyboard focus on the hidden input is shown on the visible card root (`architecture:interaction-modality` INV3); a focused nested control shows only its own outline. - **AR3 — Focusable disabled.** A disabled card keeps its tab stop, exposes @@ -236,25 +252,38 @@ Consumer migration instructions belong in consumer docs and release notes. - `architecture:component-theming-surface` sets the rules the `selectable-card` target follows and requires a safe baseline for the extensible `variant`, which `--selectable-card-ring-color` satisfies. +- SelectableCardGroup owns group semantics and selection for members + identified by `value`. +- `spec:AST-038` FR8 stops group membership at a layer boundary: a card with a + `value` in a layer opened inside a group is not a member. ## Verification map -| Contract | Verification | Representative states | Mutation or failure expectation | Audit section | -| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | -| FR1, FR2 | `SelectableCard.test.tsx` surface, checkbox, Enter, and Space tests | Unselected, selected | A missed toggle, a wrong `onChange` value, or a doubled toggle from Space fails. Target-reflection and handler-order tests fail on a lost target, variant, selection, or disabled reflection, or a changed order of `onChange` and a caller `onClick`. Gap: no test asserts the order of an enabled caller `onMouseUp`. | `audit:SelectableCard/behavior` | -| FR3 | `SelectableCard.test.tsx` elevation tests; stable visual baseline `core-selectablecard--single-select`; `SelectableCard.stories.tsx` | Selected with elevation; one selected default card beside unselected ones | A lost elevation while selected fails; a changed default ring or border comes back changed for review. Gap: palette and theme-added ring colors have no automated check. | `audit:SelectableCard/theming` | -| FR3 (forced colors) | `SelectableCard.test.tsx` forced-colors test; `SelectableCardForcedColors.a11y.chromium.spec.ts` on the multi-select, color-variants and disabled stories, the probe theme, a toggle, and a zero-padding card | Selected and unselected cards under forced colors; a selected card under a theme that sets the card's border color; a toggle; a selected card with zero padding; the same cards outside forced colors | A selected card without a 2px `Highlight` ring inside its edge under forced colors, a themed card whose ring loses `Highlight`, a toggle that moves a card, an unselected card with a ring, or a ring outside forced colors fails. Gap: no test covers the ring on a fixed-height card whose content scrolls. | `audit:SelectableCard/a11y` | -| FR4 | `SelectableCard.test.tsx` touch-press test; `CardPress.a11y.chromium.spec.ts` on `core-selectablecard--single-select` | Rest; desktop hover and mouse press; touch press | A hover that does not paint over rest, a mouse press that does not paint over hover, or a touch press that does not match the desktop press or fade fails. `FocusRingOwner.a11y.chromium.spec.ts` fails if a focused nested button shows other than exactly one ring. | `audit:SelectableCard/design` | -| FR5, AR3 | `SelectableCard.test.tsx` disabled tests; `Checkbox.a11y.chromium.spec.ts` `card-disabled` state | Disabled click, Enter, Space | A toggle while disabled, or a disabled card that leaves keyboard reach, fails. `SelectableCardAudit.a11y.chromium.spec.ts` fails on a lost half opacity, a hover overlay on a disabled card, or a missing `data-disabled`. Gap: no test asserts the absent pressed overlay on a disabled card. | `audit:SelectableCard/a11y` | -| FR2 (nested) | `SelectableCard.test.tsx` nested-button test; `SelectableCardAudit.a11y.chromium.spec.ts` on `core-selectablecard--with-nested-button` | Card with a nested control or selected text | A click on a nested button that toggles the card fails. Gap: no test covers selected-text suppression. | `audit:SelectableCard/behavior` | -| Theming anatomy map | `scripts/check-knowledge.mjs` | Consumer anatomy and current target | Missing, extra, or stale mappings fail repository validation. | `audit:SelectableCard/theming` | -| AR1, AR2, AR4 | `SelectableCard.test.tsx` checkbox tests; `Checkbox.a11y.test.tsx` and `Checkbox.a11y.chromium.spec.ts` SelectableCard states | Unchecked, checked, disabled (`card-unchecked`, `card-checked`, `card-disabled`) | A lost checkbox role or name, a wrong checked state, or a disabled card that is not exposed as unavailable or not reachable fails, including at the accessibility tree. The passthrough test fails if the root gains a role or tab stop; `SelectableCardAudit.a11y.chromium.spec.ts` fails on a missing root focus outline or a ring that changes under hover. | `audit:SelectableCard/a11y` | -| FR6, PR1 | `SelectableCard.test.tsx` passthrough test; source review | Ref; caller props | A `ref`, `data-*`, `className`, or `style` that stops reaching the root fails. Gap: no test asserts `xstyle` or the merge order of the styling inputs, or fails if SelectableCard adds its own listener or timer. | `audit:SelectableCard/behavior` | -| AR5 | `Checkbox.a11y.chromium.spec.ts` aborted-press check on the SelectableCard states | Press that slides off the card before the lift | A toggle after a slide-off lift fails. | `audit:SelectableCard/a11y` | +| Contract | Verification | Representative states | Mutation or failure expectation | Audit section | +| ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | +| FR1, FR2 | `SelectableCard.test.tsx` surface, checkbox, Enter, and Space tests | Unselected, selected | A missed toggle, a wrong `onChange` value, or a doubled toggle from Space fails. Target-reflection and handler-order tests fail on a lost target, variant, selection, or disabled reflection, or a changed order of `onChange` and a caller `onClick`. Gap: no test asserts the order of an enabled caller `onMouseUp`. | `audit:SelectableCard/behavior` | +| FR3 | `SelectableCard.test.tsx` elevation tests; stable visual baseline `core-selectablecard--single-select`; `SelectableCard.stories.tsx` | Selected with elevation; one selected default card beside unselected ones | A lost elevation while selected fails; a changed default ring or border comes back changed for review. Gap: palette and theme-added ring colors have no automated check. | `audit:SelectableCard/theming` | +| FR3 (forced colors) | `SelectableCard.test.tsx` forced-colors test; `SelectableCardForcedColors.a11y.chromium.spec.ts` on the multi-select, color-variants and disabled stories, the probe theme, a toggle, and a zero-padding card | Selected and unselected cards under forced colors; a selected card under a theme that sets the card's border color; a toggle; a selected card with zero padding; the same cards outside forced colors | A selected card without a 2px `Highlight` ring inside its edge under forced colors, a themed card whose ring loses `Highlight`, a toggle that moves a card, an unselected card with a ring, or a ring outside forced colors fails. Gap: no test covers the ring on a fixed-height card whose content scrolls. | `audit:SelectableCard/a11y` | +| FR4 | `SelectableCard.test.tsx` touch-press test; `CardPress.a11y.chromium.spec.ts` on `core-selectablecard--single-select` | Rest; desktop hover and mouse press; touch press | A hover that does not paint over rest, a mouse press that does not paint over hover, or a touch press that does not match the desktop press or fade fails. `FocusRingOwner.a11y.chromium.spec.ts` fails if a focused nested button shows other than exactly one ring. | `audit:SelectableCard/design` | +| FR5, AR3 | `SelectableCard.test.tsx` disabled tests; `Checkbox.a11y.chromium.spec.ts` `card-disabled` state | Disabled click, Enter, Space | A toggle while disabled, or a disabled card that leaves keyboard reach, fails. `SelectableCardAudit.a11y.chromium.spec.ts` fails on a lost half opacity, a hover overlay on a disabled card, or a missing `data-disabled`. Gap: no test asserts the absent pressed overlay on a disabled card. | `audit:SelectableCard/a11y` | +| FR2 (nested) | `SelectableCard.test.tsx` nested-button test; `SelectableCardAudit.a11y.chromium.spec.ts` on `core-selectablecard--with-nested-button` | Card with a nested control or selected text | A click on a nested button that toggles the card fails. Gap: no test covers selected-text suppression. | `audit:SelectableCard/behavior` | +| Theming anatomy map | `scripts/check-knowledge.mjs` | Consumer anatomy and current target | Missing, extra, or stale mappings fail repository validation. | `audit:SelectableCard/theming` | +| AR1, AR2, AR4 | `SelectableCard.test.tsx` checkbox tests; `Checkbox.a11y.test.tsx` and `Checkbox.a11y.chromium.spec.ts` SelectableCard states | Unchecked, checked, disabled (`card-unchecked`, `card-checked`, `card-disabled`) | A lost checkbox role or name, a wrong checked state, or a disabled card that is not exposed as unavailable or not reachable fails, including at the accessibility tree. The passthrough test fails if the root gains a role or tab stop; `SelectableCardAudit.a11y.chromium.spec.ts` fails on a missing root focus outline or a ring that changes under hover. | `audit:SelectableCard/a11y` | +| FR6, PR1 | `SelectableCard.test.tsx` passthrough test; source review | Ref; caller props | A `ref`, `data-*`, `className`, or `style` that stops reaching the root fails. Gap: no test asserts `xstyle` or the merge order of the styling inputs, or fails if SelectableCard adds its own listener or timer. | `audit:SelectableCard/behavior` | +| AR5 | `Checkbox.a11y.chromium.spec.ts` aborted-press check on the SelectableCard states | Press that slides off the card before the lift | A toggle after a slide-off lift fails. | `audit:SelectableCard/a11y` | +| Group membership (FR1, FR2, FR5, AR1) | `SelectableCardRadio.test.tsx`; SelectableCardGroup's tests and `SelectableCardGroupRadio.a11y.chromium.spec.ts` | Radio member, checkbox member, disabled group, a member disabled on its own, `value` outside a group, a card in a layer inside a group | A radio member that deselects itself, a single-choice member that renders a checkbox, a radio set that is not one tab stop, a member that ignores the group's disabled state, or a card in a layer that joins the group fails. | `audit:SelectableCard/behavior` | ## Decision log -None recorded. +### DEC-1 — A card joins a SelectableCardGroup by `value` + +**Reference:** `component:SelectableCard/DEC-1` +**Decider:** `cixzhang`, `2026-11-05` + +A member identified by `value` takes its selection and selection requests from +its group, as a ToggleButtonGroup member does (`family:buttons` FR11). + +Rejected: a separate item component that wraps the card. ## Open questions diff --git a/packages/cli/test/swizzle-proof/samples.mjs b/packages/cli/test/swizzle-proof/samples.mjs index e611abfac4550..41d52f3cec3fd 100644 --- a/packages/cli/test/swizzle-proof/samples.mjs +++ b/packages/cli/test/swizzle-proof/samples.mjs @@ -785,15 +785,16 @@ export const samples = { {maxLines: 2}, 'A long paragraph that runs past two lines, so the clamp cuts it short and shows the rest only when it is expanded by the reader.', ), - lab__SelectableCardGroup: ({C, React, mod, Pkg}) => { - const Item = mod.SelectableCardGroupItem ?? Pkg.SelectableCardGroupItem; - return React.createElement( + lab__SelectableCardGroup: ({C, React, Core}) => + React.createElement( C, {label: 'Plan', value: 'pro', onChange: noop}, - React.createElement(Item, {value: 'basic', label: 'Basic'}), - React.createElement(Item, {value: 'pro', label: 'Pro'}), - ); - }, + React.createElement(Core.SelectableCard, { + value: 'basic', + label: 'Basic', + }), + React.createElement(Core.SelectableCard, {value: 'pro', label: 'Pro'}), + ), lab__Stat: ({C, React}) => React.createElement(C, {label: 'Revenue', value: '$12.4k'}), lab__TabBar: ({C, React, mod, Pkg}) => { diff --git a/packages/core/src/SelectableCard/SelectableCard.doc.mjs b/packages/core/src/SelectableCard/SelectableCard.doc.mjs index c55673614ca54..1a88fb195034a 100644 --- a/packages/core/src/SelectableCard/SelectableCard.doc.mjs +++ b/packages/core/src/SelectableCard/SelectableCard.doc.mjs @@ -14,7 +14,7 @@ export const docs = { {guidance: true, description: 'Use for multi-select groups; track the selected IDs in a Set.'}, {guidance: true, description: 'When focused, toggle selection with Space or Enter.'}, {guidance: false, description: 'Use for navigation; use ClickableCard for that.'}, - {guidance: false, description: 'Use for a single-select group: each card is a checkbox, so assistive technology announces a multi-select group with one tab stop per card.'}, + {guidance: false, description: 'Build a single-select group from standalone cards: each one is a checkbox, so assistive technology announces a multi-select group with one tab stop per card. Give each card a `value` inside a SelectableCardGroup instead.'}, ], anatomy: [ {name: 'Container', required: true, description: 'Interactive div with accent border on selection.'}, @@ -22,10 +22,11 @@ export const docs = { ], }, props: [ - {name: 'label', type: 'string', description: "Accessible name of the card's checkbox. Name the option the card stands for: a screen reader announces it with the checked state.", required: true}, - {name: 'isSelected', type: 'boolean', description: 'Controlled selection state.', required: true}, - {name: 'onChange', type: '(isSelected: boolean) => void', description: 'Called when toggled.', required: true}, - {name: 'isDisabled', type: 'boolean', description: 'Disables the card.', default: 'false'}, + {name: 'label', type: 'string', description: "Accessible name of the card's checkbox, or of its radio in a single-choice SelectableCardGroup. Name the option the card stands for: a screen reader announces it with the checked state.", required: true}, + {name: 'isSelected', type: 'boolean', description: 'Controlled selection state. Required for a standalone card; a card with a `value` takes it from its group instead.'}, + {name: 'onChange', type: '(isSelected: boolean) => void', description: 'Called when toggled. Required for a standalone card; a card with a `value` asks its group instead.'}, + {name: 'value', type: 'string', description: "The value this card stands for in a SelectableCardGroup's `value`. It makes the card a member of the group around it, in place of `isSelected` and `onChange`: the group gives the card its selection, a radio or checkbox input, and its disabled default."}, + {name: 'isDisabled', type: 'boolean', description: 'Disables the card. In a SelectableCardGroup, a disabled group disables every card, and an enabled group does not enable a card that disables itself.', default: 'false'}, {name: 'children', type: 'ReactNode', description: 'Card content.'}, {name: 'padding', type: '0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10', description: 'Inner padding.', default: '4'}, {name: 'variant', type: "'default' | 'transparent' | 'muted' | 'blue' | 'cyan' | 'gray' | 'green' | 'orange' | 'pink' | 'purple' | 'red' | 'teal' | 'yellow'", description: 'Background color variant.', default: "'default'"}, @@ -70,14 +71,15 @@ export const docsDense = { {guidance: true, description: 'Use for multi-select groups; track selected IDs in a Set.'}, {guidance: true, description: 'When focused, toggle selection with Space or Enter.'}, {guidance: false, description: 'Use for navigation; use ClickableCard instead.'}, - {guidance: false, description: 'Use for single-select: each card is a checkbox, so screen readers announce multi-select.'}, + {guidance: false, description: 'Build single-select from standalone cards: each is a checkbox, so screen readers announce multi-select. Use a SelectableCardGroup of cards w/ `value` instead.'}, ], }, propDescriptions: { - label: "checkbox's accessible name; name the option", - isSelected: 'controlled selection state', - onChange: 'called when toggled', - isDisabled: 'disables card', + label: "checkbox or radio's accessible name; name the option", + isSelected: 'controlled selection state; required standalone, from the group w/ value', + onChange: 'called when toggled; required standalone', + value: 'joins the SelectableCardGroup around it: the group owns selection, input type, disabled default', + isDisabled: 'disables card; a disabled group disables every card', padding: 'inner padding', variant: 'background color variant', elevation: 'resting shadow depth: none|low|med|high; selection ring composes on top', diff --git a/packages/core/src/SelectableCard/SelectableCard.tsx b/packages/core/src/SelectableCard/SelectableCard.tsx index d34981d08ff0a..144a297e6aafc 100644 --- a/packages/core/src/SelectableCard/SelectableCard.tsx +++ b/packages/core/src/SelectableCard/SelectableCard.tsx @@ -5,7 +5,7 @@ /** * @file SelectableCard.tsx * @input Uses Card, useClickableContainer, StyleX - * @output Exports SelectableCard component and SelectableCardProps + * @output Exports SelectableCard, SelectableCardProps and SelectableCardMemberProps * @position Interactive card for toggle selection * * SYNC: When modified, update these files to stay in sync: @@ -23,8 +23,8 @@ * A hidden inside the card provides the accessible * role, label, and checked state — the card surface itself has no role/tabIndex. * Space toggles it natively; Enter is wired up as an additional toggle key. - * Inside a single-choice group (Lab's SelectableCardGroup, through an internal - * context) the input is a radio: the card selects and never deselects itself. + * With a `value`, the card's group owns its selection and input; in a single + * choice the input is a radio, which never deselects itself. * * For static display, use Card. * For navigation or action cards, use ClickableCard. @@ -59,7 +59,8 @@ import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex'; import {usePressFeedback} from '../hooks/usePressFeedback'; import {useMergedRefs} from '../hooks/useMergedRefs'; -import {SelectableCardInputContext} from './selectableCardInput'; +import {useDevWarning} from '../hooks/useDevWarning'; +import {SelectableCardGroupContext} from './selectableCardGroupContext'; // ============================================================================= // Styles — selection + interaction; Card handles the rest // ============================================================================= @@ -356,6 +357,8 @@ export interface SelectableCardProps extends Omit { * Set to true to disable the card. * Disabled cards remain focusable (tabIndex 0) with aria-disabled * so screen reader users can discover them. + * In a SelectableCardGroup, a disabled group disables every card, and an + * enabled group does not enable a card that disables itself. */ isDisabled?: boolean; @@ -389,6 +392,29 @@ export interface SelectableCardProps extends Omit { /** Maximum width of the card. */ maxWidth?: SizeValue; + + /** + * Only a SelectableCardGroup member takes a `value`, in place of + * `isSelected` and `onChange` (SelectableCardMemberProps). + */ + value?: never; +} + +/** + * A SelectableCard in a SelectableCardGroup: a `value` in place of + * `isSelected` and `onChange`. The group gives the card its selection, its + * input and its disabled default. + */ +export interface SelectableCardMemberProps extends Omit< + SelectableCardProps, + 'isSelected' | 'onChange' | 'value' +> { + /** The value this card stands for in the group's `value`. */ + value: string; + + isSelected?: never; + + onChange?: never; } // ============================================================================= @@ -444,10 +470,14 @@ function callBeforeLayerHandlers( * the accessible role, label, and checked state. The card surface * is a plain
— no role or tabIndex on the container. * + * With a `value` instead of `isSelected` and `onChange`, the card is a + * member of the SelectableCardGroup around it. The group owns its selection, + * and in a single-choice group the card is a radio. + * * @compositionHint Use for multi-select card groups, managing selection - * state externally in a Set. Not for single-select: each card is a - * checkbox, so assistive technology announces a multi-select group. - * For navigation/action cards, use ClickableCard instead. + * state externally in a Set. Standalone cards are checkboxes, so do not + * build a single-select set from them: give each card a `value` inside a + * SelectableCardGroup. For navigation/action cards, use ClickableCard instead. * * @example * ``` @@ -461,12 +491,13 @@ function callBeforeLayerHandlers( */ export function SelectableCard({ label, - isSelected, + isSelected: isSelectedProp, onChange, + value, onClick: onClickProp, onMouseUp: onMouseUpProp, onPointerDown: onPointerDownProp, - isDisabled = false, + isDisabled: isDisabledProp = false, children, padding, variant = 'default', @@ -479,22 +510,41 @@ export function SelectableCard({ className: classNameProp, style, ...props -}: SelectableCardProps) { +}: SelectableCardProps | SelectableCardMemberProps) { const pressable = usePressFeedback(); const containerRef = useRef(null); const interactiveRef = useRef(null); - // A group can make the input a radio. A radio only selects: a native radio - // stays checked when it is clicked again. - const groupInput = use(SelectableCardInputContext); - const isRadio = groupInput?.type === 'radio'; + // A `value` makes the card a member of the group around it. Outside a group, + // such a card has no selection to show or change. + const groupContext = use(SelectableCardGroupContext); + const group = value == null ? null : groupContext; + useDevWarning( + 'SelectableCard', + 'A card with a `value` takes its selection from a SelectableCardGroup, and no SelectableCardGroup in the same layer is around it. Render it inside one, or pass `isSelected` and `onChange` instead of `value`.', + value != null && groupContext == null, + ); + const isSelected = + value == null + ? isSelectedProp === true + : (group?.isSelected(value) ?? false); + // Either the group or the card disabling it is enough: a group cannot + // enable a card that disables itself. + const isDisabled = (group?.isDisabled ?? false) || isDisabledProp; + // A radio only selects: a native radio stays checked when it is clicked + // again. + const isRadio = group?.inputType === 'radio'; const requestChange = useCallback(() => { - if (!isRadio) { - onChange(!isSelected); + if (value == null) { + onChange?.(!isSelected); + } else if (group == null) { + return; + } else if (!isRadio) { + group.onMemberChange(value, !isSelected); } else if (!isSelected) { - onChange(true); + group.onMemberChange(value, true); } - }, [isRadio, isSelected, onChange]); + }, [group, isRadio, isSelected, onChange, value]); const handleClick = useCallback( (_event: MouseEvent) => { @@ -620,17 +670,13 @@ export function SelectableCard({ + {group != null && isRadio && isSelected && !isDisabled ? ( + + ) : null} {children} ); diff --git a/packages/core/src/SelectableCard/SelectableCardRadio.test.tsx b/packages/core/src/SelectableCard/SelectableCardRadio.test.tsx index 3e82619818a72..2ae9930153295 100644 --- a/packages/core/src/SelectableCard/SelectableCardRadio.test.tsx +++ b/packages/core/src/SelectableCard/SelectableCardRadio.test.tsx @@ -2,54 +2,114 @@ /** * @file SelectableCardRadio.test.tsx - * @input Uses SelectableCard, its internal input context, and Testing Library - * @output Tests for SelectableCard's radio input - * @position A card a group renders as a radio (through the internal - * SelectableCardInputContext) is one choice of a set: a native radio in the - * set's named group that selects and never deselects itself. + * @input Uses SelectableCard, its internal group context, and Testing Library + * @output Tests for a SelectableCard that a `value` makes a group member + * @position A member takes its selection, input, name and disabled default + * from the group (the internal SelectableCardGroupContext). In a + * single-choice group it is a native radio that selects and never + * deselects itself. */ -import {useMemo, useState} from 'react'; +import {useMemo, useState, type ReactNode} from 'react'; import {describe, it, expect, vi} from 'vitest'; import {render, screen, fireEvent} from '@testing-library/react'; -import {SelectableCard, type SelectableCardProps} from './SelectableCard'; -import {SelectableCardInputContext} from './selectableCardInput'; +import { + SelectableCard, + type SelectableCardMemberProps, + type SelectableCardProps, +} from './SelectableCard'; +import { + SelectableCardGroupContext, + type SelectableCardGroupMembership, +} from './selectableCardGroupContext'; +import {Dialog} from '../Dialog/Dialog'; -/** A card the way a single-choice group renders it. */ -function RadioCard({value, ...props}: SelectableCardProps & {value: string}) { - const input = useMemo( +/** A group the way a single-choice SelectableCardGroup provides it. */ +function RadioGroup({ + value, + onChange, + isDisabled = false, + children, +}: { + value: string | null; + onChange: (value: string) => void; + isDisabled?: boolean; + children: ReactNode; +}) { + const membership = useMemo( () => ({ - type: 'radio' as const, - name: 'plan', - value, + inputType: 'radio', + inputName: 'plan-radios', + submitName: 'plan', + isDisabled, + isSelected: v => v === value, + onMemberChange: (v, isSelected) => { + if (isSelected) { + onChange(v); + } + }, }), - [value], + [isDisabled, onChange, value], ); return ( - - - +
+ + {children} + +
+ ); +} + +/** A group the way a multiple-choice SelectableCardGroup provides it. */ +function CheckboxGroup({ + value, + onChange, + isDisabled = false, + children, +}: { + value: ReadonlyArray; + onChange: (value: string[]) => void; + isDisabled?: boolean; + children: ReactNode; +}) { + const membership = useMemo( + () => ({ + inputType: 'checkbox', + inputName: 'addons', + submitName: 'addons', + isDisabled, + isSelected: v => value.includes(v), + onMemberChange: (v, isSelected) => + onChange( + isSelected + ? [...value.filter(x => x !== v), v] + : value.filter(x => x !== v), + ), + }), + [isDisabled, onChange, value], + ); + return ( + + {children} + ); } function Plans({onChange}: {onChange?: (value: string) => void}) { const [value, setValue] = useState('basic'); return ( -
+ { + setValue(v); + onChange?.(v); + }}> {['basic', 'pro', 'team'].map(plan => ( - { - setValue(plan); - onChange?.(plan); - }}> + {plan} - + ))} -
+ ); } @@ -60,9 +120,8 @@ describe('SelectableCard as a group radio', () => { expect(radios).toHaveLength(3); for (const radio of radios) { expect(radio).toHaveAttribute('type', 'radio'); - expect(radio).toHaveAttribute('name', 'plan'); + expect(radio).toHaveAttribute('name', 'plan-radios'); } - // A form submits the chosen card's value, not "on". expect(screen.getByRole('radio', {name: 'pro'})).toHaveAttribute( 'value', 'pro', @@ -75,6 +134,7 @@ describe('SelectableCard as a group radio', () => { const onChange = vi.fn(); render(); fireEvent.click(screen.getByText('pro')); + expect(onChange).toHaveBeenCalledTimes(1); expect(onChange).toHaveBeenCalledWith('pro'); expect(screen.getByRole('radio', {name: 'pro'})).toBeChecked(); expect(screen.getByRole('radio', {name: 'basic'})).not.toBeChecked(); @@ -83,9 +143,11 @@ describe('SelectableCard as a group radio', () => { it('never deselects itself: a click or Enter on the selected card does nothing', () => { const onChange = vi.fn(); render( - - Basic - , + + + Basic + + , ); fireEvent.click(screen.getByText('Basic')); fireEvent.keyDown(screen.getByRole('radio'), {key: 'Enter'}); @@ -95,26 +157,25 @@ describe('SelectableCard as a group radio', () => { it('selects on Enter when unselected', () => { const onChange = vi.fn(); render( - - Pro - , + + + Pro + + , ); fireEvent.keyDown(screen.getByRole('radio'), {key: 'Enter'}); expect(onChange).toHaveBeenCalledTimes(1); - expect(onChange).toHaveBeenCalledWith(true); + expect(onChange).toHaveBeenCalledWith('pro'); }); it('a disabled radio card stays focusable and does not select', () => { const onChange = vi.fn(); render( - - Team - , + + + Team + + , ); const radio = screen.getByRole('radio'); expect(radio).toHaveAttribute('aria-disabled', 'true'); @@ -126,6 +187,63 @@ describe('SelectableCard as a group radio', () => { expect(onChange).not.toHaveBeenCalled(); }); + it("a disabled group disables every member, and an enabled group keeps a member's own isDisabled", () => { + const onChange = vi.fn(); + const {rerender} = render( + + + Basic + + , + ); + expect(screen.getByRole('radio')).toHaveAttribute('aria-disabled', 'true'); + fireEvent.click(screen.getByText('Basic')); + expect(onChange).not.toHaveBeenCalled(); + rerender( + + + Basic + + , + ); + expect(screen.getByRole('radio')).toHaveAttribute('aria-disabled', 'true'); + fireEvent.click(screen.getByText('Basic')); + expect(onChange).not.toHaveBeenCalled(); + }); + + it("the chosen, enabled radio card submits its value under the group's name", () => { + const {container, rerender} = render( +
+ {}}> + + Basic + + + Pro + + +
, + ); + const form = container.querySelector('form'); + if (form == null) { + throw new Error('no form'); + } + expect([...new FormData(form).entries()]).toEqual([['plan', 'pro']]); + rerender( +
+ {}}> + + Basic + + + Pro + + +
, + ); + expect([...new FormData(form).entries()]).toEqual([]); + }); + it('keeps the checkbox without a group', () => { render( {}}> @@ -135,3 +253,158 @@ describe('SelectableCard as a group radio', () => { expect(screen.getByRole('checkbox')).toHaveAttribute('type', 'checkbox'); }); }); + +describe('SelectableCard as a group checkbox', () => { + it('toggles its value in the group and submits it while checked', () => { + const onChange = vi.fn(); + const {container} = render( +
+ + + Backup + + + Support + + +
, + ); + const backup = screen.getByRole('checkbox', {name: 'Backup'}); + expect(backup).toBeChecked(); + expect(backup).toHaveAttribute('name', 'addons'); + const form = container.querySelector('form'); + if (form == null) { + throw new Error('no form'); + } + expect([...new FormData(form).entries()]).toEqual([['addons', 'backup']]); + fireEvent.click(screen.getByText('Support')); + expect(onChange).toHaveBeenLastCalledWith(['backup', 'support']); + fireEvent.click(screen.getByText('Backup')); + expect(onChange).toHaveBeenLastCalledWith([]); + }); + + it('a disabled checkbox member submits nothing, whichever side disables it', () => { + const {container, rerender} = render( +
+ {}}> + + Backup + + +
, + ); + const form = container.querySelector('form'); + if (form == null) { + throw new Error('no form'); + } + expect(screen.getByRole('checkbox', {name: 'Backup'})).toBeChecked(); + expect([...new FormData(form).entries()]).toEqual([]); + rerender( +
+ {}} isDisabled> + + Backup + + +
, + ); + expect([...new FormData(form).entries()]).toEqual([]); + }); +}); + +describe('SelectableCard membership', () => { + it('a card without a value stays standalone inside a group', () => { + const onChange = vi.fn(); + const onCardChange = vi.fn(); + render( + + + Alone + + , + ); + expect(screen.getByRole('checkbox', {name: 'Alone'})).not.toHaveAttribute( + 'name', + ); + fireEvent.click(screen.getByText('Alone')); + expect(onCardChange).toHaveBeenCalledWith(true); + expect(onChange).not.toHaveBeenCalled(); + }); + + it('a card with a value outside a group warns in development and stays unselected and inert', () => { + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + render( + + Pro + , + ); + const input = screen.getByRole('checkbox', {name: 'Pro'}); + expect(input).not.toBeChecked(); + expect(input).not.toHaveAttribute('name'); + fireEvent.click(screen.getByText('Pro')); + fireEvent.keyDown(input, {key: 'Enter'}); + expect(input).not.toBeChecked(); + expect(warn).toHaveBeenCalledWith( + expect.stringContaining('SelectableCardGroup'), + ); + warn.mockRestore(); + }); + + it('membership stops at a layer: a card with a value in a layer inside a group is not a member', () => { + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + const onChange = vi.fn(); + render( + + {}}> + + Inner + + + , + ); + const input = screen.getByRole('checkbox', {name: 'Inner'}); + expect(input).not.toBeChecked(); + fireEvent.click(screen.getByText('Inner')); + expect(onChange).not.toHaveBeenCalled(); + warn.mockRestore(); + }); + + it('keeps SelectableCardProps an interface that callers extend and pass back', () => { + interface TrackedCardProps extends SelectableCardProps { + trackingID: string; + } + const tracked: TrackedCardProps = { + label: 'A', + isSelected: false, + onChange: () => {}, + trackingID: 'a', + }; + const {trackingID, ...card} = tracked; + const withoutVariant: Omit = card; + const member: SelectableCardMemberProps = {label: 'B', value: 'b'}; + render( + <> + {trackingID} + {}}> + B + + , + ); + expect(screen.getAllByRole('checkbox')).toHaveLength(2); + }); + + it('types a card as standalone or as a member, never both', () => { + const standalone = ( + {}} /> + ); + const member = ; + // @ts-expect-error a member takes its selection from the group + const both = ; + // @ts-expect-error a standalone card needs isSelected and onChange + const neither = ; + expect([standalone, member, both, neither]).toHaveLength(4); + }); +}); diff --git a/packages/core/src/SelectableCard/index.ts b/packages/core/src/SelectableCard/index.ts index 141073bcb5aeb..21e451314bbfe 100644 --- a/packages/core/src/SelectableCard/index.ts +++ b/packages/core/src/SelectableCard/index.ts @@ -1,4 +1,7 @@ // Copyright (c) Meta Platforms, Inc. and affiliates. export {SelectableCard} from './SelectableCard'; -export type {SelectableCardProps} from './SelectableCard'; +export type { + SelectableCardProps, + SelectableCardMemberProps, +} from './SelectableCard'; diff --git a/packages/core/src/SelectableCard/selectableCardGroupContext.ts b/packages/core/src/SelectableCard/selectableCardGroupContext.ts new file mode 100644 index 0000000000000..c0d9bc5f00585 --- /dev/null +++ b/packages/core/src/SelectableCard/selectableCardGroupContext.ts @@ -0,0 +1,40 @@ +// Copyright (c) Meta Platforms, Inc. and affiliates. + +'use client'; + +/** + * @file selectableCardGroupContext.ts + * @input The selection, input and disabled state of a group of cards + * @output SelectableCardGroupContext: what a group gives each SelectableCard + * that its `value` makes a member + * @position Internal: Lab's SelectableCardGroup provides it through + * `@astryxdesign/core/internal/selectable-card`. It is not public API. + */ + +import {createLayerScopedContext} from '../Layer/layerScopedContext'; + +/** What a group gives each card that it names by `value`. */ +export interface SelectableCardGroupMembership { + /** `radio` makes each member one choice of a single-choice set. */ + readonly inputType: 'checkbox' | 'radio'; + /** The members' input `name`. Radios that share it form one native group. */ + readonly inputName: string; + /** The name that the chosen radio member submits its value under. */ + readonly submitName: string; + /** Disables every member. A member can also disable itself. */ + readonly isDisabled: boolean; + readonly isSelected: (value: string) => boolean; + readonly onMemberChange: (value: string, isSelected: boolean) => void; +} + +/** + * Without a provider, a card with a `value` has no group. Membership stops at + * a layer boundary, so a card in a layer opened from a member is not a member. + */ +export const SelectableCardGroupContext = + createLayerScopedContext( + 'SelectableCardGroupContext', + 1, + null, + ); +SelectableCardGroupContext.displayName = 'SelectableCardGroupContext'; diff --git a/packages/core/src/SelectableCard/selectableCardInput.ts b/packages/core/src/SelectableCard/selectableCardInput.ts deleted file mode 100644 index 89e18558303b9..0000000000000 --- a/packages/core/src/SelectableCard/selectableCardInput.ts +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) Meta Platforms, Inc. and affiliates. - -'use client'; - -/** - * @file selectableCardInput.ts - * @input A card group's choice of native input for each card it renders - * @output SelectableCardInputContext: the input type, name and value a group - * gives one SelectableCard - * @position Internal: Lab's SelectableCardGroup provides it through - * `@astryxdesign/core/internal/selectable-card`. It is not public API, so - * SelectableCard's public props do not change. - */ - -import {createSharedContext} from '../utils/sharedContext'; - -/** The native input a group gives one card. */ -export interface SelectableCardInput { - /** `radio` makes the card one choice of a single-choice set. */ - readonly type: 'checkbox' | 'radio'; - /** The input's `name`. Radios that share it form one native group. */ - readonly name: string; - /** The input's `value`. A checkbox card submits it when it is selected. */ - readonly value: string; -} - -/** Without a provider, a card renders its own checkbox. */ -export const SelectableCardInputContext = - createSharedContext( - 'SelectableCardInputContext', - 1, - null, - ); -SelectableCardInputContext.displayName = 'SelectableCardInputContext'; diff --git a/packages/core/src/internal/selectable-card.ts b/packages/core/src/internal/selectable-card.ts index 90659b7fa3057..16a24e0902749 100644 --- a/packages/core/src/internal/selectable-card.ts +++ b/packages/core/src/internal/selectable-card.ts @@ -1,10 +1,10 @@ // Copyright (c) Meta Platforms, Inc. and affiliates. /** * @file selectable-card.ts - * @input SelectableCard's internal input context, the Field input styling + * @input SelectableCard's internal group context, the Field input styling * rule and the aria id joiner * @output `@astryxdesign/core/internal/selectable-card`: - * SelectableCardInputContext, useFieldInputStyling and joinAriaIDs, + * SelectableCardGroupContext, useFieldInputStyling and joinAriaIDs, * re-exported by name * for Lab's SelectableCardGroup * @position An internal entry reserved for Astryx's own packages: @@ -15,7 +15,7 @@ * * SYNC: When modified, update scripts/sync-exports.js. */ -export {SelectableCardInputContext} from '../SelectableCard/selectableCardInput'; -export type {SelectableCardInput} from '../SelectableCard/selectableCardInput'; +export {SelectableCardGroupContext} from '../SelectableCard/selectableCardGroupContext'; +export type {SelectableCardGroupMembership} from '../SelectableCard/selectableCardGroupContext'; export {useFieldInputStyling} from '../Field/fieldParts'; export {joinAriaIDs} from '../utils/inputAria'; diff --git a/packages/lab/blocks/SelectableCardGroupShippingSpeed.doc.mjs b/packages/lab/blocks/SelectableCardGroupShippingSpeed.doc.mjs index 90c268a4d6c36..1e5faef5dfe0d 100644 --- a/packages/lab/blocks/SelectableCardGroupShippingSpeed.doc.mjs +++ b/packages/lab/blocks/SelectableCardGroupShippingSpeed.doc.mjs @@ -12,6 +12,7 @@ export default { aspectRatio: 4 / 3, componentsUsed: [ 'SelectableCardGroup', + 'SelectableCard', 'HStack', 'StackItem', 'VStack', diff --git a/packages/lab/blocks/SelectableCardGroupShippingSpeed.tsx b/packages/lab/blocks/SelectableCardGroupShippingSpeed.tsx index 77925b97f392e..b2eaeaf043bf4 100644 --- a/packages/lab/blocks/SelectableCardGroupShippingSpeed.tsx +++ b/packages/lab/blocks/SelectableCardGroupShippingSpeed.tsx @@ -9,7 +9,8 @@ */ import {useState} from 'react'; -import {SelectableCardGroup, SelectableCardGroupItem} from '@astryxdesign/lab'; +import {SelectableCardGroup} from '@astryxdesign/lab'; +import {SelectableCard} from '@astryxdesign/core/SelectableCard'; import {HStack, StackItem, VStack} from '@astryxdesign/core/Stack'; import {Text} from '@astryxdesign/core/Text'; @@ -44,7 +45,7 @@ export default function SelectableCardGroupShippingSpeed() { value={speed} onChange={setSpeed}> {SPEEDS.map(item => ( - {item.price} - + ))} ); diff --git a/packages/lab/blocks/SelectableCardGroupShowcase.doc.mjs b/packages/lab/blocks/SelectableCardGroupShowcase.doc.mjs index c8cd466c99b4a..f71de88b71c5a 100644 --- a/packages/lab/blocks/SelectableCardGroupShowcase.doc.mjs +++ b/packages/lab/blocks/SelectableCardGroupShowcase.doc.mjs @@ -11,5 +11,5 @@ export default { isReady: true, isShowcase: true, aspectRatio: 16 / 9, - componentsUsed: ['SelectableCardGroup', 'VStack', 'Text'], + componentsUsed: ['SelectableCardGroup', 'SelectableCard', 'VStack', 'Text'], }; diff --git a/packages/lab/blocks/SelectableCardGroupShowcase.tsx b/packages/lab/blocks/SelectableCardGroupShowcase.tsx index cef4e38aceebb..644567e4ae7c6 100644 --- a/packages/lab/blocks/SelectableCardGroupShowcase.tsx +++ b/packages/lab/blocks/SelectableCardGroupShowcase.tsx @@ -9,7 +9,8 @@ */ import {useState} from 'react'; -import {SelectableCardGroup, SelectableCardGroupItem} from '@astryxdesign/lab'; +import {SelectableCardGroup} from '@astryxdesign/lab'; +import {SelectableCard} from '@astryxdesign/core/SelectableCard'; import {VStack} from '@astryxdesign/core/Stack'; import {Text} from '@astryxdesign/core/Text'; @@ -39,7 +40,7 @@ export default function SelectableCardGroupShowcase() { value={plan} onChange={setPlan}> {PLANS.map(item => ( - - + ))} ); diff --git a/packages/lab/src/SelectableCardGroup/SelectableCardGroup.doc.mjs b/packages/lab/src/SelectableCardGroup/SelectableCardGroup.doc.mjs index 98f3351110cd3..77b0b30fb0d10 100644 --- a/packages/lab/src/SelectableCardGroup/SelectableCardGroup.doc.mjs +++ b/packages/lab/src/SelectableCardGroup/SelectableCardGroup.doc.mjs @@ -18,7 +18,7 @@ export const docs = { 'selection', ], description: - 'A set of selectable cards with the semantics of its selection. One choice (the default) is a radio group: the cards are native radios sharing one name, so the set is one tab stop, the arrow keys move and select, and screen readers speak the position ("2 of 3"). Several choices are a named group of checkboxes. Each SelectableCardGroupItem is a SelectableCard whose input, name and selection come from the group.', + 'A set of selectable cards with the semantics of its selection. One choice (the default) is a radio group: the cards are native radios sharing one name, so the set is one tab stop, the arrow keys move and select, and screen readers speak the position ("2 of 3"). Several choices are a named group of checkboxes. Each card is a SelectableCard with a `value`; its input, name and selection come from the group.', props: [ { name: 'label', @@ -82,7 +82,7 @@ export const docs = { name: 'children', type: 'ReactNode', description: - 'SelectableCardGroupItem cards. Each takes a `value` and the SelectableCard props other than isSelected and onChange.', + 'SelectableCard cards, each with a `value` in place of isSelected and onChange.', required: true, }, { @@ -145,7 +145,7 @@ export const docsZh = { name: 'SelectableCardGroup', displayName: 'Selectable Card Group', description: - '一组可选卡片,语义与其选择方式一致。单选(默认)是一个单选按钮组:卡片是共享同一 name 的原生单选按钮,因此整组只占一个 Tab 停靠点,方向键移动并选中,读屏软件会读出位置(“第 2 项,共 3 项”)。多选是一个带名称的复选框组。每个 SelectableCardGroupItem 都是一个 SelectableCard,其输入类型、name 和选中状态由组提供。', + '一组可选卡片,语义与其选择方式一致。单选(默认)是一个单选按钮组:卡片是共享同一 name 的原生单选按钮,因此整组只占一个 Tab 停靠点,方向键移动并选中,读屏软件会读出位置(“第 2 项,共 3 项”)。多选是一个带名称的复选框组。每张卡片都是一个带 `value` 的 SelectableCard,其输入类型、name 和选中状态由组提供。', props: [ { name: 'label', @@ -206,7 +206,7 @@ export const docsZh = { name: 'children', type: 'ReactNode', description: - 'SelectableCardGroupItem 卡片。每张卡片接受一个 `value`,以及除 isSelected 和 onChange 之外的 SelectableCard 属性。', + 'SelectableCard 卡片,每张卡片用 `value` 代替 isSelected 和 onChange。', required: true, }, { diff --git a/packages/lab/src/SelectableCardGroup/SelectableCardGroup.test.tsx b/packages/lab/src/SelectableCardGroup/SelectableCardGroup.test.tsx index dbf3cf2bb8aac..2f78508c57873 100644 --- a/packages/lab/src/SelectableCardGroup/SelectableCardGroup.test.tsx +++ b/packages/lab/src/SelectableCardGroup/SelectableCardGroup.test.tsx @@ -2,7 +2,7 @@ /** * @file SelectableCardGroup.test.tsx - * @input Uses SelectableCardGroup, SelectableCardGroupItem, Testing Library + * @input Uses SelectableCardGroup, core SelectableCard, Testing Library * @output Tests the group's semantics and selection * @position A single choice is a radio group of native radios sharing a name; * several choices are a named group of checkboxes. @@ -11,10 +11,8 @@ import {useState} from 'react'; import {describe, it, expect, vi} from 'vitest'; import {render, screen, fireEvent} from '@testing-library/react'; -import { - SelectableCardGroup, - SelectableCardGroupItem, -} from './SelectableCardGroup'; +import {SelectableCard} from '@astryxdesign/core/SelectableCard'; +import {SelectableCardGroup} from './SelectableCardGroup'; const PLANS = ['Basic', 'Pro', 'Team']; @@ -39,9 +37,9 @@ function Single({ onChange?.(v); }}> {PLANS.map(plan => ( - + {plan} - + ))} ); @@ -59,9 +57,9 @@ function Multiple({onChange}: {onChange?: (value: string[]) => void}) { onChange?.(v); }}> {PLANS.map(plan => ( - + {plan} - + ))} ); @@ -141,12 +139,30 @@ describe('SelectableCardGroup', () => { expect(screen.getByRole('checkbox', {name: 'Basic'})).not.toBeChecked(); }); - it('an item outside a group throws', () => { - const spy = vi.spyOn(console, 'error').mockImplementation(() => {}); - expect(() => - render(), - ).toThrow(/inside a SelectableCardGroup/); - spy.mockRestore(); + it("a card's own isDisabled holds in an enabled group", () => { + const onChange = vi.fn(); + render( + + {PLANS.map(plan => ( + + {plan} + + ))} + , + ); + expect(screen.getByRole('radio', {name: 'Team'})).toHaveAttribute( + 'aria-disabled', + 'true', + ); + expect(screen.getByRole('radio', {name: 'Pro'})).not.toHaveAttribute( + 'aria-disabled', + ); + fireEvent.click(screen.getByText('Team')); + expect(onChange).not.toHaveBeenCalled(); }); it('a disabled group submits nothing with its form, and keeps its grouping', () => { @@ -175,9 +191,9 @@ describe('SelectableCardGroup', () => { value="Pro" onChange={() => {}}> {PLANS.map(plan => ( - + {plan} - +
))} , @@ -198,13 +214,13 @@ describe('SelectableCardGroup', () => { value="Team" onChange={() => {}}> {PLANS.map(plan => ( - {plan} - + ))} , @@ -232,9 +248,9 @@ describe('SelectableCardGroup', () => { aria-describedby="extra-help" value={null} onChange={() => {}}> - + Basic - + , ); @@ -251,9 +267,9 @@ describe('SelectableCardGroup', () => { value={null} onChange={() => {}} {...untyped}> - + Basic - + , ); expect(document.querySelector('.root-class')).toBeNull(); @@ -269,9 +285,9 @@ describe('SelectableCardGroup', () => { onChange={() => {}} containerClassName="field-box" containerStyle={{marginTop: 7}}> - + Basic - + , ); const group = screen.getByRole('radiogroup', {name: 'Plan'}); diff --git a/packages/lab/src/SelectableCardGroup/SelectableCardGroup.tsx b/packages/lab/src/SelectableCardGroup/SelectableCardGroup.tsx index c5fec5e5ba9b8..4d47dd4d82282 100644 --- a/packages/lab/src/SelectableCardGroup/SelectableCardGroup.tsx +++ b/packages/lab/src/SelectableCardGroup/SelectableCardGroup.tsx @@ -4,10 +4,10 @@ /** * @file SelectableCardGroup.tsx - * @input Uses core SelectableCard (its input set through Core's internal - * SelectableCardInputContext), Field (the group label and description), + * @input Uses Core's internal SelectableCardGroupContext (read by each core + * SelectableCard with a `value`), Field (the group label and description), * useFieldInputStyling, useId, StyleX and the spacing tokens - * @output Exports SelectableCardGroup, SelectableCardGroupItem and their props + * @output Exports SelectableCardGroup and its props * @position Lab: a set of selectable cards with the semantics of its selection * * SYNC: When modified, update these files to stay in sync: @@ -16,26 +16,15 @@ * - /apps/storybook/stories/SelectableCardGroup.stories.tsx (stories) */ -import { - createContext, - useContext, - useId, - useMemo, - type ReactNode, - type Ref, -} from 'react'; +import {useId, useMemo, type ReactNode, type Ref} from 'react'; import * as stylex from '@stylexjs/stylex'; import type {BaseProps} from '@astryxdesign/core'; import {Field, type FieldContainerStyleProps} from '@astryxdesign/core/Field'; import { - SelectableCard, - type SelectableCardProps, -} from '@astryxdesign/core/SelectableCard'; -import { - SelectableCardInputContext, + SelectableCardGroupContext, joinAriaIDs, useFieldInputStyling, - type SelectableCardInput, + type SelectableCardGroupMembership, } from '@astryxdesign/core/internal/selectable-card'; import {spacingVars} from '@astryxdesign/core/theme/tokens.stylex'; import {mergeProps, themeProps} from '@astryxdesign/core/utils'; @@ -105,37 +94,15 @@ export type SelectableCardGroupProps = Omit< * `horizontal` (the default) wraps cards in rows; `vertical` stacks them. */ orientation?: 'horizontal' | 'vertical'; - /** The SelectableCardGroupItem cards. */ + /** + * The cards: SelectableCards, each with a `value` in place of + * `isSelected` and `onChange`. + */ children: ReactNode; }; -export interface SelectableCardGroupItemProps extends Omit< - SelectableCardProps, - 'isSelected' | 'onChange' -> { - /** The value this card stands for in the group's `value`. */ - value: string; -} - // ============================================================================= -// Context -// ============================================================================= - -interface GroupContextValue { - inputType: 'checkbox' | 'radio'; - groupName: string; - submitName: string; - isDisabled: boolean; - isSelected: (value: string) => boolean; - change: (value: string, isSelected: boolean) => void; -} - -const SelectableCardGroupContext = createContext( - null, -); - -// ============================================================================= -// Components +// Component // ============================================================================= /** @@ -146,8 +113,8 @@ const SelectableCardGroupContext = createContext( * @example * ``` * - * Basic - * Pro + * Basic + * Pro * * ``` */ @@ -194,16 +161,16 @@ export function SelectableCardGroup(props: SelectableCardGroupProps) { ); const isMultiple = props.type === 'multiple'; - const context = useMemo(() => { + const membership = useMemo(() => { if (props.type === 'multiple') { const {value, onChange} = props; return { inputType: 'checkbox', - groupName: submitName, + inputName: submitName, submitName, isDisabled, isSelected: v => value.includes(v), - change: (v, isSelected) => + onMemberChange: (v, isSelected) => onChange( isSelected ? [...value.filter(x => x !== v), v] @@ -216,11 +183,11 @@ export function SelectableCardGroup(props: SelectableCardGroupProps) { // apart, even from another form's group with the same `htmlName`. return { inputType: 'radio', - groupName: generatedName, + inputName: generatedName, submitName, isDisabled, isSelected: v => value === v, - change: (v, isSelected) => { + onMemberChange: (v, isSelected) => { if (isSelected) { onChange(v); } @@ -263,68 +230,12 @@ export function SelectableCardGroup(props: SelectableCardGroupProps) { orientation === 'vertical' && styles.vertical, ), )}> - + {children} - +
); } SelectableCardGroup.displayName = 'SelectableCardGroup'; - -/** - * One card of a SelectableCardGroup: a SelectableCard whose input, name and - * selection come from the group. - * - * @example - * ``` - * - * - * Pro, $29 a month - * - * - * ``` - */ -export function SelectableCardGroupItem({ - value, - isDisabled, - ...props -}: SelectableCardGroupItemProps) { - const group = useContext(SelectableCardGroupContext); - const input = useMemo( - () => - group == null - ? null - : { - type: group.inputType, - name: group.groupName, - value, - }, - [group, value], - ); - if (group == null) { - throw new Error( - 'SelectableCardGroupItem must be rendered inside a SelectableCardGroup.', - ); - } - const isSelected = group.isSelected(value); - const isCardDisabled = group.isDisabled || isDisabled === true; - return ( - - group.change(value, nextSelected)} - /> - {/* The radio cards stay out of the form, so the chosen, enabled card - submits the group's value here. */} - {group.inputType === 'radio' && isSelected && !isCardDisabled ? ( - - ) : null} - - ); -} - -SelectableCardGroupItem.displayName = 'SelectableCardGroupItem'; diff --git a/packages/lab/src/SelectableCardGroup/index.ts b/packages/lab/src/SelectableCardGroup/index.ts index 3c7603cf43ced..4b138efa7fcff 100644 --- a/packages/lab/src/SelectableCardGroup/index.ts +++ b/packages/lab/src/SelectableCardGroup/index.ts @@ -4,11 +4,5 @@ * @file SelectableCardGroup component barrel export */ -export { - SelectableCardGroup, - SelectableCardGroupItem, -} from './SelectableCardGroup'; -export type { - SelectableCardGroupProps, - SelectableCardGroupItemProps, -} from './SelectableCardGroup'; +export {SelectableCardGroup} from './SelectableCardGroup'; +export type {SelectableCardGroupProps} from './SelectableCardGroup'; diff --git a/packages/lab/src/index.ts b/packages/lab/src/index.ts index 1f1eda4d82ad7..873d7951259ff 100644 --- a/packages/lab/src/index.ts +++ b/packages/lab/src/index.ts @@ -28,9 +28,7 @@ export {InfoTip, type InfoTipProps, type InfoTipSize} from './InfoTip'; // selection: one choice is a radio group, several a group of checkboxes export { SelectableCardGroup, - SelectableCardGroupItem, type SelectableCardGroupProps, - type SelectableCardGroupItemProps, } from './SelectableCardGroup'; // CircleCheckIndicator — the iOS multiple-selection circle, a checkbox-family From d4f41c22494ec1e6b3d716e87b0f682c7e3b332b Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Thu, 3 Dec 2026 06:46:45 -0800 Subject: [PATCH 2/3] fix(SelectableCard): keep the props type extendable and a stray card inert - Two call signatures, the member one first, keep `ComponentProps` the standalone interface, so a wrapper that extends or omits from it compiles again. - A card with a `value` outside a group is disabled: no click, no hover or press paint, and its checkbox reads as disabled. - Drop the development warning. The inert card shows the mistake, and the warning was most of the card's added bundle size. - Core's JSDoc, doc and changeset say "card group" and name no Lab surface. - Keep the internal `selectableCardInput.ts` module and its `SelectableCardInputContext` name for the group's membership context, instead of a new module. - Add a story for a card with a value outside a group. Co-authored-by: Ernest Tien --- .changeset/selectable-card-group-value.md | 2 +- .../stories/SelectableCard.stories.tsx | 25 +++ .../src/SelectableCard/SelectableCard.doc.mjs | 181 +++++++++++++++--- .../src/SelectableCard/SelectableCard.tsx | 45 +++-- .../SelectableCardRadio.test.tsx | 48 ++--- ...GroupContext.ts => selectableCardInput.ts} | 16 +- packages/core/src/internal/selectable-card.ts | 8 +- .../SelectableCardGroup.tsx | 12 +- 8 files changed, 245 insertions(+), 92 deletions(-) rename packages/core/src/SelectableCard/{selectableCardGroupContext.ts => selectableCardInput.ts} (73%) diff --git a/.changeset/selectable-card-group-value.md b/.changeset/selectable-card-group-value.md index 14bcf225cea11..35d251872e4da 100644 --- a/.changeset/selectable-card-group-value.md +++ b/.changeset/selectable-card-group-value.md @@ -2,6 +2,6 @@ '@astryxdesign/core': patch --- -[feat] `SelectableCard` takes `value`. A card with a `value` in place of `isSelected` and `onChange` is a member of the `SelectableCardGroup` around it, and the group gives the card its selection, its input and its disabled default. In a single-choice group the card is a native radio that selects and never deselects itself; in a multiple-choice group it is a checkbox that submits its `value` under the group's name. The new `SelectableCardMemberProps` type describes a member. `SelectableCardProps` stays the interface it was and gains only `value?: never`, so TypeScript rejects `isSelected` or `onChange` beside `value`. Outside a group, a card with a `value` warns in development and stays unselected. A standalone card does not change. +[feat] `SelectableCard` takes `value`. A card with a `value` in place of `isSelected` and `onChange` is a member of the card group around it, and the group gives the card its selection, its input and its disabled default. In a single-choice group the card is a native radio that selects and never deselects itself; in a multiple-choice group it is a checkbox that submits its `value` under the group's name. The new `SelectableCardMemberProps` type describes a member. `SelectableCardProps` stays the interface it was and gains only `value?: never`, so TypeScript rejects `isSelected` or `onChange` beside `value`. Outside a group, a card with a `value` is unselected and inert: it reads as disabled and ignores clicks. A standalone card keeps its props type, DOM and behavior. @ernestt diff --git a/apps/storybook/stories/SelectableCard.stories.tsx b/apps/storybook/stories/SelectableCard.stories.tsx index 2b8aaf9ae52e5..c1137bdab9777 100644 --- a/apps/storybook/stories/SelectableCard.stories.tsx +++ b/apps/storybook/stories/SelectableCard.stories.tsx @@ -277,6 +277,31 @@ export const Disabled: Story = { }, }; +/** + * A card with a `value` outside any group has no selection to show or change, + * so it is unselected and inert: it reads as disabled and ignores clicks. + */ +export const ValueOutsideAGroup: Story = { + render: () => ( + + {}} + width={200}> + + Standalone + + + + + Value outside a group + + + + ), +}; + function useSelectedSet(initial: string[]) { const [selected, setSelected] = useState(new Set(initial)); const toggle = (id: string, isNow: boolean) => { diff --git a/packages/core/src/SelectableCard/SelectableCard.doc.mjs b/packages/core/src/SelectableCard/SelectableCard.doc.mjs index 1a88fb195034a..2936469c2a84b 100644 --- a/packages/core/src/SelectableCard/SelectableCard.doc.mjs +++ b/packages/core/src/SelectableCard/SelectableCard.doc.mjs @@ -8,40 +8,132 @@ export const docs = { category: 'Container', keywords: ['card', 'selectable', 'toggle', 'checkbox', 'radio', 'selection'], usage: { - description: 'A card that toggles between selected and unselected states with an accent border. For navigation use ClickableCard.', + description: + 'A card that toggles between selected and unselected states with an accent border. For navigation use ClickableCard.', bestPractices: [ - {guidance: true, description: 'Use for multi-select choices: filter chips, feature add-ons, or option grids where several can be on.'}, - {guidance: true, description: 'Use for multi-select groups; track the selected IDs in a Set.'}, - {guidance: true, description: 'When focused, toggle selection with Space or Enter.'}, - {guidance: false, description: 'Use for navigation; use ClickableCard for that.'}, - {guidance: false, description: 'Build a single-select group from standalone cards: each one is a checkbox, so assistive technology announces a multi-select group with one tab stop per card. Give each card a `value` inside a SelectableCardGroup instead.'}, + { + guidance: true, + description: + 'Use for multi-select choices: filter chips, feature add-ons, or option grids where several can be on.', + }, + { + guidance: true, + description: + 'Use for multi-select groups; track the selected IDs in a Set.', + }, + { + guidance: true, + description: 'When focused, toggle selection with Space or Enter.', + }, + { + guidance: false, + description: 'Use for navigation; use ClickableCard for that.', + }, + { + guidance: false, + description: + 'Build a single-select group from standalone cards: each one is a checkbox, so assistive technology announces a multi-select group with one tab stop per card. Give each card a `value` inside a single-choice card group instead.', + }, ], anatomy: [ - {name: 'Container', required: true, description: 'Interactive div with accent border on selection.'}, - {name: 'Content', required: true, description: 'Children rendered inside the card.'}, + { + name: 'Container', + required: true, + description: 'Interactive div with accent border on selection.', + }, + { + name: 'Content', + required: true, + description: 'Children rendered inside the card.', + }, ], }, props: [ - {name: 'label', type: 'string', description: "Accessible name of the card's checkbox, or of its radio in a single-choice SelectableCardGroup. Name the option the card stands for: a screen reader announces it with the checked state.", required: true}, - {name: 'isSelected', type: 'boolean', description: 'Controlled selection state. Required for a standalone card; a card with a `value` takes it from its group instead.'}, - {name: 'onChange', type: '(isSelected: boolean) => void', description: 'Called when toggled. Required for a standalone card; a card with a `value` asks its group instead.'}, - {name: 'value', type: 'string', description: "The value this card stands for in a SelectableCardGroup's `value`. It makes the card a member of the group around it, in place of `isSelected` and `onChange`: the group gives the card its selection, a radio or checkbox input, and its disabled default."}, - {name: 'isDisabled', type: 'boolean', description: 'Disables the card. In a SelectableCardGroup, a disabled group disables every card, and an enabled group does not enable a card that disables itself.', default: 'false'}, + { + name: 'label', + type: 'string', + description: + "Accessible name of the card's checkbox, or of its radio in a single-choice card group. Name the option the card stands for: a screen reader announces it with the checked state.", + required: true, + }, + { + name: 'isSelected', + type: 'boolean', + description: + 'Controlled selection state. Required for a standalone card; a card with a `value` takes it from its group instead.', + }, + { + name: 'onChange', + type: '(isSelected: boolean) => void', + description: + 'Called when toggled. Required for a standalone card; a card with a `value` asks its group instead.', + }, + { + name: 'value', + type: 'string', + description: + "The value this card stands for in its card group's `value`. It makes the card a member of the group around it, in place of `isSelected` and `onChange`: the group gives the card its selection, a radio or checkbox input, and its disabled default. Outside a group, the card is unselected and inert.", + }, + { + name: 'isDisabled', + type: 'boolean', + description: + 'Disables the card. In a card group, a disabled group disables every card, and an enabled group does not enable a card that disables itself.', + default: 'false', + }, {name: 'children', type: 'ReactNode', description: 'Card content.'}, - {name: 'padding', type: '0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10', description: 'Inner padding.', default: '4'}, - {name: 'variant', type: "'default' | 'transparent' | 'muted' | 'blue' | 'cyan' | 'gray' | 'green' | 'orange' | 'pink' | 'purple' | 'red' | 'teal' | 'yellow'", description: 'Background color variant.', default: "'default'"}, - {name: 'elevation', type: "'none' | 'low' | 'med' | 'high'", description: 'Resting shadow depth. The selection ring composes on top, so a selected card keeps its shadow.', default: "'none'"}, + { + name: 'padding', + type: '0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10', + description: 'Inner padding.', + default: '4', + }, + { + name: 'variant', + type: "'default' | 'transparent' | 'muted' | 'blue' | 'cyan' | 'gray' | 'green' | 'orange' | 'pink' | 'purple' | 'red' | 'teal' | 'yellow'", + description: 'Background color variant.', + default: "'default'", + }, + { + name: 'elevation', + type: "'none' | 'low' | 'med' | 'high'", + description: + 'Resting shadow depth. The selection ring composes on top, so a selected card keeps its shadow.', + default: "'none'", + }, {name: 'width', type: 'SizeValue', description: 'Card width.'}, {name: 'height', type: 'SizeValue', description: 'Card height.'}, {name: 'maxWidth', type: 'SizeValue', description: 'Maximum card width.'}, - {name: 'xstyle', type: 'StyleXStyles', description: 'StyleX styles for layout customization (margins, positioning, sizing). Must be a stylex.create() value, not an inline style object like style={{}}.'}, + { + name: 'xstyle', + type: 'StyleXStyles', + description: + 'StyleX styles for layout customization (margins, positioning, sizing). Must be a stylex.create() value, not an inline style object like style={{}}.', + }, ], theming: { container: true, - targets: [{className: 'astryx-selectable-card', visualProps: ['selected', 'variant'], states: ['disabled']}], + targets: [ + { + className: 'astryx-selectable-card', + visualProps: ['selected', 'variant'], + states: ['disabled'], + }, + ], vars: [ - {name: '--selectable-card-ring-color', description: 'Colour of the selection ring drawn for a variant a theme added. The built-in variants each ring in their own border token and ignore this; a theme that adds a variant sets it in the same rule as that variant\'s `backgroundColor`, because no token the component could pick is guaranteed to contrast with a fill it cannot know.', default: 'var(--color-accent)'}, - {name: '--_press-overlay', description: 'Colour of the ::after interaction overlay for the hover and mouse states: transparent at rest, the hover overlay token on hover (hover-capable pointers), the pressed overlay token while a mouse holds `:active`. A press the touch press controller paints (`data-astryx-press`) is the overlay\'s image instead, at the press\'s strength, and the colour yields to it. Set on the card element by its own interaction arms.', default: 'transparent', private: true}, + { + name: '--selectable-card-ring-color', + description: + "Colour of the selection ring drawn for a variant a theme added. The built-in variants each ring in their own border token and ignore this; a theme that adds a variant sets it in the same rule as that variant's `backgroundColor`, because no token the component could pick is guaranteed to contrast with a fill it cannot know.", + default: 'var(--color-accent)', + }, + { + name: '--_press-overlay', + description: + "Colour of the ::after interaction overlay for the hover and mouse states: transparent at rest, the hover overlay token on hover (hover-capable pointers), the pressed overlay token while a mouse holds `:active`. A press the touch press controller paints (`data-astryx-press`) is the overlay's image instead, at the press's strength, and the colour yields to it. Set on the card element by its own interaction arms.", + default: 'transparent', + private: true, + }, ], }, playground: { @@ -54,7 +146,11 @@ export const docs = { props: {gap: 1}, children: [ {__element: 'XDSHeading', props: {level: 3}, children: 'Pro plan'}, - {__element: 'XDSText', props: {type: 'body'}, children: '$29/month, unlimited projects and priority support.'}, + { + __element: 'XDSText', + props: {type: 'body'}, + children: '$29/month, unlimited projects and priority support.', + }, ], }, }, @@ -63,26 +159,49 @@ export const docs = { /** @type {import('@astryxdesign/cli/authoring').ComponentTranslationDoc} */ export const docsDense = { - description: 'Card toggling between selected/unselected states w/ accent border. For navigation use ClickableCard instead.', + description: + 'Card toggling between selected/unselected states w/ accent border. For navigation use ClickableCard instead.', usage: { - description: 'Card toggling between selected/unselected states w/ accent border. For navigation use ClickableCard instead.', + description: + 'Card toggling between selected/unselected states w/ accent border. For navigation use ClickableCard instead.', bestPractices: [ - {guidance: true, description: 'Use for multi-select choices: filter chips, add-ons, option grids.'}, - {guidance: true, description: 'Use for multi-select groups; track selected IDs in a Set.'}, - {guidance: true, description: 'When focused, toggle selection with Space or Enter.'}, - {guidance: false, description: 'Use for navigation; use ClickableCard instead.'}, - {guidance: false, description: 'Build single-select from standalone cards: each is a checkbox, so screen readers announce multi-select. Use a SelectableCardGroup of cards w/ `value` instead.'}, + { + guidance: true, + description: + 'Use for multi-select choices: filter chips, add-ons, option grids.', + }, + { + guidance: true, + description: + 'Use for multi-select groups; track selected IDs in a Set.', + }, + { + guidance: true, + description: 'When focused, toggle selection with Space or Enter.', + }, + { + guidance: false, + description: 'Use for navigation; use ClickableCard instead.', + }, + { + guidance: false, + description: + 'Build single-select from standalone cards: each is a checkbox, so screen readers announce multi-select. Use a single-choice card group of cards w/ `value` instead.', + }, ], }, propDescriptions: { label: "checkbox or radio's accessible name; name the option", - isSelected: 'controlled selection state; required standalone, from the group w/ value', + isSelected: + 'controlled selection state; required standalone, from the group w/ value', onChange: 'called when toggled; required standalone', - value: 'joins the SelectableCardGroup around it: the group owns selection, input type, disabled default', + value: + 'joins the card group around it: the group owns selection, input type, disabled default', isDisabled: 'disables card; a disabled group disables every card', padding: 'inner padding', variant: 'background color variant', - elevation: 'resting shadow depth: none|low|med|high; selection ring composes on top', + elevation: + 'resting shadow depth: none|low|med|high; selection ring composes on top', width: 'card width', height: 'card height', maxWidth: 'max card width', diff --git a/packages/core/src/SelectableCard/SelectableCard.tsx b/packages/core/src/SelectableCard/SelectableCard.tsx index 144a297e6aafc..102fe5dd29fd1 100644 --- a/packages/core/src/SelectableCard/SelectableCard.tsx +++ b/packages/core/src/SelectableCard/SelectableCard.tsx @@ -59,8 +59,7 @@ import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex'; import {usePressFeedback} from '../hooks/usePressFeedback'; import {useMergedRefs} from '../hooks/useMergedRefs'; -import {useDevWarning} from '../hooks/useDevWarning'; -import {SelectableCardGroupContext} from './selectableCardGroupContext'; +import {SelectableCardInputContext} from './selectableCardInput'; // ============================================================================= // Styles — selection + interaction; Card handles the rest // ============================================================================= @@ -357,8 +356,8 @@ export interface SelectableCardProps extends Omit { * Set to true to disable the card. * Disabled cards remain focusable (tabIndex 0) with aria-disabled * so screen reader users can discover them. - * In a SelectableCardGroup, a disabled group disables every card, and an - * enabled group does not enable a card that disables itself. + * In a card group, a disabled group disables every card, and an enabled + * group does not enable a card that disables itself. */ isDisabled?: boolean; @@ -394,15 +393,15 @@ export interface SelectableCardProps extends Omit { maxWidth?: SizeValue; /** - * Only a SelectableCardGroup member takes a `value`, in place of + * Only a member of a card group takes a `value`, in place of * `isSelected` and `onChange` (SelectableCardMemberProps). */ value?: never; } /** - * A SelectableCard in a SelectableCardGroup: a `value` in place of - * `isSelected` and `onChange`. The group gives the card its selection, its + * A SelectableCard in a card group: a `value` in place of `isSelected` and + * `onChange`. The group gives the card its selection, its * input and its disabled default. */ export interface SelectableCardMemberProps extends Omit< @@ -459,6 +458,17 @@ function callBeforeLayerHandlers( } } +// Two signatures, the member one first, keep `ComponentProps` the standalone interface that wrappers extend: it reads +// the last signature. Each call still takes standalone or member props, +// never both and never neither. +/** + * A SelectableCard that is a member of the card group around it: a `value` + * in place of `isSelected` and `onChange`. + */ +export function SelectableCard( + props: SelectableCardMemberProps, +): React.JSX.Element; /** * A card that toggles between selected and unselected states. * @@ -471,13 +481,15 @@ function callBeforeLayerHandlers( * is a plain
— no role or tabIndex on the container. * * With a `value` instead of `isSelected` and `onChange`, the card is a - * member of the SelectableCardGroup around it. The group owns its selection, - * and in a single-choice group the card is a radio. + * member of the card group around it. The group owns its selection, and in a + * single-choice group the card is a radio. Outside a group, such a card is + * unselected and inert. * * @compositionHint Use for multi-select card groups, managing selection * state externally in a Set. Standalone cards are checkboxes, so do not * build a single-select set from them: give each card a `value` inside a - * SelectableCardGroup. For navigation/action cards, use ClickableCard instead. + * single-choice card group. For navigation/action cards, use ClickableCard + * instead. * * @example * ``` @@ -489,6 +501,7 @@ function callBeforeLayerHandlers( * * ``` */ +export function SelectableCard(props: SelectableCardProps): React.JSX.Element; export function SelectableCard({ label, isSelected: isSelectedProp, @@ -516,21 +529,17 @@ export function SelectableCard({ const interactiveRef = useRef(null); // A `value` makes the card a member of the group around it. Outside a group, - // such a card has no selection to show or change. - const groupContext = use(SelectableCardGroupContext); + // such a card has no selection to show or change, so it is disabled. + const groupContext = use(SelectableCardInputContext); const group = value == null ? null : groupContext; - useDevWarning( - 'SelectableCard', - 'A card with a `value` takes its selection from a SelectableCardGroup, and no SelectableCardGroup in the same layer is around it. Render it inside one, or pass `isSelected` and `onChange` instead of `value`.', - value != null && groupContext == null, - ); + const isStray = value != null && groupContext == null; const isSelected = value == null ? isSelectedProp === true : (group?.isSelected(value) ?? false); // Either the group or the card disabling it is enough: a group cannot // enable a card that disables itself. - const isDisabled = (group?.isDisabled ?? false) || isDisabledProp; + const isDisabled = isStray || (group?.isDisabled ?? false) || isDisabledProp; // A radio only selects: a native radio stays checked when it is clicked // again. const isRadio = group?.inputType === 'radio'; diff --git a/packages/core/src/SelectableCard/SelectableCardRadio.test.tsx b/packages/core/src/SelectableCard/SelectableCardRadio.test.tsx index 2ae9930153295..8a7323349f67d 100644 --- a/packages/core/src/SelectableCard/SelectableCardRadio.test.tsx +++ b/packages/core/src/SelectableCard/SelectableCardRadio.test.tsx @@ -5,12 +5,12 @@ * @input Uses SelectableCard, its internal group context, and Testing Library * @output Tests for a SelectableCard that a `value` makes a group member * @position A member takes its selection, input, name and disabled default - * from the group (the internal SelectableCardGroupContext). In a + * from the group (the internal SelectableCardInputContext). In a * single-choice group it is a native radio that selects and never * deselects itself. */ -import {useMemo, useState, type ReactNode} from 'react'; +import {useMemo, useState, type ComponentProps, type ReactNode} from 'react'; import {describe, it, expect, vi} from 'vitest'; import {render, screen, fireEvent} from '@testing-library/react'; import { @@ -19,9 +19,9 @@ import { type SelectableCardProps, } from './SelectableCard'; import { - SelectableCardGroupContext, - type SelectableCardGroupMembership, -} from './selectableCardGroupContext'; + SelectableCardInputContext, + type SelectableCardInput, +} from './selectableCardInput'; import {Dialog} from '../Dialog/Dialog'; /** A group the way a single-choice SelectableCardGroup provides it. */ @@ -36,7 +36,7 @@ function RadioGroup({ isDisabled?: boolean; children: ReactNode; }) { - const membership = useMemo( + const membership = useMemo( () => ({ inputType: 'radio', inputName: 'plan-radios', @@ -53,9 +53,9 @@ function RadioGroup({ ); return (
- + {children} - +
); } @@ -72,7 +72,7 @@ function CheckboxGroup({ isDisabled?: boolean; children: ReactNode; }) { - const membership = useMemo( + const membership = useMemo( () => ({ inputType: 'checkbox', inputName: 'addons', @@ -89,9 +89,9 @@ function CheckboxGroup({ [isDisabled, onChange, value], ); return ( - + {children} - + ); } @@ -334,27 +334,24 @@ describe('SelectableCard membership', () => { expect(onChange).not.toHaveBeenCalled(); }); - it('a card with a value outside a group warns in development and stays unselected and inert', () => { - const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + it('a card with a value outside a group stays unselected and inert', () => { + const onClick = vi.fn(); render( - + Pro , ); const input = screen.getByRole('checkbox', {name: 'Pro'}); expect(input).not.toBeChecked(); expect(input).not.toHaveAttribute('name'); + expect(input).toHaveAttribute('aria-disabled', 'true'); fireEvent.click(screen.getByText('Pro')); fireEvent.keyDown(input, {key: 'Enter'}); expect(input).not.toBeChecked(); - expect(warn).toHaveBeenCalledWith( - expect.stringContaining('SelectableCardGroup'), - ); - warn.mockRestore(); + expect(onClick).not.toHaveBeenCalled(); }); it('membership stops at a layer: a card with a value in a layer inside a group is not a member', () => { - const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); const onChange = vi.fn(); render( @@ -369,11 +366,13 @@ describe('SelectableCard membership', () => { expect(input).not.toBeChecked(); fireEvent.click(screen.getByText('Inner')); expect(onChange).not.toHaveBeenCalled(); - warn.mockRestore(); }); - it('keeps SelectableCardProps an interface that callers extend and pass back', () => { - interface TrackedCardProps extends SelectableCardProps { + it("keeps the card's props an interface that callers extend and pass back", () => { + type CardProps = ComponentProps; + // A wrapper derives the card's props from the component, so they must stay + // the standalone interface rather than a union with the member props. + interface TrackedCardProps extends CardProps { trackingID: string; } const tracked: TrackedCardProps = { @@ -383,11 +382,12 @@ describe('SelectableCard membership', () => { trackingID: 'a', }; const {trackingID, ...card} = tracked; - const withoutVariant: Omit = card; + const withoutVariant: Omit = card; + const standalone: SelectableCardProps = withoutVariant; const member: SelectableCardMemberProps = {label: 'B', value: 'b'}; render( <> - {trackingID} + {trackingID} {}}> B diff --git a/packages/core/src/SelectableCard/selectableCardGroupContext.ts b/packages/core/src/SelectableCard/selectableCardInput.ts similarity index 73% rename from packages/core/src/SelectableCard/selectableCardGroupContext.ts rename to packages/core/src/SelectableCard/selectableCardInput.ts index c0d9bc5f00585..3bcbd100094bb 100644 --- a/packages/core/src/SelectableCard/selectableCardGroupContext.ts +++ b/packages/core/src/SelectableCard/selectableCardInput.ts @@ -3,10 +3,10 @@ 'use client'; /** - * @file selectableCardGroupContext.ts + * @file selectableCardInput.ts * @input The selection, input and disabled state of a group of cards - * @output SelectableCardGroupContext: what a group gives each SelectableCard - * that its `value` makes a member + * @output SelectableCardInputContext: the input, selection and disabled + * default a group gives each SelectableCard that its `value` makes a member * @position Internal: Lab's SelectableCardGroup provides it through * `@astryxdesign/core/internal/selectable-card`. It is not public API. */ @@ -14,7 +14,7 @@ import {createLayerScopedContext} from '../Layer/layerScopedContext'; /** What a group gives each card that it names by `value`. */ -export interface SelectableCardGroupMembership { +export interface SelectableCardInput { /** `radio` makes each member one choice of a single-choice set. */ readonly inputType: 'checkbox' | 'radio'; /** The members' input `name`. Radios that share it form one native group. */ @@ -31,10 +31,10 @@ export interface SelectableCardGroupMembership { * Without a provider, a card with a `value` has no group. Membership stops at * a layer boundary, so a card in a layer opened from a member is not a member. */ -export const SelectableCardGroupContext = - createLayerScopedContext( - 'SelectableCardGroupContext', +export const SelectableCardInputContext = + createLayerScopedContext( + 'SelectableCardInputContext', 1, null, ); -SelectableCardGroupContext.displayName = 'SelectableCardGroupContext'; +SelectableCardInputContext.displayName = 'SelectableCardInputContext'; diff --git a/packages/core/src/internal/selectable-card.ts b/packages/core/src/internal/selectable-card.ts index 16a24e0902749..90659b7fa3057 100644 --- a/packages/core/src/internal/selectable-card.ts +++ b/packages/core/src/internal/selectable-card.ts @@ -1,10 +1,10 @@ // Copyright (c) Meta Platforms, Inc. and affiliates. /** * @file selectable-card.ts - * @input SelectableCard's internal group context, the Field input styling + * @input SelectableCard's internal input context, the Field input styling * rule and the aria id joiner * @output `@astryxdesign/core/internal/selectable-card`: - * SelectableCardGroupContext, useFieldInputStyling and joinAriaIDs, + * SelectableCardInputContext, useFieldInputStyling and joinAriaIDs, * re-exported by name * for Lab's SelectableCardGroup * @position An internal entry reserved for Astryx's own packages: @@ -15,7 +15,7 @@ * * SYNC: When modified, update scripts/sync-exports.js. */ -export {SelectableCardGroupContext} from '../SelectableCard/selectableCardGroupContext'; -export type {SelectableCardGroupMembership} from '../SelectableCard/selectableCardGroupContext'; +export {SelectableCardInputContext} from '../SelectableCard/selectableCardInput'; +export type {SelectableCardInput} from '../SelectableCard/selectableCardInput'; export {useFieldInputStyling} from '../Field/fieldParts'; export {joinAriaIDs} from '../utils/inputAria'; diff --git a/packages/lab/src/SelectableCardGroup/SelectableCardGroup.tsx b/packages/lab/src/SelectableCardGroup/SelectableCardGroup.tsx index 4d47dd4d82282..8743ccbc9370c 100644 --- a/packages/lab/src/SelectableCardGroup/SelectableCardGroup.tsx +++ b/packages/lab/src/SelectableCardGroup/SelectableCardGroup.tsx @@ -4,7 +4,7 @@ /** * @file SelectableCardGroup.tsx - * @input Uses Core's internal SelectableCardGroupContext (read by each core + * @input Uses Core's internal SelectableCardInputContext (read by each core * SelectableCard with a `value`), Field (the group label and description), * useFieldInputStyling, useId, StyleX and the spacing tokens * @output Exports SelectableCardGroup and its props @@ -21,10 +21,10 @@ import * as stylex from '@stylexjs/stylex'; import type {BaseProps} from '@astryxdesign/core'; import {Field, type FieldContainerStyleProps} from '@astryxdesign/core/Field'; import { - SelectableCardGroupContext, + SelectableCardInputContext, joinAriaIDs, useFieldInputStyling, - type SelectableCardGroupMembership, + type SelectableCardInput, } from '@astryxdesign/core/internal/selectable-card'; import {spacingVars} from '@astryxdesign/core/theme/tokens.stylex'; import {mergeProps, themeProps} from '@astryxdesign/core/utils'; @@ -161,7 +161,7 @@ export function SelectableCardGroup(props: SelectableCardGroupProps) { ); const isMultiple = props.type === 'multiple'; - const membership = useMemo(() => { + const membership = useMemo(() => { if (props.type === 'multiple') { const {value, onChange} = props; return { @@ -230,9 +230,9 @@ export function SelectableCardGroup(props: SelectableCardGroupProps) { orientation === 'vertical' && styles.vertical, ), )}> - + {children} - +
); From 9a66a0492bfdca8216f21a87fcc759efc15819f9 Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Thu, 3 Dec 2026 08:42:55 -0800 Subject: [PATCH 3/3] fix(SelectableCard): record a stray card as disabled; keep the doc layout - The Group value row says a card with a `value` outside a group renders unselected and disabled (FR5), as it now does; it no longer promises a development warning. - Restore SelectableCard.doc.mjs's layout for entries this change does not touch; only the six "card group" wordings differ from before. - Bump SelectableCardInputContext's protocol version to 2: its value changed shape, so an older copy on the page never reads it. - Say exactly where membership stops at a layer boundary. Co-authored-by: Ernest Tien --- .../SelectableCard/SelectableCard.spec.md | 12 +- .../src/SelectableCard/SelectableCard.doc.mjs | 181 +++--------------- .../src/SelectableCard/selectableCardInput.ts | 4 +- 3 files changed, 39 insertions(+), 158 deletions(-) diff --git a/docs/specs/components/SelectableCard/SelectableCard.spec.md b/docs/specs/components/SelectableCard/SelectableCard.spec.md index 50061f3522ea9..273012d84d3a8 100644 --- a/docs/specs/components/SelectableCard/SelectableCard.spec.md +++ b/docs/specs/components/SelectableCard/SelectableCard.spec.md @@ -145,12 +145,12 @@ 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 | -| ----------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------- | ------------------------------------------------ | -------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Selection | selected; unselected | Controlled checked state, reflected as `data-selected`; a member's comes from its group. | Always | Required standalone; from the group for a member | `component:SelectableCard` | Stable | — | -| Disabled | enabled; disabled | Blocks toggling while keeping the input focusable, reflected as `data-disabled`; a group's `isDisabled` disables every member. | Always | enabled | `component:SelectableCard` | Stable | — | -| Variant | Card variants; theme additions | Card paint and the matching selection ring color. | Always | `default` | `component:Card` | Stable | A theme-added variant rings in `--selectable-card-ring-color` (default `--color-accent`) and keeps its border color. | -| Group value | a string | Identifies the card as a `SelectableCardGroup` member; the group's `value` names the selected members. | Inside `SelectableCardGroup` | none | `component:SelectableCard` | Stable | TypeScript rejects `isSelected` or `onChange` beside it (`spec:AST-002` FR15). Outside a group, a card with a `value` warns in development and renders unselected and inert. | +| Concept | Closed values or states | Meaning | Availability by variant/orientation/state | Default | Owner | Stability | Invalid-value behavior | +| ----------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------- | ------------------------------------------------ | -------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| Selection | selected; unselected | Controlled checked state, reflected as `data-selected`; a member's comes from its group. | Always | Required standalone; from the group for a member | `component:SelectableCard` | Stable | — | +| Disabled | enabled; disabled | Blocks toggling while keeping the input focusable, reflected as `data-disabled`; a group's `isDisabled` disables every member. | Always | enabled | `component:SelectableCard` | Stable | — | +| Variant | Card variants; theme additions | Card paint and the matching selection ring color. | Always | `default` | `component:Card` | Stable | A theme-added variant rings in `--selectable-card-ring-color` (default `--color-accent`) and keeps its border color. | +| Group value | a string | Identifies the card as a `SelectableCardGroup` member; the group's `value` names the selected members. | Inside `SelectableCardGroup` | none | `component:SelectableCard` | Stable | TypeScript rejects `isSelected` or `onChange` beside it (`spec:AST-002` FR15). Outside a group, a card with a `value` renders unselected and disabled (FR5). | ## Behavioral and layout contract diff --git a/packages/core/src/SelectableCard/SelectableCard.doc.mjs b/packages/core/src/SelectableCard/SelectableCard.doc.mjs index 2936469c2a84b..b593b25f7069e 100644 --- a/packages/core/src/SelectableCard/SelectableCard.doc.mjs +++ b/packages/core/src/SelectableCard/SelectableCard.doc.mjs @@ -8,132 +8,40 @@ export const docs = { category: 'Container', keywords: ['card', 'selectable', 'toggle', 'checkbox', 'radio', 'selection'], usage: { - description: - 'A card that toggles between selected and unselected states with an accent border. For navigation use ClickableCard.', + description: 'A card that toggles between selected and unselected states with an accent border. For navigation use ClickableCard.', bestPractices: [ - { - guidance: true, - description: - 'Use for multi-select choices: filter chips, feature add-ons, or option grids where several can be on.', - }, - { - guidance: true, - description: - 'Use for multi-select groups; track the selected IDs in a Set.', - }, - { - guidance: true, - description: 'When focused, toggle selection with Space or Enter.', - }, - { - guidance: false, - description: 'Use for navigation; use ClickableCard for that.', - }, - { - guidance: false, - description: - 'Build a single-select group from standalone cards: each one is a checkbox, so assistive technology announces a multi-select group with one tab stop per card. Give each card a `value` inside a single-choice card group instead.', - }, + {guidance: true, description: 'Use for multi-select choices: filter chips, feature add-ons, or option grids where several can be on.'}, + {guidance: true, description: 'Use for multi-select groups; track the selected IDs in a Set.'}, + {guidance: true, description: 'When focused, toggle selection with Space or Enter.'}, + {guidance: false, description: 'Use for navigation; use ClickableCard for that.'}, + {guidance: false, description: 'Build a single-select group from standalone cards: each one is a checkbox, so assistive technology announces a multi-select group with one tab stop per card. Give each card a `value` inside a single-choice card group instead.'}, ], anatomy: [ - { - name: 'Container', - required: true, - description: 'Interactive div with accent border on selection.', - }, - { - name: 'Content', - required: true, - description: 'Children rendered inside the card.', - }, + {name: 'Container', required: true, description: 'Interactive div with accent border on selection.'}, + {name: 'Content', required: true, description: 'Children rendered inside the card.'}, ], }, props: [ - { - name: 'label', - type: 'string', - description: - "Accessible name of the card's checkbox, or of its radio in a single-choice card group. Name the option the card stands for: a screen reader announces it with the checked state.", - required: true, - }, - { - name: 'isSelected', - type: 'boolean', - description: - 'Controlled selection state. Required for a standalone card; a card with a `value` takes it from its group instead.', - }, - { - name: 'onChange', - type: '(isSelected: boolean) => void', - description: - 'Called when toggled. Required for a standalone card; a card with a `value` asks its group instead.', - }, - { - name: 'value', - type: 'string', - description: - "The value this card stands for in its card group's `value`. It makes the card a member of the group around it, in place of `isSelected` and `onChange`: the group gives the card its selection, a radio or checkbox input, and its disabled default. Outside a group, the card is unselected and inert.", - }, - { - name: 'isDisabled', - type: 'boolean', - description: - 'Disables the card. In a card group, a disabled group disables every card, and an enabled group does not enable a card that disables itself.', - default: 'false', - }, + {name: 'label', type: 'string', description: "Accessible name of the card's checkbox, or of its radio in a single-choice card group. Name the option the card stands for: a screen reader announces it with the checked state.", required: true}, + {name: 'isSelected', type: 'boolean', description: 'Controlled selection state. Required for a standalone card; a card with a `value` takes it from its group instead.'}, + {name: 'onChange', type: '(isSelected: boolean) => void', description: 'Called when toggled. Required for a standalone card; a card with a `value` asks its group instead.'}, + {name: 'value', type: 'string', description: "The value this card stands for in its card group's `value`. It makes the card a member of the group around it, in place of `isSelected` and `onChange`: the group gives the card its selection, a radio or checkbox input, and its disabled default. Outside a group, the card is unselected and disabled."}, + {name: 'isDisabled', type: 'boolean', description: 'Disables the card. In a card group, a disabled group disables every card, and an enabled group does not enable a card that disables itself.', default: 'false'}, {name: 'children', type: 'ReactNode', description: 'Card content.'}, - { - name: 'padding', - type: '0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10', - description: 'Inner padding.', - default: '4', - }, - { - name: 'variant', - type: "'default' | 'transparent' | 'muted' | 'blue' | 'cyan' | 'gray' | 'green' | 'orange' | 'pink' | 'purple' | 'red' | 'teal' | 'yellow'", - description: 'Background color variant.', - default: "'default'", - }, - { - name: 'elevation', - type: "'none' | 'low' | 'med' | 'high'", - description: - 'Resting shadow depth. The selection ring composes on top, so a selected card keeps its shadow.', - default: "'none'", - }, + {name: 'padding', type: '0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10', description: 'Inner padding.', default: '4'}, + {name: 'variant', type: "'default' | 'transparent' | 'muted' | 'blue' | 'cyan' | 'gray' | 'green' | 'orange' | 'pink' | 'purple' | 'red' | 'teal' | 'yellow'", description: 'Background color variant.', default: "'default'"}, + {name: 'elevation', type: "'none' | 'low' | 'med' | 'high'", description: 'Resting shadow depth. The selection ring composes on top, so a selected card keeps its shadow.', default: "'none'"}, {name: 'width', type: 'SizeValue', description: 'Card width.'}, {name: 'height', type: 'SizeValue', description: 'Card height.'}, {name: 'maxWidth', type: 'SizeValue', description: 'Maximum card width.'}, - { - name: 'xstyle', - type: 'StyleXStyles', - description: - 'StyleX styles for layout customization (margins, positioning, sizing). Must be a stylex.create() value, not an inline style object like style={{}}.', - }, + {name: 'xstyle', type: 'StyleXStyles', description: 'StyleX styles for layout customization (margins, positioning, sizing). Must be a stylex.create() value, not an inline style object like style={{}}.'}, ], theming: { container: true, - targets: [ - { - className: 'astryx-selectable-card', - visualProps: ['selected', 'variant'], - states: ['disabled'], - }, - ], + targets: [{className: 'astryx-selectable-card', visualProps: ['selected', 'variant'], states: ['disabled']}], vars: [ - { - name: '--selectable-card-ring-color', - description: - "Colour of the selection ring drawn for a variant a theme added. The built-in variants each ring in their own border token and ignore this; a theme that adds a variant sets it in the same rule as that variant's `backgroundColor`, because no token the component could pick is guaranteed to contrast with a fill it cannot know.", - default: 'var(--color-accent)', - }, - { - name: '--_press-overlay', - description: - "Colour of the ::after interaction overlay for the hover and mouse states: transparent at rest, the hover overlay token on hover (hover-capable pointers), the pressed overlay token while a mouse holds `:active`. A press the touch press controller paints (`data-astryx-press`) is the overlay's image instead, at the press's strength, and the colour yields to it. Set on the card element by its own interaction arms.", - default: 'transparent', - private: true, - }, + {name: '--selectable-card-ring-color', description: 'Colour of the selection ring drawn for a variant a theme added. The built-in variants each ring in their own border token and ignore this; a theme that adds a variant sets it in the same rule as that variant\'s `backgroundColor`, because no token the component could pick is guaranteed to contrast with a fill it cannot know.', default: 'var(--color-accent)'}, + {name: '--_press-overlay', description: 'Colour of the ::after interaction overlay for the hover and mouse states: transparent at rest, the hover overlay token on hover (hover-capable pointers), the pressed overlay token while a mouse holds `:active`. A press the touch press controller paints (`data-astryx-press`) is the overlay\'s image instead, at the press\'s strength, and the colour yields to it. Set on the card element by its own interaction arms.', default: 'transparent', private: true}, ], }, playground: { @@ -146,11 +54,7 @@ export const docs = { props: {gap: 1}, children: [ {__element: 'XDSHeading', props: {level: 3}, children: 'Pro plan'}, - { - __element: 'XDSText', - props: {type: 'body'}, - children: '$29/month, unlimited projects and priority support.', - }, + {__element: 'XDSText', props: {type: 'body'}, children: '$29/month, unlimited projects and priority support.'}, ], }, }, @@ -159,49 +63,26 @@ export const docs = { /** @type {import('@astryxdesign/cli/authoring').ComponentTranslationDoc} */ export const docsDense = { - description: - 'Card toggling between selected/unselected states w/ accent border. For navigation use ClickableCard instead.', + description: 'Card toggling between selected/unselected states w/ accent border. For navigation use ClickableCard instead.', usage: { - description: - 'Card toggling between selected/unselected states w/ accent border. For navigation use ClickableCard instead.', + description: 'Card toggling between selected/unselected states w/ accent border. For navigation use ClickableCard instead.', bestPractices: [ - { - guidance: true, - description: - 'Use for multi-select choices: filter chips, add-ons, option grids.', - }, - { - guidance: true, - description: - 'Use for multi-select groups; track selected IDs in a Set.', - }, - { - guidance: true, - description: 'When focused, toggle selection with Space or Enter.', - }, - { - guidance: false, - description: 'Use for navigation; use ClickableCard instead.', - }, - { - guidance: false, - description: - 'Build single-select from standalone cards: each is a checkbox, so screen readers announce multi-select. Use a single-choice card group of cards w/ `value` instead.', - }, + {guidance: true, description: 'Use for multi-select choices: filter chips, add-ons, option grids.'}, + {guidance: true, description: 'Use for multi-select groups; track selected IDs in a Set.'}, + {guidance: true, description: 'When focused, toggle selection with Space or Enter.'}, + {guidance: false, description: 'Use for navigation; use ClickableCard instead.'}, + {guidance: false, description: 'Build single-select from standalone cards: each is a checkbox, so screen readers announce multi-select. Use a single-choice card group of cards w/ `value` instead.'}, ], }, propDescriptions: { label: "checkbox or radio's accessible name; name the option", - isSelected: - 'controlled selection state; required standalone, from the group w/ value', + isSelected: 'controlled selection state; required standalone, from the group w/ value', onChange: 'called when toggled; required standalone', - value: - 'joins the card group around it: the group owns selection, input type, disabled default', + value: 'joins the card group around it: the group owns selection, input type, disabled default', isDisabled: 'disables card; a disabled group disables every card', padding: 'inner padding', variant: 'background color variant', - elevation: - 'resting shadow depth: none|low|med|high; selection ring composes on top', + elevation: 'resting shadow depth: none|low|med|high; selection ring composes on top', width: 'card width', height: 'card height', maxWidth: 'max card width', diff --git a/packages/core/src/SelectableCard/selectableCardInput.ts b/packages/core/src/SelectableCard/selectableCardInput.ts index 3bcbd100094bb..2ff8875722b81 100644 --- a/packages/core/src/SelectableCard/selectableCardInput.ts +++ b/packages/core/src/SelectableCard/selectableCardInput.ts @@ -29,12 +29,12 @@ export interface SelectableCardInput { /** * Without a provider, a card with a `value` has no group. Membership stops at - * a layer boundary, so a card in a layer opened from a member is not a member. + * a layer boundary: a card in a layer opened inside the group is not a member. */ export const SelectableCardInputContext = createLayerScopedContext( 'SelectableCardInputContext', - 1, + 2, null, ); SelectableCardInputContext.displayName = 'SelectableCardInputContext';