File tree Expand file tree Collapse file tree 4 files changed +30
-4
lines changed Expand file tree Collapse file tree 4 files changed +30
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @leafygreen-ui/menu ' : patch
3
+ ---
4
+
5
+ Improves MenuProps types to extend ` React.ComponentProps<'ul'> `
Original file line number Diff line number Diff line change @@ -105,7 +105,6 @@ describe('packages/menu', () => {
105
105
test ( 'respects custom testid' , async ( ) => {
106
106
const customTestId = 'custom-menu-test-id' ;
107
107
const { getByTestId } = renderMenu ( {
108
- // @ts -expect-error - data-testid is not a valid prop for MenuProps FIXME: LG-5477
109
108
'data-testid' : customTestId ,
110
109
initialOpen : true ,
111
110
} ) ;
@@ -639,4 +638,16 @@ describe('packages/menu', () => {
639
638
} ) ;
640
639
} ) ;
641
640
} ) ;
641
+
642
+ // eslint-disable-next-line jest/no-disabled-tests
643
+ describe . skip ( 'Types work as expected' , ( ) => {
644
+ test ( 'Types work as expected' , ( ) => {
645
+ render (
646
+ < Menu data-testid = "menu" >
647
+ < MenuItem > Item</ MenuItem >
648
+ < MenuItem > Item</ MenuItem >
649
+ </ Menu > ,
650
+ ) ;
651
+ } ) ;
652
+ } ) ;
642
653
} ) ;
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ export const Menu = React.forwardRef<HTMLDivElement, MenuProps>(function Menu(
70
70
darkMode : darkModeProp ,
71
71
renderDarkMenu = true ,
72
72
'data-lgid' : dataLgId ,
73
+ 'data-testid' : dataTestId ,
73
74
children,
74
75
className,
75
76
refEl,
@@ -81,6 +82,8 @@ export const Menu = React.forwardRef<HTMLDivElement, MenuProps>(function Menu(
81
82
portalRef,
82
83
scrollContainer,
83
84
popoverZIndex,
85
+ // Extract only ul-appropriate props from rest
86
+ id,
84
87
...rest
85
88
} : MenuProps ,
86
89
forwardRef ,
@@ -264,12 +267,13 @@ export const Menu = React.forwardRef<HTMLDivElement, MenuProps>(function Menu(
264
267
{ /* Need to stop propagation, otherwise Menu will closed automatically when clicked */ }
265
268
{ /* eslint-disable-next-line jsx-a11y/click-events-have-key-events*/ }
266
269
< ul
267
- data-testid = { lgIds . root }
268
- { ... rest }
270
+ data-testid = { dataTestId || lgIds . root }
271
+ id = { id }
269
272
data-lgid = { lgIds . root }
270
273
className = { scrollContainerStyle }
271
274
role = "menu"
272
275
onClick = { e => e . stopPropagation ( ) }
276
+ { ...rest }
273
277
>
274
278
{ children }
275
279
</ ul >
Original file line number Diff line number Diff line change @@ -20,14 +20,20 @@ export const MenuVariant = {
20
20
export type MenuVariant = ( typeof MenuVariant ) [ keyof typeof MenuVariant ] ;
21
21
22
22
export interface MenuProps
23
- extends Omit < PopoverProps , 'active' | 'dismissMode' | 'onToggle' > ,
23
+ extends Omit < React . ComponentPropsWithoutRef < 'ul' > , 'onClick' > ,
24
+ Omit < PopoverProps , 'active' | 'dismissMode' | 'onToggle' > ,
24
25
LgIdProps {
25
26
/**
26
27
* The menu items, or submenus
27
28
* @type `<MenuItem />` | `<SubMenu />` | `<MenuGroup />` | `<MenuSeparator />`
28
29
*/
29
30
children : ReactNode ;
30
31
32
+ /**
33
+ * Test id for the menu element
34
+ */
35
+ 'data-testid' ?: string ;
36
+
31
37
/**
32
38
* A slot for the element used to trigger the Menu. Passing a trigger allows
33
39
* Menu to control opening and closing itself internally.
You can’t perform that action at this time.
0 commit comments