@sproutsocial/seeds-react-menu 1.8.1 → 1.8.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sproutsocial/seeds-react-menu",
3
- "version": "1.8.1",
3
+ "version": "1.8.4",
4
4
  "description": "Seeds React Menu",
5
5
  "author": "Sprout Social, Inc.",
6
6
  "license": "MIT",
@@ -31,18 +31,18 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@radix-ui/react-popover": "^1.1.2",
34
- "@sproutsocial/seeds-react-box": "^1.1.12",
35
- "@sproutsocial/seeds-react-button": "^1.3.16",
36
- "@sproutsocial/seeds-react-checkbox": "^1.3.20",
37
- "@sproutsocial/seeds-react-icon": "^2.2.2",
38
- "@sproutsocial/seeds-react-input": "^1.5.2",
39
- "@sproutsocial/seeds-react-label": "^1.0.12",
40
- "@sproutsocial/seeds-react-popout": "^2.4.22",
41
- "@sproutsocial/seeds-react-radio": "^1.3.11",
42
- "@sproutsocial/seeds-react-switch": "^1.2.19",
34
+ "@sproutsocial/seeds-react-box": "^1.1.13",
35
+ "@sproutsocial/seeds-react-button": "^1.3.18",
36
+ "@sproutsocial/seeds-react-checkbox": "^1.3.22",
37
+ "@sproutsocial/seeds-react-icon": "^2.2.4",
38
+ "@sproutsocial/seeds-react-input": "^1.5.4",
39
+ "@sproutsocial/seeds-react-label": "^1.0.13",
40
+ "@sproutsocial/seeds-react-popout": "^2.4.24",
41
+ "@sproutsocial/seeds-react-radio": "^1.3.12",
42
+ "@sproutsocial/seeds-react-switch": "^1.2.21",
43
43
  "@sproutsocial/seeds-react-system-props": "^3.0.2",
44
- "@sproutsocial/seeds-react-theme": "^3.5.0",
45
- "@sproutsocial/seeds-react-token-input": "^1.4.23",
44
+ "@sproutsocial/seeds-react-theme": "^3.5.1",
45
+ "@sproutsocial/seeds-react-token-input": "^1.4.25",
46
46
  "@sproutsocial/seeds-react-utilities": "^4.3.0",
47
47
  "@tanstack/react-virtual": "^3.13.12",
48
48
  "downshift": "9.0.4",
@@ -51,7 +51,7 @@
51
51
  "styled-system": "^5.1.5"
52
52
  },
53
53
  "devDependencies": {
54
- "@sproutsocial/seeds-react-tooltip": "^1.1.4",
54
+ "@sproutsocial/seeds-react-tooltip": "^1.1.6",
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([
@@ -22,9 +22,17 @@ import {
22
22
  import { menuPlacementOrigin } from "../MenuRoot";
23
23
  import { testDefaultContext } from "../../menuTestingUtils";
24
24
 
25
- jest.mock("@sproutsocial/seeds-react-portal", () => ({ children }) => (
26
- <div>{children}</div>
27
- ));
25
+ jest.mock("@sproutsocial/seeds-react-portal", () => {
26
+ const Portal = ({ children }) => <div>{children}</div>;
27
+ Portal.DisablePortalToBodyContext = jest
28
+ .requireActual("react")
29
+ .createContext(false);
30
+ return {
31
+ __esModule: true,
32
+ default: Portal,
33
+ DisablePortalToBodyContext: Portal.DisablePortalToBodyContext,
34
+ };
35
+ });
28
36
 
29
37
  const TestComponent = () => {
30
38
  const { isOpen } = useContext(MenuToggleContext);