@sanity/ui 5.0.0-alpha.22 → 5.0.0-alpha.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/README.md +10 -0
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/styles.css +1 -1
  5. package/docs/components/avatar-counter.dsds.yaml +78 -0
  6. package/docs/components/avatar-stack.dsds.yaml +96 -0
  7. package/docs/components/avatar.dsds.yaml +115 -0
  8. package/docs/components/badge.dsds.yaml +126 -0
  9. package/docs/components/box.dsds.yaml +223 -0
  10. package/docs/components/button.dsds.yaml +284 -0
  11. package/docs/components/card.dsds.yaml +317 -0
  12. package/docs/components/checkbox.dsds.yaml +204 -0
  13. package/docs/components/code.dsds.yaml +167 -0
  14. package/docs/components/container.dsds.yaml +189 -0
  15. package/docs/components/dialog.dsds.yaml +343 -0
  16. package/docs/components/divider.dsds.yaml +93 -0
  17. package/docs/components/eyebrow.dsds.yaml +217 -0
  18. package/docs/components/flex.dsds.yaml +237 -0
  19. package/docs/components/grid.dsds.yaml +217 -0
  20. package/docs/components/h-stack.dsds.yaml +127 -0
  21. package/docs/components/heading.dsds.yaml +233 -0
  22. package/docs/components/hotkeys.dsds.yaml +60 -0
  23. package/docs/components/icon-button.dsds.yaml +220 -0
  24. package/docs/components/icon.dsds.yaml +275 -0
  25. package/docs/components/indicator-stack.dsds.yaml +98 -0
  26. package/docs/components/indicator.dsds.yaml +108 -0
  27. package/docs/components/inline.dsds.yaml +127 -0
  28. package/docs/components/kbd.dsds.yaml +59 -0
  29. package/docs/components/link.dsds.yaml +108 -0
  30. package/docs/components/list-button-item.dsds.yaml +103 -0
  31. package/docs/components/list-item-image.dsds.yaml +82 -0
  32. package/docs/components/list-item-text.dsds.yaml +80 -0
  33. package/docs/components/list-item.dsds.yaml +148 -0
  34. package/docs/components/list.dsds.yaml +162 -0
  35. package/docs/components/popover.dsds.yaml +208 -0
  36. package/docs/components/press-area.dsds.yaml +279 -0
  37. package/docs/components/radio.dsds.yaml +198 -0
  38. package/docs/components/select.dsds.yaml +214 -0
  39. package/docs/components/skip-to-content.dsds.yaml +110 -0
  40. package/docs/components/spinner.dsds.yaml +119 -0
  41. package/docs/components/switch.dsds.yaml +202 -0
  42. package/docs/components/tab.dsds.yaml +54 -0
  43. package/docs/components/tabs-list.dsds.yaml +56 -0
  44. package/docs/components/tabs-panel.dsds.yaml +54 -0
  45. package/docs/components/tabs.dsds.yaml +104 -0
  46. package/docs/components/text-area.dsds.yaml +170 -0
  47. package/docs/components/text-input.dsds.yaml +189 -0
  48. package/docs/components/text.dsds.yaml +268 -0
  49. package/docs/components/tooltip-group.dsds.yaml +90 -0
  50. package/docs/components/tooltip.dsds.yaml +216 -0
  51. package/docs/components/v-stack.dsds.yaml +155 -0
  52. package/docs/components/visually-hidden.dsds.yaml +112 -0
  53. package/docs/evals/cases.yaml +1319 -0
  54. package/docs/examples/checkbox-2.tsx +57 -0
  55. package/docs/examples/confirmation-dialogs-1.tsx +27 -0
  56. package/docs/examples/confirmation-dialogs-2.tsx +55 -0
  57. package/docs/examples/confirmation-dialogs-3.tsx +28 -0
  58. package/docs/examples/confirmation-dialogs-4.tsx +38 -0
  59. package/docs/examples/popover-1.tsx +48 -0
  60. package/docs/examples/popover-2.tsx +53 -0
  61. package/docs/foundations/accessibility-guidelines.dsds.yaml +301 -0
  62. package/docs/foundations/color-guidelines.dsds.yaml +308 -0
  63. package/docs/foundations/content-guidelines.dsds.yaml +285 -0
  64. package/docs/foundations/semantics.dsds.yaml +125 -0
  65. package/docs/foundations/spacing-guidelines.dsds.yaml +226 -0
  66. package/docs/foundations/typography-guidelines.dsds.yaml +322 -0
  67. package/docs/icons.dsds.yaml +2513 -0
  68. package/docs/index.dsds.yaml +515 -0
  69. package/docs/overview/api-essentials.dsds.yaml +221 -0
  70. package/docs/overview/component-reference.dsds.yaml +215 -0
  71. package/docs/overview/designer-contribution-model.dsds.yaml +77 -0
  72. package/docs/overview/developer-contribution-model.dsds.yaml +362 -0
  73. package/docs/overview/installation.dsds.yaml +238 -0
  74. package/docs/overview/quick-start.dsds.yaml +317 -0
  75. package/docs/overview/resources.dsds.yaml +34 -0
  76. package/docs/patterns/confirmation-dialogs.dsds.yaml +140 -0
  77. package/docs/patterns/error-messaging.dsds.yaml +58 -0
  78. package/docs/patterns/forms.dsds.yaml +356 -0
  79. package/docs/patterns/layouts.dsds.yaml +403 -0
  80. package/docs/patterns/loading-states.dsds.yaml +41 -0
  81. package/docs/patterns/messaging.dsds.yaml +72 -0
  82. package/docs/patterns/navigation.dsds.yaml +153 -0
  83. package/docs/patterns/responsive.dsds.yaml +590 -0
  84. package/docs/tokens/color.dsds.yaml +1158 -0
  85. package/docs/tokens/container-widths.dsds.yaml +131 -0
  86. package/docs/tokens/content.dsds.yaml +258 -0
  87. package/docs/tokens/content.tokens.json +180 -0
  88. package/docs/tokens/dtcg/README.md +39 -0
  89. package/docs/tokens/dtcg/css/color.css +107 -0
  90. package/docs/tokens/dtcg/css/container.css +12 -0
  91. package/docs/tokens/dtcg/css/fontFamily.css +10 -0
  92. package/docs/tokens/dtcg/css/fontWeight.css +10 -0
  93. package/docs/tokens/dtcg/css/index.css +13 -0
  94. package/docs/tokens/dtcg/css/radius.css +14 -0
  95. package/docs/tokens/dtcg/css/semantic.css +42 -0
  96. package/docs/tokens/dtcg/css/shadow.css +22 -0
  97. package/docs/tokens/dtcg/css/space.css +16 -0
  98. package/docs/tokens/dtcg/css/typography.css +69 -0
  99. package/docs/tokens/dtcg/json/color.tokens.json +911 -0
  100. package/docs/tokens/dtcg/json/container.tokens.json +44 -0
  101. package/docs/tokens/dtcg/json/fontFamily.tokens.json +10 -0
  102. package/docs/tokens/dtcg/json/fontWeight.tokens.json +18 -0
  103. package/docs/tokens/dtcg/json/radius.tokens.json +58 -0
  104. package/docs/tokens/dtcg/json/semantic.tokens.json +372 -0
  105. package/docs/tokens/dtcg/json/shadow.tokens.json +599 -0
  106. package/docs/tokens/dtcg/json/space.tokens.json +72 -0
  107. package/docs/tokens/dtcg/json/typography.tokens.json +354 -0
  108. package/docs/tokens/font-family.dsds.yaml +79 -0
  109. package/docs/tokens/font-weight.dsds.yaml +103 -0
  110. package/docs/tokens/radius.dsds.yaml +153 -0
  111. package/docs/tokens/semantic.dsds.yaml +397 -0
  112. package/docs/tokens/shadow.dsds.yaml +125 -0
  113. package/docs/tokens/space.dsds.yaml +185 -0
  114. package/docs/tokens/typography.dsds.yaml +316 -0
  115. package/llms.txt +108 -0
  116. package/package.json +5 -2
  117. package/skills/sanity-ui-5/SKILL.md +158 -0
  118. package/skills/sanity-ui-5/references/component-choice.md +37 -0
  119. package/skills/sanity-ui-5/references/components.md +145 -0
  120. package/skills/sanity-ui-5/references/forms-and-accessibility.md +189 -0
  121. package/skills/sanity-ui-5/references/migrating-from-v3.md +250 -0
  122. package/skills/sanity-ui-5/references/props-and-imports.md +169 -0
  123. package/skills/sanity-ui-5/references/setup.md +177 -0
  124. package/skills/sanity-ui-5/references/silent-failures.md +33 -0
  125. package/skills/sanity-ui-5/references/taste.md +53 -0
  126. package/skills/sanity-ui-5/references/tone-and-color.md +55 -0
  127. package/src/version.ts +2 -2
@@ -0,0 +1,208 @@
1
+ kind: component
2
+ id: popover
3
+ name: Popover
4
+ description: A floating layer to disclose secondary, contextually relevant content or actions.
5
+ metadata:
6
+ tags: [popover, floating, overlay, contextual, non-modal, secondary]
7
+ status:
8
+ status: beta
9
+ sections:
10
+ - kind: guidelines
11
+ for: all
12
+ framing: when-to-use
13
+ title: When to use
14
+ items:
15
+ - level: should
16
+ statement: To save space by hiding secondary controls until requested.
17
+ - level: should
18
+ statement: To introduce or educate users on a specific feature or element on the screen.
19
+ - level: should-not
20
+ statement: To display critical information the user needs for their workflow.
21
+ - level: should-not
22
+ statement: To provide a standard list of options in a contextual menu. Use a List with List.ButtonItem inside this Popover instead.
23
+ alternatives:
24
+ - to: list-button-item
25
+ - level: must-not
26
+ statement: To display helper text via hover or focus. Use Tooltip instead.
27
+ alternatives:
28
+ - to: tooltip
29
+ - kind: guidelines
30
+ for: agent
31
+ framing: when-to-use
32
+ title: When to use
33
+ items:
34
+ - level: should
35
+ statement: To display non-essential, non-blocking secondary content.
36
+ - kind: guidelines
37
+ for: all
38
+ framing: how-to-use
39
+ items:
40
+ - level: must
41
+ statement: Open Popover on press or Space/Enter keypress. Popover should not open on hover.
42
+ - level: must
43
+ statement: Give the trigger a clear accessible name that describes what the Popover reveals.
44
+ - level: should
45
+ statement: Provide a visual cue that interacting with an item will open a Popover. When in doubt, use an end-aligned ChevronDownIcon.
46
+ - level: should
47
+ statement: Keep the content short and self-contained. A Popover should only be relevant to its target..
48
+ - level: should
49
+ statement: Choose a placement that keeps the content inside the viewport and clear of the trigger's neighbors.
50
+ - level: must-not
51
+ statement: Don't auto-open Popovers outside of walkthroughs.
52
+ - level: must-not
53
+ statement: Don't open more than one Popover at a time.
54
+ - level: must-not
55
+ statement: Do not use Popover for gating content. Use Dialog instead.
56
+ - kind: guidelines
57
+ for: agent
58
+ framing: how-to-use
59
+ items:
60
+ - level: must
61
+ statement: Popover has no `open`, `onOpen` or `onClose` prop. Its trigger opens it, and the browser closes it on Escape or an outside click. Do not mirror its open state in React state.
62
+ - level: must
63
+ statement: The child of Popover must be a single React element (not a string, fragment, or array). Popover clones it.
64
+ - level: must
65
+ statement: The child must render a button element. The popovertarget attribute is only honoured on buttons, so Button, IconButton, and a bare button work; a Box, Text, or div renders but never opens.
66
+ - level: must
67
+ statement: Move focus into the content when the panel opens. An auto popover does not move focus on its own. Do not use `autoFocus` for this. It causes usability problems for sighted and non-sighted users, and the `jsx-a11y/no-autofocus` lint rule flags it. Put the first control in a small component that focuses it in a `useEffect`. The content stays mounted while the popover is closed, so the effect runs each time the panel opens.
68
+ example:
69
+ title: Focus the first control when the panel opens
70
+ description: A filter panel whose first Select is focused by a small component's `useEffect`. Opening the Popover moves focus into the panel, so the next key press lands on the first filter, not back on the trigger.
71
+ ref:
72
+ href: ../examples/popover-1.tsx
73
+ rel: source
74
+ - level: should
75
+ statement: To open or close a Popover from code, put a `ref` on it. The ref reaches the native popover element, so `ref.current?.hidePopover()`, `showPopover()` and `togglePopover()` work. Use `hidePopover()` to close it after a form inside it submits.
76
+ example:
77
+ title: Close the popover when its form submits
78
+ description: A rename form inside a Popover. On submit it saves the name and closes the popover through the ref.
79
+ ref:
80
+ href: ../examples/popover-2.tsx
81
+ rel: source
82
+ - level: should
83
+ statement: The content box has its own padding, {space-2} across and {space-1} down, with radius {radius-2} and shadow {shadow-2}. Put the content straight inside; a padded wrapper doubles the padding.
84
+ - level: should
85
+ statement: Set portal only when an ancestor clips or misplaces the content.
86
+ - level: may
87
+ statement: Set the same anchorName on a Tooltip and a Popover to attach both to one trigger, with the Tooltip nested inside the Popover.
88
+ - level: must-not
89
+ statement: Don't set aria-expanded on the trigger by hand. Popover attaches popovertarget, and browsers implementing invoker semantics reflect aria-expanded themselves.
90
+ - level: must-not
91
+ statement: Escape and outside-click dismissal come from the browser. Do not reimplement them.
92
+ - level: must-not
93
+ statement: Do not trigger Popover on hover — trigger on click or keyboard press only.
94
+
95
+ alternatives:
96
+ - to: dialog
97
+ note: Use when the content must block the rest of the page or gate a task
98
+ - to: tooltip
99
+ note: Use when the floating content is a short, non-interactive label. Share a trigger with a Popover via `anchorName`
100
+ - to: list-button-item
101
+ refs:
102
+ - href: https://www.figma.com/design/5mhVqXlldJEEB2VWZeKQ4i/Sanity-UI?node-id=33949-674
103
+ rel: design
104
+ role: Figma component (v5)
105
+ - to: button
106
+ rel: relates-to
107
+ note: The required trigger for a Popover
108
+ - to: icon-button
109
+ rel: relates-to
110
+ note: The required trigger for a Popover
111
+ - to: card
112
+ rel: relates-to
113
+ note: Compose inside `content` when the floating surface needs its own tone, padding, or border
114
+ sourceFiles:
115
+ - platform: react
116
+ file: packages/ui/src/components/popover/Popover.tsx
117
+ imports:
118
+ - platform: react
119
+ code: import { Popover } from '@sanity/ui'
120
+ package: '@sanity/ui'
121
+ traits:
122
+ - traitType: variant
123
+ kind: enum
124
+ id: placement
125
+ description: >-
126
+ Position of the floating layer relative to its trigger. Keeps the content
127
+ in the viewport and clear of whatever sits next to the trigger. Each value
128
+ declares a fallback on the opposite side, so the browser flips the layer
129
+ rather than letting it overflow.
130
+ values:
131
+ - id: top
132
+ description: Above the trigger, centered.
133
+ - id: top-start
134
+ description: Above, aligned to the start edge.
135
+ - id: top-end
136
+ description: Above, aligned to the end edge.
137
+ - id: right
138
+ description: Right of the trigger, centered.
139
+ - id: right-start
140
+ description: Right, aligned to the start edge.
141
+ - id: right-end
142
+ description: Right, aligned to the end edge.
143
+ - id: bottom
144
+ description: >-
145
+ Below the trigger, centered. The default. The default reading
146
+ direction for a menu or a disclosure opened from a toolbar.
147
+ - id: bottom-start
148
+ description: Below, aligned to the start edge.
149
+ - id: bottom-end
150
+ description: >-
151
+ Below, aligned to the end edge. The conventional placement for a menu
152
+ opened from an end-aligned action button.
153
+ - id: left
154
+ description: Left of the trigger, centered.
155
+ - id: left-start
156
+ description: Left, aligned to the start edge.
157
+ - id: left-end
158
+ description: Left, aligned to the end edge.
159
+ - traitType: variant
160
+ kind: boolean
161
+ id: portal
162
+ description: >-
163
+ Renders the floating content into document.body through a React portal
164
+ instead of inline. Rarely needed. The content already sits in the
165
+ browser's top layer, so overflow ancestors do not clip it. Use when an
166
+ ancestor with transform, filter, or contain creates a containing block
167
+ that breaks anchor positioning. Portalled content does not render during
168
+ server-side rendering.
169
+ $extensions:
170
+ com.sanity.ui:
171
+ implementationStatus:
172
+ context: Implementation status. Lets a tool tell a component that is coming from one that does not exist, without parsing the status note.
173
+ implemented: true
174
+ migrationGuide:
175
+ context: 'Migration guide for this component, covering the codemod and the changes it cannot make. Held as an extension because it is temporary: migration tooling and porting agents read it, and it should be dropped when Sanity UI 3 support ends.'
176
+ guidance: |-
177
+ The v3 Popover was a controlled component positioned by Floating UI and rendered through a portal. The v5 Popover is uncontrolled and built on the native Popover API and CSS anchor positioning. Most of the v3 configuration surface is gone because the browser now does that work.
178
+
179
+ ### Key differences
180
+
181
+ - **Popover is no longer controlled.** `open` is removed. The trigger opens the Popover; you cannot drive it from state.
182
+ - **`children` is now the trigger, not a positioning reference.** In v3, `children` was the reference element and could be omitted in favor of `referenceElement`. In v5, `children` is required and must render a `<button>`.
183
+ - **Positioning is CSS, not JavaScript.** Floating UI is gone. `placement` maps to a CSS class, and viewport flipping uses `position-try-fallbacks`.
184
+ - **Card styling props are gone.** v3 Popover rendered a `PopoverCard` and accepted `radius`, `shadow`, `tone`, `padding`, `overflow`, and `width`. v5 applies a fixed radius, shadow, and padding. Compose a `Card` inside `content` if you need more.
185
+ - **No arrow.** The `arrow` prop is removed.
186
+ - **No layer management.** `zOffset`, `onActivate`, and the `Layer` context are gone. The browser's top layer handles stacking.
187
+
188
+ ### Detailed list of differences
189
+
190
+ | v3 prop | v5 prop | Notes |
191
+ | :---- | :---- | :---- |
192
+ | `open` | — | Removed. The Popover is uncontrolled and driven by the trigger. |
193
+ | `content` | `content` | Same purpose |
194
+ | `children` | `children` | Now required, and must render a `<button>`. It is the trigger, not just a positioning reference. |
195
+ | `placement` | `placement` | Same values, same default (`'bottom'`) |
196
+ | `portal` | `portal` | Now `boolean` only; v3 also accepted a portal name string |
197
+ | `arrow` | — | Removed |
198
+ | `disabled` | — | Removed. Conditionally render the trigger without a Popover instead. |
199
+ | `modal` | — | Removed. Use **Dialog** when interaction beneath the layer must be blocked. |
200
+ | `animate` | — | Removed. The open and close transition is always applied. |
201
+ | `fallbackPlacements`, `placementStrategy`, `preventOverflow`, `constrainSize` | — | Removed. CSS `position-try-fallbacks` flips the popover automatically. |
202
+ | `matchReferenceWidth`, `width` | — | Removed. Size the content yourself. |
203
+ | `referenceElement` | `anchorName` | Point a Popover at a shared anchor by name rather than by element reference. |
204
+ | `boundaryElement`, `floatingBoundary`, `referenceBoundary` | — | Removed. The viewport is the boundary. |
205
+ | `radius`, `shadow`, `tone`, `padding`, `overflow` | — | Removed. Compose a **Card** inside `content` for custom surface styling. |
206
+ | `scheme` | — | Removed |
207
+ | `zOffset`, `onActivate` | — | Removed. The browser's top layer handles stacking. |
208
+ | `updateRef`, `__unstable_margins` | — | Removed |
@@ -0,0 +1,279 @@
1
+ kind: component
2
+ id: press-area
3
+ name: PressArea
4
+ description: PressArea wraps a non-interactive element (Card, Box, Avatar) into an interactive target.
5
+ metadata:
6
+ tags:
7
+ - interactive
8
+ - press
9
+ - click
10
+ - surface
11
+ - card
12
+ - row
13
+ - clickable
14
+ - navigation
15
+ - anchor
16
+ - button
17
+ - press-area
18
+ status:
19
+ status: beta
20
+ sections:
21
+ - kind: guidelines
22
+ for: all
23
+ framing: when-to-use
24
+ title: When to use
25
+ items:
26
+ - level: should
27
+ statement: To make a non-Button interactive surface — a whole Card, a media tile, a list row, or an avatar that opens a profile.
28
+ - level: should
29
+ statement: To wrap a complex layout (icon + title + description + badge) in a single press target without rebuilding Button's chrome.
30
+ - level: should
31
+ statement: Add type='button' when PressArea is inside a <form> — the component sets no type, so the browser would default to type='submit'.
32
+ - level: should-not
33
+ statement: "For standard labeled actions like 'Save', 'Cancel', or 'Publish', and for icon-only toolbar buttons. Use Button — it provides label styling, icon support, tone, and loading state."
34
+ alternatives:
35
+ - to: button
36
+ - level: should-not
37
+ statement: For a clickable text link inside a paragraph. Render an <a> directly, or use a Link component if your app has one.
38
+ alternatives:
39
+ - to: link
40
+ - level: should-not
41
+ statement: For tabbed interfaces. Use Tabs — it provides keyboard navigation and aria-selected wiring.
42
+ alternatives:
43
+ - to: tabs
44
+ - level: should-not
45
+ statement: To wrap another interactive element (Button inside PressArea, PressArea inside PressArea). Nested interactives fail screen reader expectations (WCAG 4.1.2 A).
46
+ - id: non-interactive-backdrop-dialog-overlay
47
+ level: must-not
48
+ statement: "As a non-interactive backdrop, dialog overlay, or plain layout wrapper. PressArea must be activatable and cannot render as='div' — for a non-interactive surface use a styled Box."
49
+ alternatives:
50
+ - to: box
51
+ - kind: guidelines
52
+ for: agent
53
+ framing: when-to-use
54
+ title: When to use
55
+ items:
56
+ - level: should-not
57
+ statement: Don't use PressArea for switching between views. Use Tabs instead — it wires aria-selected and arrow-key navigation.
58
+ alternatives:
59
+ - to: tabs
60
+ - kind: guidelines
61
+ for: all
62
+ framing: how-to-use
63
+ items:
64
+ - id: press-area-renders-native-element
65
+ level: must
66
+ statement: 'PressArea renders a native `<button>` or `<a>`, never a `<div role="button">`.'
67
+ checks:
68
+ - href: ../evals/cases.yaml
69
+ role: agent-test
70
+ checkedBy: assisted
71
+ $extensions:
72
+ io.jev:
73
+ type: boolean
74
+ - level: must
75
+ statement: Give every PressArea an accessible name. Visible child text serves as the name; for purely visual content (icon-only press, captionless avatar) provide an aria-label that describes the action.
76
+ - level: must
77
+ statement: Use PressArea only for interactive surfaces — a real press target. Never use it as a non-interactive backdrop, dialog overlay, or layout wrapper; render a styled Box for those.
78
+ - id: keep-constrained-button-react-component
79
+ level: must
80
+ statement: Keep as constrained to 'button', 'a', or a React component. InteractiveAs<T> rejects arbitrary tags like 'div' or 'span'. Passing as='div' produces the error "Type 'string' is not assignable to type 'undefined'" — switch to 'button'/'a', or use Box if the element is not interactive.
81
+ - level: should
82
+ statement: Set as='a' with href when the press changes the URL; omit as when the press performs an action. Real anchors give middle-click and 'Open in new tab' for free.
83
+ - level: must-not
84
+ statement: "Don't style PressArea directly — it takes no padding, margin, background, radius, loading, icon, or other layout/visual props (passing them is a type error), and it sets no cursor. Put padding, background, tone, and border on the child Card or Box."
85
+ - level: must-not
86
+ statement: Don't nest interactive elements — Button inside PressArea, PressArea inside Button, or PressArea inside another PressArea. Screen readers and keyboard users can't reach the inner control reliably (WCAG 4.1.2 A).
87
+ - level: must-not
88
+ statement: Don't add role='button' to PressArea — it already renders a real <button>; overriding role breaks the native semantics.
89
+ - id: don-add-custom-onkeydown-handle
90
+ level: must-not
91
+ statement: Don't add a custom onKeyDown to handle Enter/Space — the native <button> and <a> already activate on those keys (WCAG 2.1.1 A).
92
+ - id: don-remove-focus-ring-outline
93
+ level: must-not
94
+ statement: "Don't remove the focus ring with outline: none or override it with inline styles — the offset and color are tuned for system contrast (WCAG 2.4.7 AA)."
95
+ - kind: guidelines
96
+ for: agent
97
+ framing: how-to-use
98
+ items:
99
+ - level: must-not
100
+ statement: 'Nesting a Button or another interactive element inside a PressArea. Instead: move the secondary action outside the press surface — for example, a Flex holding the PressArea and the Button as siblings.'
101
+ - kind: guidelines
102
+ for: all
103
+ title: Content
104
+ tags: [content]
105
+ items:
106
+ - id: press-area-sets-no-text-styles
107
+ level: should
108
+ statement: '**PressArea does not set text styles.** It provides an interaction surface. Use Text or Heading inside for typography.'
109
+ - kind: guidelines
110
+ for: all
111
+ title: Accessibility
112
+ description: 'Target conformance: WCAG Level AA.'
113
+ tags: [accessibility]
114
+ items:
115
+ - id: aria-label
116
+ level: must
117
+ statement: "Set `aria-label` on a PressArea whose children are purely visual (an icon-only press, an avatar with no caption). Describe the action — 'Open recipe details' — not the layout."
118
+ refines:
119
+ - to: content-guidelines#name-the-action
120
+ - id: aria-current
121
+ level: must
122
+ statement: 'Set `aria-current="page"` on the rendered `<a>` to mark the active item in a navigation list.'
123
+ - id: aria-disabled
124
+ level: must
125
+ statement: 'On the `<a>` form, use `aria-disabled` to show a disabled state, because `<a>` has no native `disabled`. When it is set, also stop navigation in `onClick`.'
126
+ refines:
127
+ - to: shared-foundations#aria-disabled-keeps-focus
128
+ - kind: section
129
+ for: all
130
+ freeform:
131
+ - title: For agents
132
+ body: |-
133
+ ### Element selection — `as` prop
134
+
135
+ PressArea's rendered element is set by `as`. It defaults to `'button'`.
136
+
137
+ | `as` value | Renders | Use when |
138
+ |------------|---------|----------|
139
+ | `'button'` (default) | `<button>` | The press performs an action (open inspector, toggle expanded, run a command) |
140
+ | `'a'` | `<a href="...">` | The press changes the URL (navigate to a detail page, jump to an anchor) |
141
+ | Custom component | That component | Router links — pass `as={Link}` from your router |
142
+
143
+ > **`as` is constrained to `'button'`, `'a'`, or a React component.** Passing an arbitrary tag like `'div'` fails the TypeScript check.
144
+
145
+ ### Width override pattern
146
+
147
+ PressArea fills its parent's width by default (`width: 100%` via `sui-width-full`). To shrink it to its content — for example, an icon-only press inside a toolbar — wrap it in a sized parent:
148
+
149
+ ```tsx
150
+ {/* Default — full width, good for list rows and Cards */}
151
+ <PressArea onClick={handleSelect}>
152
+ <Card>...</Card>
153
+ </PressArea>
154
+
155
+ {/* Shrink to content — wrap in a sized parent */}
156
+ <Box width="fit-content">
157
+ <PressArea onClick={handleToggle}>
158
+ <Icon icon={MenuIcon} />
159
+ </PressArea>
160
+ </Box>
161
+ ```
162
+
163
+ ### Inline style overrides
164
+
165
+ Most inline styles aren't needed. PressArea is intentionally minimal — apply visual state to the child component.
166
+
167
+ | Inline style | Alternative |
168
+ |--------------|-------------|
169
+ | `style={{ background: '...' }}` | Apply `tone` to the child Card or Box |
170
+ | `style={{ padding: '8px' }}` | Apply padding to the child Box or Card |
171
+ | `style={{ outline: 'none' }}` | Don't remove the focus ring — it's required for WCAG 2.4.7 AA |
172
+
173
+ ### Building a clickable Card
174
+
175
+ The most common use of PressArea is a clickable Card list row:
176
+
177
+ ```tsx
178
+ import { PressArea, Card, Flex, VStack, Heading, Text, Badge } from '@sanity/ui'
179
+
180
+ function RecipeRow({ recipe, onSelect }: { recipe: Recipe; onSelect: () => void }) {
181
+ return (
182
+ <PressArea onClick={onSelect} aria-label={`Open recipe: ${recipe.title}`}>
183
+ <Card>
184
+ <Flex alignItems="center" justifyContent="space-between" gap={3}>
185
+ <VStack gap={1}>
186
+ <Heading as="h3" size={1}>{recipe.title}</Heading>
187
+ <Text size={1} muted>{recipe.cuisine} · {recipe.prepTime}</Text>
188
+ </VStack>
189
+ <Badge tone={recipe.status === 'Published' ? 'positive' : 'caution'}>
190
+ {recipe.status}
191
+ </Badge>
192
+ </Flex>
193
+ </Card>
194
+ </PressArea>
195
+ )
196
+ }
197
+ ```
198
+
199
+ The `aria-label` describes the action ("Open recipe: …"), not the layout. Screen reader users get a clear "what does this press do?" announcement.
200
+
201
+ ### Don't nest interactives
202
+
203
+ ```tsx
204
+ {/* ✗ — Button inside a clickable PressArea — screen readers can't reach the inner Button reliably */}
205
+ <PressArea onClick={openRow}>
206
+ <Card>
207
+ <Heading as="h3">{title}</Heading>
208
+ <Button text="Quick edit" onClick={openEditor} />
209
+ </Card>
210
+ </PressArea>
211
+
212
+ {/* ✓ — move the secondary action outside the press surface */}
213
+ <Flex alignItems="center" gap={2}>
214
+ <PressArea onClick={openRow} aria-label={`Open ${title}`}>
215
+ <Card>
216
+ <Heading as="h3">{title}</Heading>
217
+ </Card>
218
+ </PressArea>
219
+ <Button text="Quick edit" onClick={openEditor} />
220
+ </Flex>
221
+ ```
222
+
223
+ ### PressArea vs Button
224
+
225
+ Use Button when the press is a chrome action with a label, icon, or tone. Use PressArea when the press is the content itself.
226
+
227
+ | Use **Button** for | Use **PressArea** for |
228
+ |---|---|
229
+ | "Save", "Cancel", "Publish" | Whole-Card "open detail" presses |
230
+ | Icon-only toolbar actions | Avatar / media-tile presses that open a profile |
231
+ | Form submit / reset | Navigation rows that should render as `<a>` |
232
+ | Anything that needs `tone`, `loading`, or `iconEnd` | Content surfaces with arbitrary children |
233
+ alternatives:
234
+ - to: button
235
+ note: Standard action trigger with label, icon, tone, and loading state. Use Button for chrome actions ("Save", "Publish"); use PressArea for content surfaces (a whole Card)
236
+ - to: box
237
+ - to: tabs
238
+ note: For switching between views
239
+ refs:
240
+ - to: card
241
+ rel: relates-to
242
+ note: Visual content surface. Often the child of PressArea when the whole card should be interactive
243
+ - to: list-button-item
244
+ rel: relates-to
245
+ note: Action trigger inside a Popover list
246
+ sourceFiles:
247
+ - platform: react
248
+ file: packages/ui/src/components/press-area/PressArea.tsx
249
+ imports:
250
+ - platform: react
251
+ code: import { PressArea } from '@sanity/ui'
252
+ package: '@sanity/ui'
253
+ traits:
254
+ - traitType: state
255
+ kind: boolean
256
+ id: enabled
257
+ description: Included in the tab order; onClick/href is active. PressArea sets no cursor, so the element's native cursor applies — pointer on <a href>, the default arrow on <button>.
258
+ - traitType: state
259
+ kind: boolean
260
+ id: hovered
261
+ description: Unstyled by default. Apply any visual hover through the child (for example, Card's tone change).
262
+ - traitType: state
263
+ kind: boolean
264
+ id: focused
265
+ description: 'Design-system focus ring on :focus-visible: outline --focus-outline with offset --focus-offset.'
266
+ - traitType: state
267
+ kind: boolean
268
+ id: disabled
269
+ description: 'On the <button> form: the native disabled attribute removes it from the tab order, suppresses click and keyboard activation, and CSS sets pointer-events: none.'
270
+ - traitType: state
271
+ kind: boolean
272
+ id: disabled-link
273
+ description: "On the <a> form: no native disabled exists. Use aria-disabled='true' and suppress navigation in onClick."
274
+
275
+ $extensions:
276
+ com.sanity.ui:
277
+ implementationStatus:
278
+ context: Implementation status. Lets a tool tell a component that is coming from one that does not exist, without parsing the status note.
279
+ implemented: true
@@ -0,0 +1,198 @@
1
+ kind: component
2
+ id: radio
3
+ name: Radio
4
+ description: Enables the selection from a small set of options (2–4).
5
+ metadata:
6
+ tags: [radio, form, input, single-select, choice, option, group]
7
+ status:
8
+ status: beta
9
+ sections:
10
+ - kind: guidelines
11
+ for: all
12
+ framing: when-to-use
13
+ title: When to use
14
+ items:
15
+ - level: should
16
+ statement: To select from a small set of options (2–4).
17
+ refines:
18
+ - to: forms#choose-control-by-option-count
19
+ - refs:
20
+ - to: forms#choose-control-by-option-count
21
+ rel: same-as
22
+ - level: should-not
23
+ statement: For binary on/off toggles that trigger immediate feedback. Use Switch instead.
24
+ alternatives:
25
+ - to: switch
26
+ - level: should-not
27
+ statement: When more than one option can be selected. Use Checkbox instead.
28
+ alternatives:
29
+ - to: checkbox
30
+ - kind: guidelines
31
+ for: all
32
+ framing: how-to-use
33
+ items:
34
+ - level: must
35
+ statement: Give every Radio an accessible name. Link a visible label element to it with id and htmlFor, or use aria-label or aria-labelledby when there is no visible text to link.
36
+ refines:
37
+ - to: forms#pair-with-visible-label
38
+ - level: must-not
39
+ statement: Use Radio without an accessible name. A nameless radio is announced as an unlabeled radio button.
40
+ - level: must
41
+ statement: Always group radios with a shared name prop for mutual exclusivity.
42
+ - refs:
43
+ - to: forms#pair-checked-with-onchange
44
+ rel: same-as
45
+ - level: should
46
+ statement: Wrap groups in a fieldset with a legend to provide group-level labeling.
47
+ - refs:
48
+ - to: forms#stack-options-vertically
49
+ rel: same-as
50
+ - refs:
51
+ - to: forms#stack-fields-vertically
52
+ rel: same-as
53
+ - refs:
54
+ - to: shared-foundations#error-state-never-disabled
55
+ rel: same-as
56
+ - level: must-not
57
+ statement: Don't horizontally arrange more than 2 radio options.
58
+ - refs:
59
+ - to: forms#no-mixed-controlled-uncontrolled
60
+ rel: same-as
61
+ - kind: guidelines
62
+ for: agent
63
+ framing: how-to-use
64
+ items:
65
+ - id: radio-has-accessible-name
66
+ level: must
67
+ statement: Every Radio has an accessible name from a linked label element, aria-label or aria-labelledby. Radio has no label prop.
68
+ checkedBy: manual
69
+ - level: must-not
70
+ statement: 'Passing hasError to Radio. Radio has no error state. Instead: Show a visible message near the group and link each Radio to it with aria-describedby.'
71
+ - refs:
72
+ - to: forms#error-prop-needs-visible-message
73
+ rel: same-as
74
+ - kind: guidelines
75
+ for: all
76
+ title: Content
77
+ tags: [content]
78
+ items:
79
+ - refs:
80
+ - to: content-guidelines#sentence-case-all-system-set
81
+ rel: same-as
82
+ - refs:
83
+ - to: forms#label-short
84
+ rel: same-as
85
+ - level: should
86
+ statement: All labels in a group should follow the same grammatical pattern ("Send weekly", "Send daily", "Send hourly" — not "Send weekly", "Daily digest", "Send hourly notifications").
87
+ - refs:
88
+ - to: forms#label-no-trailing-period
89
+ rel: same-as
90
+ - refs:
91
+ - to: forms#label-no-trailing-colon
92
+ rel: same-as
93
+ - kind: guidelines
94
+ for: all
95
+ title: Accessibility
96
+ description: 'Target conformance: WCAG Level AA.'
97
+ tags: [accessibility]
98
+ items:
99
+ - level: must
100
+ statement: The Radio has no name of its own (WCAG 4.1.2). Name it through a linked label element, aria-label or aria-labelledby.
101
+ - refs:
102
+ - to: forms#aria-label-overrides-name
103
+ rel: same-as
104
+ - refs:
105
+ - to: forms#aria-labelledby-references-name
106
+ rel: same-as
107
+ - refs:
108
+ - to: forms#label-available-to-screen-readers
109
+ rel: same-as
110
+ - refs:
111
+ - to: forms#error-described-in-text
112
+ rel: same-as
113
+ - refs:
114
+ - to: forms#border-contrast
115
+ rel: same-as
116
+ - kind: section
117
+ for: all
118
+ freeform:
119
+ - title: Example — single handler for a Radio group
120
+ body: |-
121
+ ```
122
+ import { Flex, Radio, Text, VStack } from '@sanity/ui'
123
+
124
+ <VStack gap={2}>
125
+ {plans.map((plan) => (
126
+ <Flex key={plan.id} alignItems="center" gap={2}>
127
+ <Radio
128
+ id={`plan-${plan.id}`}
129
+ name="plan"
130
+ value={plan.id}
131
+ checked={selectedPlan === plan.id}
132
+ onChange={(e) => setSelectedPlan(e.currentTarget.value)}
133
+ />
134
+ <Text as="label" htmlFor={`plan-${plan.id}`}>{plan.label}</Text>
135
+ </Flex>
136
+ ))}
137
+ </VStack>
138
+ ```
139
+
140
+ Use `checked` and `onChange` to control each radio from React state. Only the newly-selected Radio fires `onChange`. The previously-checked Radio does not fire a "deselect" event, so derive deselection from the next selection in state. Each `id` and `htmlFor` pair gives its option its name.
141
+ alternatives:
142
+ - to: checkbox
143
+ note: multi-select or boolean toggle
144
+ - to: switch
145
+ note: boolean toggle that takes effect immediately
146
+ - to: select
147
+ note: single-select dropdown for 5–20 options
148
+ refs:
149
+ - href: https://www.figma.com/design/5mhVqXlldJEEB2VWZeKQ4i/Sanity-UI?node-id=31902-99
150
+ rel: design
151
+ role: Figma component (v5)
152
+ sourceFiles:
153
+ - platform: react
154
+ file: packages/ui/src/components/radio/Radio.tsx
155
+ imports:
156
+ - platform: react
157
+ code: import { Radio } from '@sanity/ui'
158
+ package: '@sanity/ui'
159
+ traits:
160
+ - traitType: state
161
+ kind: boolean
162
+ id: enabled
163
+ description: Standard unselected state.
164
+ - traitType: state
165
+ kind: boolean
166
+ id: focused
167
+ description: Focus ring on :focus-visible.
168
+ - traitType: state
169
+ kind: boolean
170
+ id: checked
171
+ description: Filled inner dot showing the selected option.
172
+ - traitType: state
173
+ kind: boolean
174
+ id: disabled
175
+ description: Muted appearance, removed from tab order.
176
+ $extensions:
177
+ com.sanity.ui:
178
+ implementationStatus:
179
+ context: Implementation status. Lets a tool tell a component that is coming from one that does not exist, without parsing the status note.
180
+ implemented: true
181
+ migrationGuide:
182
+ context: 'Migration guide for this component, covering the codemod and the changes it cannot make. Held as an extension because it is temporary: migration tooling and porting agents read it, and it should be dropped when Sanity UI 3 support ends.'
183
+ guidance: |-
184
+ The v5 Radio is the input itself, with no label wrapper. It has no visible text and no name of its own. In v3, a separate `<label htmlFor>` named the Radio. In v5, link a label element with `id` and `htmlFor`, or use `aria-label` or `aria-labelledby`.
185
+
186
+ | v3 pattern | v5 pattern | Notes |
187
+ | :---- | :---- | :---- |
188
+ | `<label htmlFor="x">Label</label><Radio id="x" name="g" />` | `<Radio id="x" name="g" /><label htmlFor="x">Label</label>` | Same association. Use `Text as="label"` if you need the Sanity UI text styles |
189
+ | `<Radio checked />` | `<Radio checked />` | Same `checked`/`onChange` API |
190
+ | All native `<input>` attributes (`name`, `value`, `required`, `aria-*`) | Forwarded unchanged | Pass them as before |
191
+
192
+ ### Breaking changes
193
+
194
+ - **`customValidity` removed.** Handle validation outside the component. Show a visible message near the group and link it with `aria-describedby`.
195
+
196
+ ### Codemod
197
+
198
+ Run `pnpx @sanity/ui-codemod latest:radio --paths <paths> --toPackage @sanity/ui`. It updates the import and warns about `customValidity`. It does not rewrite `label` props or wrapping label elements. Fix those by hand.