@sproutsocial/seeds-react-menu 1.8.3 → 1.8.5
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/.turbo/turbo-build.log +12 -12
- package/CHANGELOG.md +15 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/v2/index.js +4 -0
- package/dist/esm/v2/index.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/v2/index.js +4 -0
- package/dist/v2/index.js.map +1 -1
- package/package.json +3 -3
- package/src/MenuItem/MenuItem.tsx +1 -0
- package/src/MenuItem/__tests__/MenuItem.test.tsx +76 -0
- package/src/v2/Common-V2/Popout.tsx +4 -0
- package/src/v2/Common-V2/PopoutTypes.tsx +17 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sproutsocial/seeds-react-menu",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.5",
|
|
4
4
|
"description": "Seeds React Menu",
|
|
5
5
|
"author": "Sprout Social, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@sproutsocial/seeds-react-icon": "^2.2.4",
|
|
38
38
|
"@sproutsocial/seeds-react-input": "^1.5.4",
|
|
39
39
|
"@sproutsocial/seeds-react-label": "^1.0.13",
|
|
40
|
-
"@sproutsocial/seeds-react-popout": "^2.4.
|
|
40
|
+
"@sproutsocial/seeds-react-popout": "^2.4.25",
|
|
41
41
|
"@sproutsocial/seeds-react-radio": "^1.3.12",
|
|
42
42
|
"@sproutsocial/seeds-react-switch": "^1.2.21",
|
|
43
43
|
"@sproutsocial/seeds-react-system-props": "^3.0.2",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"styled-system": "^5.1.5"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@sproutsocial/seeds-react-tooltip": "^1.1.
|
|
54
|
+
"@sproutsocial/seeds-react-tooltip": "^1.1.7",
|
|
55
55
|
"@sproutsocial/eslint-config-seeds": "*",
|
|
56
56
|
"@sproutsocial/seeds-react-testing-library": "*",
|
|
57
57
|
"@sproutsocial/seeds-testing": "*",
|
|
@@ -59,6 +59,7 @@ const MenuItem = ({
|
|
|
59
59
|
})}
|
|
60
60
|
// use anchor tag if href is provided and button for menuitem
|
|
61
61
|
as={isListbox ? undefined : href ? "a" : "button"}
|
|
62
|
+
type={href ? undefined : "button"}
|
|
62
63
|
href={href}
|
|
63
64
|
children={children}
|
|
64
65
|
// Keyboard nav uses the arrow keys, not tab.
|
|
@@ -321,6 +321,82 @@ const testByType = {
|
|
|
321
321
|
},
|
|
322
322
|
};
|
|
323
323
|
|
|
324
|
+
describe("MenuItem type attribute", () => {
|
|
325
|
+
it('renders with type="button" when used as a menuitem (not listbox)', () => {
|
|
326
|
+
render(
|
|
327
|
+
<ActionMenu menuToggleElement={testMenuToggleElement} isOpen>
|
|
328
|
+
<MenuContent>
|
|
329
|
+
<MenuItem {...menuItemProps} />
|
|
330
|
+
</MenuContent>
|
|
331
|
+
</ActionMenu>
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
const menuItem = screen.getByRole("menuitem");
|
|
335
|
+
expect(menuItem).toHaveAttribute("type", "button");
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it('renders with type="button" when used as a listbox option', () => {
|
|
339
|
+
const testItem = books[0];
|
|
340
|
+
render(
|
|
341
|
+
<TestWithMockedMenu context={{ items: books, isListbox: true }}>
|
|
342
|
+
<MenuItem id={testItem.id}>{testItem.title}</MenuItem>
|
|
343
|
+
</TestWithMockedMenu>
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
const option = screen.getByRole("option");
|
|
347
|
+
expect(option).toHaveAttribute("type", "button");
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it("does not trigger form submission when clicked inside a form", async () => {
|
|
351
|
+
const handleSubmit = jest.fn((e: React.FormEvent) => e.preventDefault());
|
|
352
|
+
|
|
353
|
+
const { user } = render(
|
|
354
|
+
<form onSubmit={handleSubmit}>
|
|
355
|
+
<ActionMenu menuToggleElement={testMenuToggleElement} isOpen>
|
|
356
|
+
<MenuContent>
|
|
357
|
+
<MenuItem {...menuItemProps} />
|
|
358
|
+
</MenuContent>
|
|
359
|
+
</ActionMenu>
|
|
360
|
+
</form>
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
const menuItem = screen.getByRole("menuitem");
|
|
364
|
+
await user
|
|
365
|
+
.setup({ pointerEventsCheck: PointerEventsCheckLevel.Never })
|
|
366
|
+
.click(menuItem);
|
|
367
|
+
|
|
368
|
+
expect(handleSubmit).not.toHaveBeenCalled();
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("does not trigger form submission when listbox option clicked inside a form", async () => {
|
|
372
|
+
const handleSubmit = jest.fn((e: React.FormEvent) => e.preventDefault());
|
|
373
|
+
|
|
374
|
+
const { user } = render(
|
|
375
|
+
<form onSubmit={handleSubmit}>
|
|
376
|
+
<MultiSelectMenu
|
|
377
|
+
menuToggleElement={<MenuToggleButton>Open</MenuToggleButton>}
|
|
378
|
+
defaultIsOpen
|
|
379
|
+
>
|
|
380
|
+
<MenuContent>
|
|
381
|
+
{books.map((book) => (
|
|
382
|
+
<MenuItem key={book.id} id={book.id}>
|
|
383
|
+
{book.title}
|
|
384
|
+
</MenuItem>
|
|
385
|
+
))}
|
|
386
|
+
</MenuContent>
|
|
387
|
+
</MultiSelectMenu>
|
|
388
|
+
</form>
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
const firstOption = screen.getByRole("option", { name: books[0].title });
|
|
392
|
+
await user
|
|
393
|
+
.setup({ pointerEventsCheck: PointerEventsCheckLevel.Never })
|
|
394
|
+
.click(firstOption);
|
|
395
|
+
|
|
396
|
+
expect(handleSubmit).not.toHaveBeenCalled();
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
|
|
324
400
|
describe("MenuItem when isListbox", () => {
|
|
325
401
|
describe("User Behavior", () => {
|
|
326
402
|
describe.each([
|
|
@@ -46,6 +46,8 @@ export function Popout({
|
|
|
46
46
|
onOpenAutoFocus,
|
|
47
47
|
onEscapeKeyDown,
|
|
48
48
|
onCloseAutoFocus,
|
|
49
|
+
onPointerDownOutside,
|
|
50
|
+
onInteractOutside,
|
|
49
51
|
...rest
|
|
50
52
|
}: TypePopoutProps) {
|
|
51
53
|
const [isOpen, setIsOpen] = React.useState(defaultOpen ?? false);
|
|
@@ -90,6 +92,8 @@ export function Popout({
|
|
|
90
92
|
onOpenAutoFocus={onOpenAutoFocus}
|
|
91
93
|
onEscapeKeyDown={onEscapeKeyDown}
|
|
92
94
|
onCloseAutoFocus={onCloseAutoFocus}
|
|
95
|
+
onPointerDownOutside={onPointerDownOutside}
|
|
96
|
+
onInteractOutside={onInteractOutside}
|
|
93
97
|
// This only needs added to Popouts used in Menus
|
|
94
98
|
// those do not need the dialog role which radix applies automatically
|
|
95
99
|
role="presentation"
|
|
@@ -89,4 +89,21 @@ export interface TypePopoutProps
|
|
|
89
89
|
* Can be used to prevent the default focus return behavior or customize it.
|
|
90
90
|
*/
|
|
91
91
|
onCloseAutoFocus?: (event: Event) => void;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Event handler called when a pointer down event occurs outside the popout content.
|
|
95
|
+
* Call `event.preventDefault()` to prevent the default dismiss behavior.
|
|
96
|
+
* Useful when the Popout is nested inside a Radix Dialog (e.g. ModalV2) to
|
|
97
|
+
* avoid conflicts between nested DismissableLayer instances.
|
|
98
|
+
*/
|
|
99
|
+
onPointerDownOutside?: (
|
|
100
|
+
event: CustomEvent<{ originalEvent: PointerEvent }>
|
|
101
|
+
) => void;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Event handler called when an interaction (pointer or focus) occurs outside
|
|
105
|
+
* the popout content. Call `event.preventDefault()` to prevent the popout
|
|
106
|
+
* from closing.
|
|
107
|
+
*/
|
|
108
|
+
onInteractOutside?: (event: CustomEvent<{ originalEvent: Event }>) => void;
|
|
92
109
|
}
|