Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .changeset/remove-menu-indicator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@clerk/mosaic': minor
---

**Breaking:** Remove `Menu.Indicator` and the `size` prop on `Menu.Media`. Menu now has checkbox and radio items, so a checkmark that marks the current choice goes in their indicator and is announced with `aria-checked`. Anything else at the end of a row, such as a spinner, goes in a trailing `Menu.Media`, which keeps its width while empty. `Menu.Media` is now always 20px wide; `size='xs'` made it 16px without changing the row height, so the label no longer lined up with the other rows.

| Before | After |
| ------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| `<Menu.Item>` with a check in `<Menu.Indicator>` | `<Menu.RadioItem value>` in a `<Menu.RadioGroup>`, with the check in `<Menu.RadioItemIndicator>` |
| A toggled `<Menu.Item>` with a check in `<Menu.Indicator>` | `<Menu.CheckboxItem>`, with the check in `<Menu.CheckboxItemIndicator>` |
| Any other `<Menu.Indicator>…</Menu.Indicator>` | `<Menu.Media>…</Menu.Media>` |
| `MenuIndicatorProps` | `MenuMediaProps`, `MenuRadioItemIndicatorProps` or `MenuCheckboxItemIndicatorProps` |
| `.cl-menu-item-indicator` | `.cl-menu-item-media`, `.cl-menu-radio-item-indicator` or `.cl-menu-checkbox-item-indicator` |
| `<Menu.Media size='xs'>` or `size='sm'` | `<Menu.Media>` |
| `MenuMediaSize` | Remove it |
| `.cl-menu-item-media[data-size]` | `.cl-menu-item-media` |

Find usages with `git grep -nE 'Menu\.Indicator|MenuIndicatorProps|cl-menu-item-indicator|MenuMediaSize|Menu\.Media[^>]*size='`.

Checkbox and radio items keep the menu open on click. Pass `closeOnClick` to close it.

In the Switcher's accounts flyout, each account is now a `menuitemradio` inside a group named "Switch account", and the active one has `aria-checked="true"` in place of `aria-current="true"`.
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ describe('Mosaic ActionMenu', () => {
await waitFor(() => expect(screen.queryByRole('menu')).not.toBeInTheDocument());
});

it('reserves an indicator immediately and delays its named spinner', async () => {
it('reserves a trailing media column immediately and delays its named spinner', async () => {
const user = userEvent.setup();
render(<AsyncMenu />);
await user.click(screen.getByRole('button', { name: 'Manage passkey' }));
const item = await screen.findByRole('menuitem', { name: 'Regenerate' });
expect(item.querySelector('.cl-menu-item-indicator')).toBeInTheDocument();
expect(item.lastElementChild).toHaveClass('cl-menu-item-media');
expect(item.lastElementChild).toBeEmptyDOMElement();
expect(screen.getByRole('menuitem', { name: 'Remove' }).querySelector('.cl-menu-item-media')).toBeNull();
vi.useFakeTimers();
try {
fireEvent.click(item);
Expand Down
4 changes: 2 additions & 2 deletions packages/mosaic/src/components/action-menu/action-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ export function ActionMenu({ label, actions, triggerRef, disabled, focusableWhen
) : null}
<Menu.Label>{action.label}</Menu.Label>
{action.status !== undefined ? (
<Menu.Indicator>
<Menu.Media>
{action.status === 'pending' && showSpinner ? (
<Spinner
size='sm'
label={action.label}
/>
) : null}
</Menu.Indicator>
</Menu.Media>
) : null}
</Menu.Item>
))}
Expand Down
6 changes: 5 additions & 1 deletion packages/mosaic/src/components/menu/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
export * as Menu from './menu.parts';
export type {
MenuCheckboxItemIndicatorProps,
MenuCheckboxItemProps,
MenuItemProps,
MenuLabelProps,
MenuMediaProps,
MenuMediaSize,
MenuPopupProps,
MenuProps,
MenuRadioGroupProps,
MenuRadioItemIndicatorProps,
MenuRadioItemProps,
MenuSeparatorProps,
MenuTriggerProps,
} from './menu';
116 changes: 98 additions & 18 deletions packages/mosaic/src/components/menu/menu.doc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import type { ComponentDoc } from '../../docs-schema';
import type { MenuProps } from '../../primitives/menu/menu-root';
import type {
MenuIndicatorProps,
MenuCheckboxItemIndicatorProps,
MenuCheckboxItemProps,
MenuItemProps,
MenuLabelProps,
MenuMediaProps,
MenuPopupProps,
MenuRadioGroupProps,
MenuRadioItemIndicatorProps,
MenuRadioItemProps,
MenuSeparatorProps,
MenuTriggerProps,
} from './menu';
Expand All @@ -18,8 +22,10 @@ export default {
'a list of actions behind an ellipsis button',
'a row or card overflow menu',
'a destructive action among others, with `color="negative"`',
'a setting toggled on or off, with `Menu.CheckboxItem`',
'marking the current choice, such as the active account, with `Menu.RadioItem`',
],
keywords: ['menu', 'dropdown', 'overflow', 'ellipsis', 'more actions', 'kebab'],
keywords: ['menu', 'dropdown', 'overflow', 'ellipsis', 'more actions', 'kebab', 'checkbox', 'radio', 'checked'],
practices: [
{
do: true,
Expand All @@ -29,12 +35,15 @@ export default {
do: true,
text: 'Put the item text in `Menu.Label`, not straight in `Menu.Item`, so it lines up and truncates.',
},
{ do: true, text: 'Use the same `Menu.Media` size for every item in one menu, so the text starts on one line.' },
{
do: true,
text: 'Pass an `aria-label` to a `Menu.Trigger` with no children. The default ellipsis has no name.',
},
{ do: false, text: 'Use it to pick a value. Use `Select` instead.' },
{
do: true,
text: 'Show a checked state with `Menu.CheckboxItem` or `Menu.RadioItem` and their indicator, not a checkmark in `Menu.Media`, so `aria-checked` announces it.',
},
{ do: false, text: 'Use it as a form field that picks a value. Use `Select` instead.' },
],
parts: {
'Menu.Root': {
Expand Down Expand Up @@ -85,8 +94,7 @@ export default {
},
},
'Menu.Item': {
description:
'One action, as a `button`. What it shows is the `Menu.Media`, `Menu.Label` and `Menu.Indicator` inside it.',
description: 'One action, as a `button`. What it shows is the `Menu.Media` and `Menu.Label` inside it.',
slot: 'cl-menu-item',
props: {
label: { type: 'string', doc: 'The text typeahead matches on. Not rendered and not the accessible name.' },
Expand All @@ -96,23 +104,78 @@ export default {
},
},
'Menu.Media': {
description: 'A square leading column that centers an icon, image or avatar.',
description:
'A square column at either end of the row that centers an icon, image, avatar or spinner. Keeps its width while empty.',
slot: 'cl-menu-item-media',
},
'Menu.Label': {
description: 'The item text. Fills the space between the media at either end and cuts to one line.',
slot: 'cl-menu-item-label',
},
'Menu.CheckboxItem': {
description:
'An item that toggles on and off, as a `button` with `role="menuitemcheckbox"`. Keeps the menu open on click by default.',
slot: 'cl-menu-checkbox-item',
props: {
size: {
type: 'MenuMediaSize',
doc: '`sm` fits an icon or avatar, `xs` a bare glyph. Sets the row height.',
default: "'sm'",
label: { type: 'string', doc: 'The text typeahead matches on. Not rendered and not the accessible name.' },
checked: { type: 'boolean', doc: 'Whether the item is checked, when controlled.' },
defaultChecked: {
type: 'boolean',
doc: 'Whether the item starts checked, when uncontrolled.',
default: 'false',
},
onCheckedChange: { type: '(checked: boolean) => void', doc: 'Called with the new checked state.' },
disabled: { type: 'boolean', doc: 'Disables the item and ignores its `onClick`.' },
closeOnClick: { type: 'boolean', doc: 'Closes the menu after a click.', default: 'false' },
},
},
'Menu.Label': {
description: 'The item text. Fills the space between media and indicator and cuts to one line.',
slot: 'cl-menu-item-label',
'Menu.RadioGroup': {
description: 'Holds the value of the radio items inside it. Name it with `aria-label`.',
slot: 'cl-menu-radio-group',
props: {
value: { type: 'string', doc: "The checked item's value, when controlled." },
defaultValue: { type: 'string', doc: "The checked item's value on mount, when uncontrolled." },
onValueChange: {
type: '(value: string) => void',
doc: "Called with the picked item's value, even when it is already checked.",
},
disabled: { type: 'boolean', doc: 'Disables every item in the group.' },
},
},
'Menu.RadioItem': {
description:
'An item that picks its group\'s value, as a `button` with `role="menuitemradio"`. Keeps the menu open on click by default.',
slot: 'cl-menu-radio-item',
props: {
label: { type: 'string', doc: 'The text typeahead matches on. Not rendered and not the accessible name.' },
value: { type: 'string', doc: 'The value the group takes when this item is picked.' },
disabled: { type: 'boolean', doc: 'Disables the item and ignores its `onClick`.' },
closeOnClick: { type: 'boolean', doc: 'Closes the menu after a click.', default: 'false' },
},
},
'Menu.CheckboxItemIndicator': {
description:
'A square column in every row with a check in the secondary icon color, shown only while its checkbox item is checked.',
slot: 'cl-menu-checkbox-item-indicator',
props: {
keepMounted: {
type: 'boolean',
doc: 'Keeps its column, with the check hidden, while unchecked, so labels line up. Pass `false` to render it only while checked.',
default: 'true',
},
},
},
'Menu.Indicator': {
description: 'A small square trailing slot, such as for a spinner while the action runs.',
slot: 'cl-menu-item-indicator',
'Menu.RadioItemIndicator': {
description:
'A square column in every row with a check in the secondary icon color, shown only while its radio item is checked.',
slot: 'cl-menu-radio-item-indicator',
props: {
keepMounted: {
type: 'boolean',
doc: 'Keeps its column, with the check hidden, while unchecked, so labels line up. Pass `false` to render it only while checked.',
default: 'true',
},
},
},
'Menu.Separator': {
description: 'A full-width divider between groups of items.',
Expand All @@ -135,6 +198,19 @@ export default {
</Menu.Item>
</Menu.Popup>
</Menu.Root>
`,
},
{
title: 'Picking the current account',
code: `
<Menu.RadioGroup aria-label='Accounts' value={activeId} onValueChange={switchTo}>
{accounts.map(account => (
<Menu.RadioItem key={account.id} label={account.name} value={account.id} closeOnClick>
<Menu.Label>{account.name}</Menu.Label>
<Menu.RadioItemIndicator />
</Menu.RadioItem>
))}
</Menu.RadioGroup>
`,
},
],
Expand All @@ -146,6 +222,10 @@ export default {
'Menu.Item': MenuItemProps;
'Menu.Media': MenuMediaProps;
'Menu.Label': MenuLabelProps;
'Menu.Indicator': MenuIndicatorProps;
'Menu.CheckboxItem': MenuCheckboxItemProps;
'Menu.RadioGroup': MenuRadioGroupProps;
'Menu.RadioItem': MenuRadioItemProps;
'Menu.CheckboxItemIndicator': MenuCheckboxItemIndicatorProps;
'Menu.RadioItemIndicator': MenuRadioItemIndicatorProps;
'Menu.Separator': MenuSeparatorProps;
}>;
6 changes: 5 additions & 1 deletion packages/mosaic/src/components/menu/menu.parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ export {
MenuTrigger as Trigger,
MenuPopup as Popup,
MenuItem as Item,
MenuCheckboxItem as CheckboxItem,
MenuRadioGroup as RadioGroup,
MenuRadioItem as RadioItem,
MenuCheckboxItemIndicator as CheckboxItemIndicator,
MenuRadioItemIndicator as RadioItemIndicator,
MenuMedia as Media,
MenuLabel as Label,
MenuIndicator as Indicator,
MenuSeparator as Separator,
} from './menu';
36 changes: 22 additions & 14 deletions packages/mosaic/src/components/menu/menu.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,7 @@ export const media = stylex.create({
display: 'flex',
flexShrink: 0,
justifyContent: 'center',
},
xs: { width: space['4'] },
sm: { width: space['5'] },
});

// The item lays its children out in one flat row, so the label is what has to take the space
// between the media and whatever trails it, rather than the row spacing the three evenly.
// `minWidth: 0` is what lets it shrink past its text and truncate instead of pushing the row wide.
export const label = stylex.create({
base: {
paddingInline: space['1'],
flexGrow: 1,
minWidth: 0,
width: space['5'],
},
});

Expand All @@ -167,7 +155,27 @@ export const indicator = stylex.create({
display: 'flex',
flexShrink: 0,
justifyContent: 'center',
width: space['4'],
visibility: { default: 'hidden', ':is([data-checked])': 'visible' },
width: space['5'],
},
});

export const radioGroup = stylex.create({
base: {
gap: space['0.5'],
display: 'flex',
flexDirection: 'column',
},
});

// The item lays its children out in one flat row, so the label is what has to take the space
// between the media and whatever trails it, rather than the row spacing the three evenly.
// `minWidth: 0` is what lets it shrink past its text and truncate instead of pushing the row wide.
export const label = stylex.create({
base: {
paddingInline: space['1'],
flexGrow: 1,
minWidth: 0,
},
});

Expand Down
Loading
Loading