Repository navigation
Add Clickable and ClickableContainer primitives (+ useClickable hook) - #3711
Prajwalraut29 wants to merge 3 commits into
Conversation
|
@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. |
cixzhang
left a comment
There was a problem hiding this comment.
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, andxstyleis already spread last so a consumer can setxstyle={{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: usedisabledMessage(our convention, ~40 components) — the spec'sdisabledReasonis a misnomer. - Disabled contract is inconsistent on the container. The link path uses
aria-disabled, but the button uses nativedisabled— which removes it from the a11y tree. Per #3704 it should bearia-disabledeverywhere so it stays focusable/announced. Clickable.tsx#L334 - One component per file.
ClickableContainershould live in its ownClickableContainer/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.
|
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
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
|
@cixzhang can you check this PR as well |
cixzhang
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
Could this stay internal? #3704 argues against a spreadable clickable hook.
|
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? |
There was a problem hiding this comment.
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
useClickableinternal. The spec for this work deliberately ruled out a public spreadable hook (notably,hrefcannot work through a spread), so please remove the public export while keeping internal use byClickable. - Read-only links still navigate in both components —
isReadOnlyonly suppresses the callback whilehrefstays live. Please derive the effectivehref/callback from state in one place and addhref+isReadOnlytests. - Disabled controls are removed from tab order (
tabIndex: -1on most paths), so keyboard users cannot reachdisabledMessage. Please keep them focusable underaria-disabledconsistently, as documented. - A disabled or no-action
Clickablerenders a native button withouttype="button", which can submit an enclosing form, and the container's disabled hidden link keeps a livehref. 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-visibleon the leaf root fixes it.
[Automated review]
There was a problem hiding this comment.
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).
isReadOnlywithhrefstill navigates in both components; resolving disabled and read-only once, before the link/button branch, and testinghrefwithisReadOnlywould close it.- A disabled
ClickablegetstabIndex={-1}, so keyboard users never reachdisabledMessage;aria-disabledcontrols should stay focusable on every path. - A disabled
href-only or action-lessClickablerenders a native button withouttype="button", so it submits an enclosing form, and a disabled container keeps a live hiddenhref. - 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; |
There was a problem hiding this comment.
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} : {}; |
There was a problem hiding this comment.
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)': { |
There was a problem hiding this comment.
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)': { |
There was a problem hiding this comment.
: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.
|
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. |
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.