Skip to content

Commit dd24917

Browse files
fix(mosaic): derive nested radii from the surrounding surface (#10579)
1 parent ac24c87 commit dd24917

7 files changed

Lines changed: 52 additions & 19 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/mosaic': patch
3+
---
4+
5+
Align the corners of `Select`, `Combobox`, `Menu` and `PhoneInput` options and `ActionBar` buttons with their surrounding surface. These radii now follow `--cl-radius-lg` and `--cl-spacing` rather than `--cl-radius-md`, so an override of `--cl-radius-md` no longer changes them.

‎packages/mosaic/AGENTS.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ Stop and check the table if you are writing any of these in a feature:
7373
- `setTimeout` to debounce or to delay a spinner
7474
- `stylex.create` inside a `.tsx` file
7575

76+
## Nested radii
77+
78+
A part inset from a rounded surface gets its radius from that surface: `max(0px, calc(outer - border - padding))`. Do not pick a fixed step, or it stops matching when `--cl-radius-*` or `--cl-spacing` is overridden. This applies to small insets. When the inset is about as large as the outer radius or larger (Card content, TagInput tags), the part keeps its own radius.
79+
80+
- **Same component:** declare the outer radius, border and padding as local consts, and use them in both the surface and the calc, so changing any of them updates the inner radius (`components/select/select.styles.ts`).
81+
- **Different component:** the parent computes the radius from the same consts and sets a `--_cl-*-radius` var, and the child reads it with a fallback (`--_cl-button-radius` in `components/action-bar/action-bar.styles.ts` and `components/button/button.styles.ts`).
82+
83+
Do not add a shared `concentric()` helper or a global surface-radius var. A global var inherits into nested surfaces and gives them the wrong value.
84+
7685
## Readability before complexity scores
7786

7887
Do not extract a helper or introduce a machine only to reduce a lint score.

‎packages/mosaic/src/components/action-bar/action-bar.styles.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
} from '../../tokens.stylex';
1313

1414
const reduceMotion = '@media (prefers-reduced-motion: reduce)';
15+
const barRadius = radiusVars['--cl-radius-lg'];
16+
const inset = space['1'];
1517

1618
export const styles = stylex.create({
1719
positioner: {
@@ -25,10 +27,11 @@ export const styles = stylex.create({
2527
'--_cl-icon-color': colorVars['--cl-color-negative'],
2628
},
2729
bar: {
28-
borderRadius: radiusVars['--cl-radius-lg'],
30+
'--_cl-button-radius': `max(0px, calc(${barRadius} - ${inset}))`,
31+
borderRadius: barRadius,
2932
gap: space['1'],
30-
paddingBlock: space['1'],
31-
paddingInline: space['1'],
33+
paddingBlock: inset,
34+
paddingInline: inset,
3235
alignItems: 'center',
3336
backgroundColor: colorVars['--cl-color-surface'],
3437
blockSize: space['10'],

‎packages/mosaic/src/components/combobox/combobox.styles.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ import {
1212
typeScaleVars,
1313
} from '../../tokens.stylex';
1414

15+
const popupRadius = radiusVars['--cl-radius-lg'];
16+
const inset = space['1'];
17+
const optionRadius = `max(0px, calc(${popupRadius} - ${inset}))`;
18+
1519
export const styles = stylex.create({
1620
positioner: {
1721
outline: 'none',
1822
},
1923
popup: {
20-
borderRadius: radiusVars['--cl-radius-lg'],
24+
borderRadius: popupRadius,
2125
outline: 'none',
2226
overflow: 'hidden',
2327
backgroundColor: colorVars['--cl-color-surface'],
@@ -53,21 +57,21 @@ export const styles = stylex.create({
5357
minWidth: '12.5rem',
5458
},
5559
viewport: {
56-
padding: space['1'],
60+
padding: inset,
5761
gap: space['0.5'],
5862
display: 'flex',
5963
flexDirection: 'column',
6064
maxHeight: '16rem',
6165
},
6266
list: {
63-
padding: space['1'],
67+
padding: inset,
6468
gap: space['0.5'],
6569
display: 'flex',
6670
flexDirection: 'column',
6771
maxHeight: '16rem',
6872
},
6973
option: {
70-
borderRadius: radiusVars['--cl-radius-md'],
74+
borderRadius: optionRadius,
7175
gap: space['2'],
7276
outline: {
7377
default: 'none',

‎packages/mosaic/src/components/menu/menu.styles.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import {
1212
typeScaleVars,
1313
} from '../../tokens.stylex';
1414

15+
const popupRadius = radiusVars['--cl-radius-lg'];
16+
const inset = space['0.5'];
17+
const itemRadius = `max(0px, calc(${popupRadius} - ${inset}))`;
18+
1519
// Positioning is applied inline by the headless positioner; this only clears the
1620
// focus outline it receives. No z-index: the portalled, fixed positioner already
1721
// paints above page content, and consumers own their own stacking order.
@@ -23,7 +27,7 @@ export const positioner = stylex.create({
2327

2428
export const popup = stylex.create({
2529
base: {
26-
borderRadius: radiusVars['--cl-radius-lg'],
30+
borderRadius: popupRadius,
2731
outline: 'none',
2832
backgroundColor: colorVars['--cl-color-surface'],
2933
boxShadow: shadowVars['--cl-shadow-md'],
@@ -73,7 +77,7 @@ export const viewport = stylex.create({
7377
// The inset belongs to the scrolling box, not the popup: `Menu.Separator` bleeds through it
7478
// with a negative margin, and from inside a viewport that clips its inline axis a bleed past
7579
// the popup's own padding would be cut off instead.
76-
padding: space['0.5'],
80+
padding: inset,
7781
gap: space['0.5'],
7882
display: 'flex',
7983
flexDirection: 'column',
@@ -82,7 +86,7 @@ export const viewport = stylex.create({
8286

8387
export const item = stylex.create({
8488
base: {
85-
borderRadius: '0.375rem',
89+
borderRadius: itemRadius,
8690
borderStyle: 'none',
8791
gap: space['0.5'],
8892
outline: 'none',
@@ -175,7 +179,7 @@ export const separator = stylex.create({
175179
base: {
176180
// Full-bleed across the popup: cancel the viewport's inline padding.
177181
marginBlock: space['0.5'],
178-
marginInline: `calc(-1 * ${space['0.5']})`,
182+
marginInline: `calc(-1 * ${inset})`,
179183
backgroundColor: colorVars['--cl-color-border'],
180184
blockSize: '1px',
181185
flexShrink: 0,

‎packages/mosaic/src/components/phone-input/phone-input.styles.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import {
1010
typeScaleVars,
1111
} from '../../tokens.stylex';
1212

13+
const popupRadius = radiusVars['--cl-radius-lg'];
14+
const listInset = space['1'];
15+
const optionRadius = `max(0px, calc(${popupRadius} - ${listInset}))`;
16+
1317
export const styles = stylex.create({
1418
triggerStart: {
1519
paddingInlineStart: 'var(--_cl-input-group-inset)',
@@ -64,7 +68,7 @@ export const styles = stylex.create({
6468
paddingInlineStart: space['1.5'],
6569
},
6670
popup: {
67-
borderRadius: radiusVars['--cl-radius-lg'],
71+
borderRadius: popupRadius,
6872
overflow: 'hidden',
6973
backgroundColor: colorVars['--cl-color-surface'],
7074
boxShadow: shadowVars['--cl-shadow-md'],
@@ -114,15 +118,14 @@ export const styles = stylex.create({
114118
},
115119
},
116120
countryList: {
121+
padding: listInset,
117122
gap: space['0.5'],
118-
paddingBlock: space['0.5'],
119-
paddingInline: space['1'],
120123
display: 'flex',
121124
flexDirection: 'column',
122125
maxHeight: '16rem',
123126
},
124127
option: {
125-
borderRadius: radiusVars['--cl-radius-md'],
128+
borderRadius: optionRadius,
126129
gap: space['1'],
127130
outline: {
128131
default: 'none',

‎packages/mosaic/src/components/select/select.styles.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import {
1313
} from '../../tokens.stylex';
1414
import { selectOptionScope } from './select.markers.stylex';
1515

16+
const popupRadius = radiusVars['--cl-radius-lg'];
17+
const popupBorder = '1px';
18+
const inset = space['0.5'];
19+
const optionRadius = `max(0px, calc(${popupRadius} - ${popupBorder} - ${inset}))`;
20+
1621
// With `alignItemWithTrigger` the selected option's box lands over the trigger's, so the two
1722
// boxes must inset their text identically: the trigger is a `md` Button (32px, 1px border, 12px
1823
// inline padding, sm text), and the option gets the same 13px from the popup's 1px border, the
@@ -36,9 +41,9 @@ export const popup = stylex.create({
3641
base: {
3742
// Transparent, not removed: it holds the 1px of layout the alignment counts on, and forced colors paints it.
3843
borderColor: 'transparent',
39-
borderRadius: radiusVars['--cl-radius-lg'],
44+
borderRadius: popupRadius,
4045
borderStyle: 'solid',
41-
borderWidth: '1px',
46+
borderWidth: popupBorder,
4247
outline: 'none',
4348
backgroundColor: colorVars['--cl-color-surface'],
4449
boxShadow: shadowVars['--cl-shadow-md'],
@@ -77,7 +82,7 @@ export const popup = stylex.create({
7782

7883
export const viewport = stylex.create({
7984
base: {
80-
padding: space['0.5'],
85+
padding: inset,
8186
gap: space['0.5'],
8287
display: 'flex',
8388
flexDirection: 'column',
@@ -86,7 +91,7 @@ export const viewport = stylex.create({
8691

8792
export const option = stylex.create({
8893
base: {
89-
borderRadius: radiusVars['--cl-radius-md'],
94+
borderRadius: optionRadius,
9095
borderStyle: 'none',
9196
gap: space['2'],
9297
outline: 'none',

0 commit comments

Comments
 (0)