Repository navigation
Description
Add two generic interactivity components to @astryx/core:
Clickable— make a piece of content behave and look like a single button or link target.ClickableContainer— an interactive surface (card, row) that can safely contain its own nested buttons/links.
Both bundle the interaction semantics (button vs link, keyboard activation) and the visual affordances that "being clickable" implies (hover overlay, pressed state, focus ring). The machinery already exists (useClickableContainer, useInteractiveRole) — this packages it into first-class, documented components with a settled API.
Why components (not pervasive polymorphism)
We deliberately do not want to make every component polymorphic (an as contract, or a useClickable hook whose props you spread onto any element). Applied broadly that has real costs:
hrefcan't work via prop-spread alone — the element has to actually render as an<a>, which forces an element-type contract onto every consumer.- Type-surface bloat / prop collisions / ref-forwarding on components that otherwise don't need it.
- "Clickable" is a visual layer, not just semantics — the hover overlay / pressed state / focus ring need a positioned overlay element, which can't be delivered by spreading handlers onto an arbitrary element.
- RSC boundary — the interaction logic is client-side; concentrating it in two components keeps static content (
Badge,Token) server-renderable.
So individual components stay simple, and interactivity is concentrated in Clickable / ClickableContainer.
Prior art
A widely-used interactive primitive in an earlier internal design system was built exactly this way and validates the approach. Behaviors to carry forward:
- A non-interactive surface + a visually-hidden, focusable, real
<button>/<a>element + a state overlay for hover/press/disabled feedback. - It always used the container (nested-interactive-safe) pattern. Our
Clickableleaf variant — where the child itself is the target with no extra interactive surface — is the lighter new case worth adding alongside it. - It accreted extra axes over time — a
dense/padding notion, anisReadOnlystate (keep appearance, remove interaction) distinct fromisDisabled, andisSelected. We adoptisReadOnlyfrom the start (see resolved decisions); density andisSelectedare deferred. - It was fully client-side (pre-RSC); we keep the client concern contained in these two components.
Proposed API
Follow existing sibling conventions (ClickableCard, Button, Token): label required, isDisabled (not disabled), href/onClick/target, xstyle, StyleX-only, useLinkComponent() for navigation.
Clickable
interface ClickableProps extends BaseProps {
/** Accessible name (required). Not visually rendered. */
label: string;
/** Content that becomes the interactive target. */
children: ReactNode;
/** Navigation URL → renders as a link. */
href?: string;
/** Link target (with href). @default '_self' */
target?: string;
/** Action handler → renders as a button. */
onClick?: (event: MouseEvent<HTMLElement>) => void;
/** @default false — remains focusable with aria-disabled. */
isDisabled?: boolean;
/** Optional reason surfaced when disabled (tooltip + assistive tech). */
disabledReason?: string;
/** Keep appearance but remove interaction (no disabled styling). @default false */
isReadOnly?: boolean;
ref?: Ref<HTMLElement>;
}<Clickable label="View profile" href="/profile/123">
<Badge label="Engineering" />
</Clickable>
<Clickable label="Increment" onClick={() => setCount(c => c + 1)}>
<SomeContent />
</Clickable>- Priority:
href→ link, elseonClick→ button (mirrorsuseInteractiveRole). - Adds hover overlay + pressed + focus ring. No padding of its own.
ClickableContainer
interface ClickableContainerProps extends BaseProps {
/** Accessible name (required). */
label: string;
/** Surface content; may contain nested buttons/links that work independently. */
children: ReactNode;
href?: string;
target?: string;
onClick?: (event: MouseEvent<HTMLElement>) => void;
/** @default false — focusable with aria-disabled. */
isDisabled?: boolean;
/** Optional reason surfaced when disabled (tooltip + assistive tech). */
disabledReason?: string;
/** Keep appearance but remove interaction. @default false */
isReadOnly?: boolean;
ref?: Ref<HTMLDivElement>;
}<ClickableContainer label="Open item" href="/items/42">
<Text>Item title</Text>
<Button label="Quick action" onClick={handleAction} /> {/* independent */}
</ClickableContainer>Built on useClickableContainer. ClickableCard / SelectableCard can be refactored to thin visual wrappers over it, and Token / Item / Thumbnail can drop their bespoke invisible-button implementations.
Accessibility guarantees (how ClickableContainer works)
This is the delicate part, so the contract is explicit. The pattern: a visually-hidden but focusable real interactive element rendered as a sibling of inert visible content.
<div> ← container: NO role, NO tabIndex; not interactive to AT
├─ <button|a aria-label={label}> ← HIDDEN, FOCUSABLE real element (the actual control)
│ (clip 1×1, not display:none) carries role + accessible name + focus + Enter/Space
├─ [hover / pressed overlay] ← positioned visual affordance
└─ <div>{children}</div> ← INERT visible content (may hold nested buttons/links)
- Container is not interactive to assistive tech. The visible wrapper has no
roleand notabIndex, so screen readers never announce a vague "clickable group." - A real hidden element carries semantics. A visually-hidden-but-focusable
<button>(or<a>whenhrefis set) holds the role, requiredaria-label,tabIndex, and native keyboard activation (Enter/Space for button, Enter for link). Hidden via the clip/1×1 technique — neverdisplay:none/visibility:hidden, which would remove it from the a11y tree and focus order. - Sibling, not ancestor — the crux of nested-interactive safety. The accessible element is a sibling of the content, never an ancestor. Nested buttons/links in the content are therefore not descendants of a
<button>(invalid HTML that breaks AT); both the container action and nested controls stay valid and independently operable. - Click routing respects nested controls. A surface click walks the DOM for an interactive ancestor (shared
INTERACTIVE_SELECTORS). If it landed on/inside a nested control, the container does nothing and lets that control handle its event; otherwise it firesonClick/ navigates / proxies the click to the hidden element. - Focus ring on the visible surface. Since the hidden element receives focus, the container renders the ring via
:has(:focus-visible)— keyboard users see the ring on the surface they perceive. - Interaction guards. Text selection inside the surface doesn't trigger navigation; middle-click / Cmd/Ctrl-click on a link opens a new tab.
- Disabled stays discoverable via
aria-disabled(element remains focusable/announced) rather than removal.
Clickable uses the same hidden-real-element approach without the nested-interactive click-routing, since its content isn't meant to contain independent interactive children.
Acceptance criteria
-
ClickableandClickableContainerimplemented inpackages/core/src, StyleX-only, usinguseClickableContainer/useInteractiveRole/useLinkComponent. - Renders as
<button>foronClickand link (useLinkComponent) forhref; disabled links fall back to button. - Full a11y contract above, verified by tests: no role/tabIndex on the container; hidden focusable real element; keyboard Enter/Space;
:has(:focus-visible)ring; nested-interactive click isolation. - Overlay
border-radiusinherits from the child by default; explicit styling (xstyle/ direct radius) overrides. -
isDisabledusesaria-disabled(stays focusable/announced) with an optionaldisabledReasonsurfaced via tooltip + assistive tech;isReadOnlyremoves interaction while preserving appearance. - Full component surface per repo conventions:
.tsx, colocated.test.tsx,{Name}.doc.mjs,index.tsexport, Storybook story, showcase block,displayName, synced exports. - Changeset (consumer-visible, patch pre-1.0).
- No refactor of existing components in this issue (see resolved decisions).
Resolved decisions
- Border radius — auto-inherit, consumer can override. The hover/press/selection overlay uses
borderRadius: inheritso it matches the child's radius by default. Explicit styling always wins:xstyle(and any direct radius override) takes precedence. - Disabled contract —
aria-disabledeverywhere. Both components keep the element focusable and discoverable viaaria-disabled(never native<button disabled>/ removal from tab order). Same contract across the whole system. Add adisabledReasonso the why is surfaced (tooltip + assistive tech) rather than a silently-dead control. isReadOnly— adopt. Preserves appearance but removes interaction (distinct fromisDisabled, which shows a disabled state).isSelected— deferred. Selection semantics (toggle vs. visually-selected button/link, and the right ARIA) need their own design; out of scope here. UseSelectableCardfor toggle selection.- Density — deferred. Not in the initial API; revisit only with a demonstrated need.
- Migration — none up front. Do not refactor
ClickableCard/SelectableCard/Token/Item/Thumbnail. Direct hook usage (useClickableContainer/useInteractiveRole) is preferable there — it produces less DOM than wrapping in a component. Worth a follow-up review to see whether any of them would genuinely reduce code drift by adopting a component, but that's not a goal of this issue.
Non-goals
- Not making all components polymorphic — interactivity is concentrated in these two components instead.
- Not removing
useClickableContainer/useInteractiveRole— the components build on them. - Not a visual redesign of hover/focus states — reuse existing overlay/focus token conventions.
Activity
Prajwalraut29 commentedon Jul 9, 2026
Hi team,
PR #3711 implements the
Clickable/ClickableContainerprimitives +useClickablehook from #3704.useClickable: core hook with a11y + handlersClickable: lightweight inline versionClickableContainer: block version with safe nested interactivesCloses #3704.
Ready for review — feedback welcome on API and integration with existing components (e.g. ClickableCard).
Thanks!
[-]Design generic Clickable / ClickableContainer primitives (+ useClickable hook)[/-][+]Add generic Clickable and ClickableContainer components[/+]Prajwalraut29 commentedon Jul 9, 2026
Title updated
Changed to: Add Clickable and ClickableContainer primitives (+ useClickable hook)
Keeps it consistent with the issue (#3704).
#3711
cixzhang commentedon Jul 10, 2026
Small API-convention correction on the spec while it's in
needs:api-review: the disabled-reason prop should bedisabledMessage, notdisabledReason.disabledMessageis the established name across the system (~40 components — CheckboxInput, DateInput, NumberInput, MultiSelector, PowerSearch, FileInput, …);disabledReasonisn't used anywhere. Worth fixing here soClickable/ClickableContainerland consistent with the rest of the API.[feat] Clickable/ClickableContainer: address PR review feedback