Skip to content

Add Clickable and ClickableContainer primitives (+ useClickable hook) - #3711

Closed
Prajwalraut29 wants to merge 3 commits into
meta:mainfrom
Prajwalraut29:clickable-primitives
Closed

Prajwalraut29 wants to merge 3 commits into
meta:mainfrom
Prajwalraut29:clickable-primitives

Conversation

@Prajwalraut29

Copy link
Copy Markdown
Contributor

Three generic interactivity primitives — useClickable (hook, returns spreadable a11y + handlers), (button/link wrapper with hover overlay, no padding), and (surface with safe nested interactives via hidden sr-only element). Builds on existing useClickableContainer and useInteractiveRole hooks. Reuses ClickableCard's overlay pattern (::after, color-mix). Resolves the "make this element a button" pattern currently hand-rolled across Token, Item, Thumbnail, and other components.

@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

@Prajwalraut29 is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 9, 2026
@Prajwalraut29 Prajwalraut29 changed the title Add Clickable and ClickableContainer primitives Add Clickable and ClickableContainer primitives (+ useClickable hook) Jul 9, 2026

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for building this out — the ClickableContainer a11y contract (hidden focusable sibling element, no role/tabIndex on the container, :has(:focus-visible) ring) looks well done. A few things to reconcile before merge, mostly against the spec in #3704 (worth linking in the PR body):

  • Drop isBlock. It's a novel prop with no precedent, and xstyle is already spread last so a consumer can set xstyle={{display: 'flex'}} directly. Let people style block/inline rather than bake in a bool. Clickable.tsx#L138
  • Missing resolved-decision props: isReadOnly + disabledMessage. Both are acceptance criteria in #3704. Note: use disabledMessage (our convention, ~40 components) — the spec's disabledReason is a misnomer.
  • Disabled contract is inconsistent on the container. The link path uses aria-disabled, but the button uses native disabled — which removes it from the a11y tree. Per #3704 it should be aria-disabled everywhere so it stays focusable/announced. Clickable.tsx#L334
  • One component per file. ClickableContainer should live in its own ClickableContainer/ClickableContainer.tsx — the existing multi-component files are all coupled Context families, not two independent primitives.
  • Component surface is incomplete. #3704 lists .test.tsx, .doc.mjs, a Storybook story, a showcase block, and a changeset. For a primitive whose whole value is a subtle a11y contract, tests especially are needed before merge.

@cixzhang cixzhang added area:core needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review labels Jul 10, 2026
@Prajwalraut29

Copy link
Copy Markdown
Contributor Author

Hi @cixzhang, I've addressed the review feedback on the same branch. PTAL when you get a chance. Thanks!

- Drop isBlock prop (consumers use xstyle directly)
- Add isReadOnly + disabledMessage props per meta#3704
- Fix disabled: use aria-disabled everywhere (never native disabled)
- Extract ClickableContainer to own file (one component per file)
- Add .test.tsx, .doc.mjs, Storybook stories, changeset
- Sync exports for ./ClickableContainer
@vercel

vercel Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 11, 2026 12:16pm

Request Review

@github-actions
github-actions Bot requested a review from cixzhang July 11, 2026 09:35
@Prajwalraut29

Copy link
Copy Markdown
Contributor Author

Pushed to clickable-primitives. All pre-commit checks (sync, package boundaries, changesets, demo media) passed cleanly.

- Add tsconfig path mappings for theme-neutral, theme-stone, theme-y2k, vega
- Remove invalid width prop from ClickableContainer stories
- Replace invalid icon names (add, settings) with valid IconName values
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) and removed needs:design-review Affects visuals — Design should review labels Jul 11, 2026
@Prajwalraut29

Copy link
Copy Markdown
Contributor Author

@cixzhang can you check this PR as well

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for turning this around, and the container's hidden-sibling contract reads right.

The two state props aren't landing yet. isReadOnly only replaces onClick, so both components still render a live <a href> — clicking a read-only ClickableContainer in Chrome navigates. isDisabled sets tabIndex={-1} on three of the four paths, so a keyboard user tabs straight past a disabled Clickable and never gets disabledMessage; the container's button path stays focusable. Ideally both resolve where useInteractiveRole already resolves isDisabled, before the link/button branch, so there's one contract instead of four.

Separately, could useClickable stay internal? #3704 rules out a spreadable clickable hook, partly because href can't come through a spread — which its own docs note.

It also needs a merge with main.

For read-only plus href — inert, or still navigable? If you'd rather talk it through with someone, we're in Discord.

[Reviewed by Robohands]

isEnabled: showsDisabledMessage,
});

const effectiveOnClick = isReadOnly ? undefined : onClickProp;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isReadOnly only drops onClick; href still navigates. Might want it going through useInteractiveRole like isDisabled does.

'aria-label': label,
'aria-disabled': (isDisabled && !isInert) || undefined,
role: isInert ? undefined : role,
tabIndex: isInert ? undefined : isDisabled ? -1 : 0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, tabIndex: -1 undoes aria-disabled — the element leaves the tab order.

export {useLongPress} from './useLongPress';
export type {UseLongPressOptions, UseLongPressHandlers} from './useLongPress';

export {useClickable} from './useClickable';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this stay internal? #3704 argues against a spreadable clickable hook.

@cixzhang

Copy link
Copy Markdown
Contributor

Checking in on Clickable state behavior: read-only links must not navigate, disabled controls must remain discoverable, and the public hook question is still open. Would you like to continue, have us carry it, or close this for now?

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for building these primitives — the container's hidden-sibling contract and the leaf/container split match the intended design well.

A few bounded changes are needed before this is ready:

  • Please keep useClickable internal. The spec for this work deliberately ruled out a public spreadable hook (notably, href cannot work through a spread), so please remove the public export while keeping internal use by Clickable.
  • Read-only links still navigate in both components — isReadOnly only suppresses the callback while href stays live. Please derive the effective href/callback from state in one place and add href + isReadOnly tests.
  • Disabled controls are removed from tab order (tabIndex: -1 on most paths), so keyboard users cannot reach disabledMessage. Please keep them focusable under aria-disabled consistently, as documented.
  • A disabled or no-action Clickable renders a native button without type="button", which can submit an enclosing form, and the container's disabled hidden link keeps a live href. Please make those states genuinely non-activatable.
  • The leaf focus style uses :has(:focus-visible) on the root itself, so the accent outline never matches its own focus — a direct :focus-visible on the leaf root fixes it.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for carrying these primitives this far. Approval of Clickable, ClickableContainer and the public useClickable hook waits on a maintainer providing the governing spec for this new public API, which needs to settle whether useClickable stays public or internal and whether a read-only href is inert or still navigable. Separately from that decision, the state handling needs a few fixes, and the branch needs a merge with main (it conflicts in packages/core/src/hooks/index.ts and apps/storybook/tsconfig.json).

  • isReadOnly with href still navigates in both components; resolving disabled and read-only once, before the link/button branch, and testing href with isReadOnly would close it.
  • A disabled Clickable gets tabIndex={-1}, so keyboard users never reach disabledMessage; aria-disabled controls should stay focusable on every path.
  • A disabled href-only or action-less Clickable renders a native button without type="button", so it submits an enclosing form, and a disabled container keeps a live hidden href.
  • The container's :has(:focus-visible) outline also paints while a nested control is focused, so two rings show for one focus move; scoping it to the hidden control fixes that.

[Automated review]

isEnabled: showsDisabledMessage,
});

const effectiveOnClick = isReadOnly && onClick ? () => {} : onClick;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isReadOnly only swaps the callback here; href still resolves to role link, so a read-only Clickable renders a live <a href> and navigates. Resolving disabled and read-only once, withholding both href and the callback before the link/button branch, would fix this path and the container's.

const LinkComponent = useLinkComponent();
const Component = role === 'link' ? LinkComponent : 'button';

const typeProp = role === 'button' ? {type: 'button' as const} : {};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the role resolves to inert (a disabled href without onClick, or neither href nor onClick), no type is set, so the native <button> defaults to type="submit" and submits an enclosing form, even while aria-disabled="true". Setting type="button" on every native button avoids it.

outlineOffset: '2px',
},
focusWithin: {
':has(:focus-visible)': {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The root is the focused element itself and :has() only matches descendants, so this outline never applies; Chromium falls back to its default ring. :focus-visible on the root would apply it.

outlineOffset: '2px',
},
focusWithin: {
':has(:focus-visible)': {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:has(:focus-visible) also matches a focused nested control, so tabbing to a nested button keeps this 2px outline while the button paints its own ring. Scoping the selector to the hidden control keeps one ring per focus move.

@cixzhang

Copy link
Copy Markdown
Contributor

Closing as stale to reduce CI load; feel free to reopen or push a fresh branch if it's still needed. Posted by Cindy's agent on her behalf.

@cixzhang cixzhang closed this Oct 28, 2026

This branch was successfully deployed

1 active deployment
Preview — 243e85b1 Deployed Jul 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants