@astryxdesign/core 0.1.7-canary.eb8e07b → 0.1.7
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.
- package/dist/ContextMenu/ContextMenu.d.ts.map +1 -1
- package/dist/ContextMenu/ContextMenu.js +3 -4
- package/dist/ContextMenu/index.d.ts +0 -3
- package/dist/ContextMenu/index.d.ts.map +1 -1
- package/dist/ContextMenu/index.js +1 -7
- package/dist/DropdownMenu/DropdownMenu.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenu.js +4 -8
- package/dist/DropdownMenu/DropdownMenuContext.d.ts +1 -17
- package/dist/DropdownMenu/DropdownMenuContext.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuContext.js +0 -18
- package/dist/DropdownMenu/index.d.ts +1 -5
- package/dist/DropdownMenu/index.d.ts.map +1 -1
- package/dist/DropdownMenu/index.js +1 -10
- package/dist/Icon/Icon.d.ts +12 -17
- package/dist/Icon/Icon.d.ts.map +1 -1
- package/dist/Icon/Icon.js +20 -28
- package/dist/astryx.css +1 -15
- package/dist/astryx.umd.js +46 -46
- package/dist/astryx.umd.js.map +4 -4
- package/package.json +1 -1
- package/src/ContextMenu/ContextMenu.test.tsx +1 -75
- package/src/ContextMenu/ContextMenu.tsx +5 -10
- package/src/ContextMenu/index.ts +0 -15
- package/src/DropdownMenu/DropdownMenu.doc.mjs +0 -10
- package/src/DropdownMenu/DropdownMenu.tsx +6 -11
- package/src/DropdownMenu/DropdownMenuContext.tsx +1 -29
- package/src/DropdownMenu/index.ts +3 -23
- package/src/Icon/Icon.test.tsx +0 -46
- package/src/Icon/Icon.tsx +24 -37
- package/dist/DropdownMenu/DropdownMenuCheckboxItem.d.ts +0 -89
- package/dist/DropdownMenu/DropdownMenuCheckboxItem.d.ts.map +0 -1
- package/dist/DropdownMenu/DropdownMenuCheckboxItem.js +0 -170
- package/dist/DropdownMenu/DropdownMenuRadioGroup.d.ts +0 -69
- package/dist/DropdownMenu/DropdownMenuRadioGroup.d.ts.map +0 -1
- package/dist/DropdownMenu/DropdownMenuRadioGroup.js +0 -70
- package/dist/DropdownMenu/DropdownMenuRadioItem.d.ts +0 -69
- package/dist/DropdownMenu/DropdownMenuRadioItem.d.ts.map +0 -1
- package/dist/DropdownMenu/DropdownMenuRadioItem.js +0 -178
- package/dist/DropdownMenu/menuItemRoles.d.ts +0 -13
- package/dist/DropdownMenu/menuItemRoles.d.ts.map +0 -1
- package/dist/DropdownMenu/menuItemRoles.js +0 -15
- package/src/DropdownMenu/DropdownMenuCheckboxItem.doc.mjs +0 -95
- package/src/DropdownMenu/DropdownMenuCheckboxItem.tsx +0 -237
- package/src/DropdownMenu/DropdownMenuRadioGroup.doc.mjs +0 -80
- package/src/DropdownMenu/DropdownMenuRadioGroup.tsx +0 -119
- package/src/DropdownMenu/DropdownMenuRadioItem.doc.mjs +0 -80
- package/src/DropdownMenu/DropdownMenuRadioItem.tsx +0 -232
- package/src/DropdownMenu/DropdownMenuSelectable.test.tsx +0 -163
- package/src/DropdownMenu/menuItemRoles.ts +0 -22
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
'use client';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @file DropdownMenuRadioItem.tsx
|
|
7
|
-
* @input React, stylex, Item + Icon + DropdownMenu context + tokens from core
|
|
8
|
-
* @output DropdownMenuRadioItem — a single option in a radio group.
|
|
9
|
-
* @position Sub-component; must be used inside a DropdownMenuRadioGroup.
|
|
10
|
-
*
|
|
11
|
-
* A menu item representing one option in a single-select group
|
|
12
|
-
* (role="menuitemradio"). The row owns the role and aria-checked; there is no
|
|
13
|
-
* nested native <input> (per the WAI-ARIA menuitemradio pattern). Selection
|
|
14
|
-
* state + onChange come from DropdownMenuRadioGroupContext. Keyboard nav +
|
|
15
|
-
* Enter/Space activation come from the parent DropdownMenu.
|
|
16
|
-
*
|
|
17
|
-
* The round radio visual (circle + center dot) is decorative (aria-hidden) —
|
|
18
|
-
* the row owns the checked state. Its size is derived from the menu's item size
|
|
19
|
-
* and it swaps to the inline-end of the row on coarse-pointer (touch) devices
|
|
20
|
-
* via CSS `order`. The dot is a shaped element, not an icon (a filled circle
|
|
21
|
-
* has no registry glyph).
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import {useCallback, type ReactNode} from 'react';
|
|
25
|
-
import * as stylex from '@stylexjs/stylex';
|
|
26
|
-
import {renderIconSlot, type IconType} from '../Icon';
|
|
27
|
-
import {Item} from '../Item';
|
|
28
|
-
import {useDropdownMenuContext} from './DropdownMenuContext';
|
|
29
|
-
import {
|
|
30
|
-
colorVars,
|
|
31
|
-
spacingVars,
|
|
32
|
-
durationVars,
|
|
33
|
-
easeVars,
|
|
34
|
-
borderVars,
|
|
35
|
-
} from '../theme/tokens.stylex';
|
|
36
|
-
import {mergeProps, themeProps} from '../utils';
|
|
37
|
-
import type {BaseProps} from '../BaseProps';
|
|
38
|
-
import {useDropdownMenuRadioGroupContext} from './DropdownMenuContext';
|
|
39
|
-
|
|
40
|
-
const styles = stylex.create({
|
|
41
|
-
root: {
|
|
42
|
-
width: '100%',
|
|
43
|
-
borderRadius: `max(0px, calc(var(--_dropdown-menu-radius, ${spacingVars['--spacing-2']}) - var(--_dropdown-menu-padding, ${spacingVars['--spacing-1']})))`,
|
|
44
|
-
color: colorVars['--color-text-primary'],
|
|
45
|
-
backgroundColor: {
|
|
46
|
-
default: 'transparent',
|
|
47
|
-
':focus': colorVars['--color-overlay-hover'],
|
|
48
|
-
':hover': colorVars['--color-overlay-hover'],
|
|
49
|
-
},
|
|
50
|
-
cursor: 'pointer',
|
|
51
|
-
outline: 'none',
|
|
52
|
-
},
|
|
53
|
-
disabled: {
|
|
54
|
-
opacity: 0.5,
|
|
55
|
-
cursor: 'not-allowed',
|
|
56
|
-
},
|
|
57
|
-
// Rendered in Item's `marker` slot as a raw flex child. On touch it moves to
|
|
58
|
-
// the inline-end of the row via `order`.
|
|
59
|
-
circle: {
|
|
60
|
-
display: 'flex',
|
|
61
|
-
alignItems: 'center',
|
|
62
|
-
justifyContent: 'center',
|
|
63
|
-
flexShrink: 0,
|
|
64
|
-
boxSizing: 'border-box',
|
|
65
|
-
borderWidth: borderVars['--border-width'],
|
|
66
|
-
borderStyle: 'solid',
|
|
67
|
-
borderRadius: '50%',
|
|
68
|
-
transitionProperty: 'background-color, border-color',
|
|
69
|
-
transitionDuration: {
|
|
70
|
-
default: durationVars['--duration-fast'],
|
|
71
|
-
'@media (prefers-reduced-motion: reduce)': '0s',
|
|
72
|
-
},
|
|
73
|
-
transitionTimingFunction: easeVars['--ease-standard'],
|
|
74
|
-
order: {
|
|
75
|
-
default: 0,
|
|
76
|
-
'@media (pointer: coarse)': 1,
|
|
77
|
-
},
|
|
78
|
-
marginInlineStart: {
|
|
79
|
-
default: 0,
|
|
80
|
-
'@media (pointer: coarse)': 'auto',
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
unchecked: {
|
|
84
|
-
borderColor: colorVars['--color-border-emphasized'],
|
|
85
|
-
backgroundColor: colorVars['--color-background-surface'],
|
|
86
|
-
},
|
|
87
|
-
checked: {
|
|
88
|
-
borderColor: colorVars['--color-accent'],
|
|
89
|
-
backgroundColor: colorVars['--color-accent'],
|
|
90
|
-
},
|
|
91
|
-
dot: {
|
|
92
|
-
borderRadius: '50%',
|
|
93
|
-
backgroundColor: colorVars['--color-on-accent'],
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
const circleSizeStyles = stylex.create({
|
|
98
|
-
sm: {width: 18, height: 18},
|
|
99
|
-
md: {width: 22, height: 22},
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
const dotSizeStyles = stylex.create({
|
|
103
|
-
sm: {width: 6, height: 6},
|
|
104
|
-
md: {width: 8, height: 8},
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
export interface DropdownMenuRadioItemProps extends Omit<
|
|
108
|
-
BaseProps,
|
|
109
|
-
'role' | 'aria-checked' | 'tabIndex'
|
|
110
|
-
> {
|
|
111
|
-
/**
|
|
112
|
-
* The value this item represents within its group. The group's `value`
|
|
113
|
-
* matches against this to determine the checked state.
|
|
114
|
-
*/
|
|
115
|
-
value: string;
|
|
116
|
-
/**
|
|
117
|
-
* Primary label text identifying the option.
|
|
118
|
-
*/
|
|
119
|
-
label: ReactNode;
|
|
120
|
-
/**
|
|
121
|
-
* Secondary description text displayed below the label.
|
|
122
|
-
*/
|
|
123
|
-
description?: ReactNode;
|
|
124
|
-
/**
|
|
125
|
-
* Icon to display before the label. Accepts a semantic icon name (see
|
|
126
|
-
* `npx astryx docs icons`) or a rendered node.
|
|
127
|
-
*/
|
|
128
|
-
icon?: ReactNode | IconType;
|
|
129
|
-
/**
|
|
130
|
-
* Whether this individual radio item is disabled. Disabled items stay
|
|
131
|
-
* focusable (via `aria-disabled`) so they remain discoverable by keyboard
|
|
132
|
-
* and assistive technology, but selection is blocked.
|
|
133
|
-
* @default false
|
|
134
|
-
*/
|
|
135
|
-
isDisabled?: boolean;
|
|
136
|
-
/**
|
|
137
|
-
* Content to render after the label and description, such as a badge or
|
|
138
|
-
* metadata.
|
|
139
|
-
*/
|
|
140
|
-
endContent?: ReactNode;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* A single option in a DropdownMenuRadioGroup (role="menuitemradio").
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```
|
|
148
|
-
* <DropdownMenuRadioGroup value={sort} onChange={setSort} aria-label="Sort by">
|
|
149
|
-
* <DropdownMenuRadioItem value="newest" label="Newest" />
|
|
150
|
-
* <DropdownMenuRadioItem value="oldest" label="Oldest" icon="clock" />
|
|
151
|
-
* </DropdownMenuRadioGroup>
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
export function DropdownMenuRadioItem({
|
|
155
|
-
value,
|
|
156
|
-
label,
|
|
157
|
-
description,
|
|
158
|
-
icon,
|
|
159
|
-
isDisabled = false,
|
|
160
|
-
endContent,
|
|
161
|
-
xstyle,
|
|
162
|
-
className,
|
|
163
|
-
style,
|
|
164
|
-
...rest
|
|
165
|
-
}: DropdownMenuRadioItemProps) {
|
|
166
|
-
const menuCtx = useDropdownMenuContext();
|
|
167
|
-
const groupCtx = useDropdownMenuRadioGroupContext();
|
|
168
|
-
if (!groupCtx) {
|
|
169
|
-
throw new Error(
|
|
170
|
-
'DropdownMenuRadioItem must be used within a DropdownMenuRadioGroup',
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
const menuSize = menuCtx?.menuSize ?? 'md';
|
|
174
|
-
const controlSize = menuSize === 'sm' ? 'sm' : 'md';
|
|
175
|
-
const isChecked = groupCtx.value === value;
|
|
176
|
-
|
|
177
|
-
const handleClick = useCallback(() => {
|
|
178
|
-
if (isDisabled) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
groupCtx.onChange(value);
|
|
182
|
-
if (groupCtx.hasCloseOnSelect) {
|
|
183
|
-
menuCtx?.closeMenu();
|
|
184
|
-
}
|
|
185
|
-
}, [isDisabled, groupCtx, value, menuCtx]);
|
|
186
|
-
|
|
187
|
-
return (
|
|
188
|
-
<Item
|
|
189
|
-
{...rest}
|
|
190
|
-
role="menuitemradio"
|
|
191
|
-
aria-checked={isChecked}
|
|
192
|
-
tabIndex={isDisabled ? undefined : -1}
|
|
193
|
-
marker={
|
|
194
|
-
<span
|
|
195
|
-
aria-hidden="true"
|
|
196
|
-
{...mergeProps(
|
|
197
|
-
themeProps('dropdown-menu-radio', {
|
|
198
|
-
size: controlSize,
|
|
199
|
-
checked: isChecked ? 'checked' : null,
|
|
200
|
-
disabled: isDisabled ? 'disabled' : null,
|
|
201
|
-
}),
|
|
202
|
-
stylex.props(
|
|
203
|
-
styles.circle,
|
|
204
|
-
circleSizeStyles[controlSize],
|
|
205
|
-
isChecked ? styles.checked : styles.unchecked,
|
|
206
|
-
),
|
|
207
|
-
)}>
|
|
208
|
-
{isChecked && (
|
|
209
|
-
<span {...stylex.props(styles.dot, dotSizeStyles[controlSize])} />
|
|
210
|
-
)}
|
|
211
|
-
</span>
|
|
212
|
-
}
|
|
213
|
-
startContent={
|
|
214
|
-
icon
|
|
215
|
-
? renderIconSlot(icon, {size: 'sm', color: 'secondary'})
|
|
216
|
-
: undefined
|
|
217
|
-
}
|
|
218
|
-
label={label}
|
|
219
|
-
description={description}
|
|
220
|
-
endContent={endContent}
|
|
221
|
-
onClick={handleClick}
|
|
222
|
-
isDisabled={isDisabled}
|
|
223
|
-
xstyle={[styles.root, isDisabled && styles.disabled, xstyle]}
|
|
224
|
-
{...mergeProps(themeProps('dropdown-menu-item', {size: menuSize}), {
|
|
225
|
-
className,
|
|
226
|
-
style,
|
|
227
|
-
})}
|
|
228
|
-
/>
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
DropdownMenuRadioItem.displayName = 'DropdownMenuRadioItem';
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file DropdownMenuSelectable.test.tsx
|
|
5
|
-
* @input vitest, @testing-library/react, DropdownMenu + selectable items
|
|
6
|
-
* @output Unit tests for DropdownMenuCheckboxItem / RadioGroup / RadioItem (#3829)
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import {describe, it, expect, vi, beforeEach} from 'vitest';
|
|
10
|
-
import {render, screen} from '@testing-library/react';
|
|
11
|
-
import userEvent from '@testing-library/user-event';
|
|
12
|
-
import {DropdownMenu} from './DropdownMenu';
|
|
13
|
-
import {DropdownMenuCheckboxItem} from './DropdownMenuCheckboxItem';
|
|
14
|
-
import {DropdownMenuRadioGroup} from './DropdownMenuRadioGroup';
|
|
15
|
-
import {DropdownMenuRadioItem} from './DropdownMenuRadioItem';
|
|
16
|
-
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
HTMLElement.prototype.showPopover = vi.fn(function (this: HTMLElement) {
|
|
19
|
-
this.setAttribute('popover-open', '');
|
|
20
|
-
const event = new Event('toggle', {bubbles: false});
|
|
21
|
-
Object.defineProperty(event, 'newState', {value: 'open'});
|
|
22
|
-
this.dispatchEvent(event);
|
|
23
|
-
});
|
|
24
|
-
HTMLElement.prototype.hidePopover = vi.fn(function (this: HTMLElement) {
|
|
25
|
-
this.removeAttribute('popover-open');
|
|
26
|
-
const event = new Event('toggle', {bubbles: false});
|
|
27
|
-
Object.defineProperty(event, 'newState', {value: 'closed'});
|
|
28
|
-
this.dispatchEvent(event);
|
|
29
|
-
});
|
|
30
|
-
const originalMatches = HTMLElement.prototype.matches;
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
-
(HTMLElement.prototype as any).matches = function (
|
|
33
|
-
selector: string,
|
|
34
|
-
): boolean {
|
|
35
|
-
if (selector === ':popover-open') {
|
|
36
|
-
return this.hasAttribute('popover-open');
|
|
37
|
-
}
|
|
38
|
-
return originalMatches.call(this, selector);
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('DropdownMenuCheckboxItem', () => {
|
|
43
|
-
it('renders role menuitemcheckbox and reflects checked state', async () => {
|
|
44
|
-
const user = userEvent.setup();
|
|
45
|
-
render(
|
|
46
|
-
<DropdownMenu button={{label: 'View'}}>
|
|
47
|
-
<DropdownMenuCheckboxItem label="Show archived" value={true} />
|
|
48
|
-
</DropdownMenu>,
|
|
49
|
-
);
|
|
50
|
-
await user.click(screen.getByRole('button', {name: /View/}));
|
|
51
|
-
expect(
|
|
52
|
-
screen.getByRole('menuitemcheckbox', {
|
|
53
|
-
name: /Show archived/,
|
|
54
|
-
hidden: true,
|
|
55
|
-
}),
|
|
56
|
-
).toHaveAttribute('aria-checked', 'true');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('calls onChange with the toggled value on click', async () => {
|
|
60
|
-
const user = userEvent.setup();
|
|
61
|
-
const onChangeSpy = vi.fn();
|
|
62
|
-
render(
|
|
63
|
-
<DropdownMenu button={{label: 'View'}}>
|
|
64
|
-
<DropdownMenuCheckboxItem
|
|
65
|
-
label="Show archived"
|
|
66
|
-
value={false}
|
|
67
|
-
onChange={onChangeSpy}
|
|
68
|
-
/>
|
|
69
|
-
</DropdownMenu>,
|
|
70
|
-
);
|
|
71
|
-
await user.click(screen.getByRole('button', {name: /View/}));
|
|
72
|
-
await user.click(
|
|
73
|
-
screen.getByRole('menuitemcheckbox', {
|
|
74
|
-
name: /Show archived/,
|
|
75
|
-
hidden: true,
|
|
76
|
-
}),
|
|
77
|
-
);
|
|
78
|
-
expect(onChangeSpy).toHaveBeenCalledWith(true);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('does not toggle when disabled', async () => {
|
|
82
|
-
const user = userEvent.setup();
|
|
83
|
-
const onChangeSpy = vi.fn();
|
|
84
|
-
render(
|
|
85
|
-
<DropdownMenu button={{label: 'View'}}>
|
|
86
|
-
<DropdownMenuCheckboxItem
|
|
87
|
-
label="Show archived"
|
|
88
|
-
value={false}
|
|
89
|
-
onChange={onChangeSpy}
|
|
90
|
-
isDisabled
|
|
91
|
-
/>
|
|
92
|
-
</DropdownMenu>,
|
|
93
|
-
);
|
|
94
|
-
await user.click(screen.getByRole('button', {name: /View/}));
|
|
95
|
-
const item = screen.getByRole('menuitemcheckbox', {
|
|
96
|
-
name: /Show archived/,
|
|
97
|
-
hidden: true,
|
|
98
|
-
});
|
|
99
|
-
expect(item).toHaveAttribute('aria-disabled', 'true');
|
|
100
|
-
await user.click(item);
|
|
101
|
-
expect(onChangeSpy).not.toHaveBeenCalled();
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe('DropdownMenuRadioGroup / RadioItem', () => {
|
|
106
|
-
it('renders a named group with radios reflecting the selected value', async () => {
|
|
107
|
-
const user = userEvent.setup();
|
|
108
|
-
render(
|
|
109
|
-
<DropdownMenu button={{label: 'Sort'}}>
|
|
110
|
-
<DropdownMenuRadioGroup
|
|
111
|
-
value="newest"
|
|
112
|
-
onChange={() => {}}
|
|
113
|
-
aria-label="Sort by">
|
|
114
|
-
<DropdownMenuRadioItem value="newest" label="Newest" />
|
|
115
|
-
<DropdownMenuRadioItem value="oldest" label="Oldest" />
|
|
116
|
-
</DropdownMenuRadioGroup>
|
|
117
|
-
</DropdownMenu>,
|
|
118
|
-
);
|
|
119
|
-
await user.click(screen.getByRole('button', {name: /Sort/}));
|
|
120
|
-
expect(
|
|
121
|
-
screen.getByRole('menuitemradio', {name: 'Newest', hidden: true}),
|
|
122
|
-
).toHaveAttribute('aria-checked', 'true');
|
|
123
|
-
expect(
|
|
124
|
-
screen.getByRole('menuitemradio', {name: 'Oldest', hidden: true}),
|
|
125
|
-
).toHaveAttribute('aria-checked', 'false');
|
|
126
|
-
expect(
|
|
127
|
-
screen.getByRole('group', {name: 'Sort by', hidden: true}),
|
|
128
|
-
).toBeInTheDocument();
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('calls onChange with the selected value', async () => {
|
|
132
|
-
const user = userEvent.setup();
|
|
133
|
-
const onChange = vi.fn();
|
|
134
|
-
render(
|
|
135
|
-
<DropdownMenu button={{label: 'Sort'}}>
|
|
136
|
-
<DropdownMenuRadioGroup
|
|
137
|
-
value="newest"
|
|
138
|
-
onChange={onChange}
|
|
139
|
-
aria-label="Sort by">
|
|
140
|
-
<DropdownMenuRadioItem value="newest" label="Newest" />
|
|
141
|
-
<DropdownMenuRadioItem value="oldest" label="Oldest" />
|
|
142
|
-
</DropdownMenuRadioGroup>
|
|
143
|
-
</DropdownMenu>,
|
|
144
|
-
);
|
|
145
|
-
await user.click(screen.getByRole('button', {name: /Sort/}));
|
|
146
|
-
await user.click(
|
|
147
|
-
screen.getByRole('menuitemradio', {name: 'Oldest', hidden: true}),
|
|
148
|
-
);
|
|
149
|
-
expect(onChange).toHaveBeenCalledWith('oldest');
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('throws when a radio item is used outside a group', () => {
|
|
153
|
-
const spy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
154
|
-
expect(() =>
|
|
155
|
-
render(
|
|
156
|
-
<DropdownMenu button={{label: 'Sort'}}>
|
|
157
|
-
<DropdownMenuRadioItem value="x" label="X" />
|
|
158
|
-
</DropdownMenu>,
|
|
159
|
-
),
|
|
160
|
-
).toThrow(/DropdownMenuRadioGroup/);
|
|
161
|
-
spy.mockRestore();
|
|
162
|
-
});
|
|
163
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file menuItemRoles.ts
|
|
5
|
-
* @output Shared menu-item role set + focus selector.
|
|
6
|
-
* @position Internal; used by DropdownMenu and ContextMenu so their
|
|
7
|
-
* roving-focus, typeahead, and Enter/Space activation stay in sync.
|
|
8
|
-
*
|
|
9
|
-
* Includes the selectable items (menuitemradio/menuitemcheckbox) alongside
|
|
10
|
-
* plain menuitem so checkbox/radio rows are reachable by arrow keys, typeahead,
|
|
11
|
-
* and Enter/Space — not just role="menuitem".
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
export const MENU_ITEM_ROLES: ReadonlySet<string> = new Set([
|
|
15
|
-
'menuitem',
|
|
16
|
-
'menuitemradio',
|
|
17
|
-
'menuitemcheckbox',
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
export const MENU_ITEM_SELECTOR: string = [...MENU_ITEM_ROLES]
|
|
21
|
-
.map(role => `[role="${role}"]:not([aria-disabled="true"])`)
|
|
22
|
-
.join(',');
|