File tree Expand file tree Collapse file tree 4 files changed +41
-4
lines changed
Expand file tree Collapse file tree 4 files changed +41
-4
lines changed Original file line number Diff line number Diff line change 1- import React , { forwardRef } from "react" ;
1+ import React , { CSSProperties , forwardRef } from "react" ;
22import { useIcon } from "@react-md/icon" ;
33import { RenderConditionalPortalProps } from "@react-md/portal" ;
44
@@ -38,6 +38,16 @@ export interface BaseDropdownMenuProps
3838 */
3939 menuLabelledBy ?: string ;
4040
41+ /**
42+ * An optional style object to pass to the `menuRenderer`/`Menu` component.
43+ */
44+ menuStyle ?: CSSProperties ;
45+
46+ /**
47+ * An optional className to pass to the `menuRenderer`/`Menu` component.
48+ */
49+ menuClassName ?: string ;
50+
4151 /**
4252 * A custom menu renderer to use. This defaults to just rendering the `Menu`
4353 * component with the base required props and a generated id from the button
@@ -82,6 +92,8 @@ export const DropdownMenu = forwardRef<HTMLButtonElement, DropdownMenuProps>(
8292 anchor,
8393 menuLabel,
8494 menuLabelledBy,
95+ menuStyle,
96+ menuClassName,
8597 menuRenderer = defaultMenuRenderer ,
8698 items,
8799 itemRenderer = defaultMenuItemRenderer ,
@@ -143,6 +155,8 @@ export const DropdownMenu = forwardRef<HTMLButtonElement, DropdownMenuProps>(
143155 "aria-labelledby" : labelledBy as string ,
144156 id : `${ id } -menu` ,
145157 controlId : id ,
158+ style : menuStyle ,
159+ className : menuClassName ,
146160 anchor,
147161 positionOptions,
148162 closeOnScroll,
Original file line number Diff line number Diff line change @@ -150,6 +150,7 @@ export const Menu = forwardRef<HTMLDivElement, MenuProps>(function Menu(
150150 role = "menu" ,
151151 tabIndex = - 1 ,
152152 controlId,
153+ style : propStyle ,
153154 className,
154155 visible,
155156 onRequestClose,
@@ -263,7 +264,7 @@ export const Menu = forwardRef<HTMLDivElement, MenuProps>(function Menu(
263264 ref = { ref }
264265 role = { role }
265266 tabIndex = { tabIndex }
266- style = { style }
267+ style = { { ... propStyle , ... style } }
267268 className = { cn ( block ( { horizontal } ) , className ) }
268269 onClick = { onClick }
269270 onKeyDown = { onKeyDown }
Original file line number Diff line number Diff line change 11/* eslint-disable react/jsx-key */
2- import React from "react" ;
2+ import React , { CSSProperties } from "react" ;
33import { fireEvent , render } from "@testing-library/react" ;
44
55import { DropdownMenu } from "../DropdownMenu" ;
@@ -56,4 +56,24 @@ describe("DropdownMenu", () => {
5656 rerender ( < DropdownMenu { ...PROPS } items = { items4 } /> ) ;
5757 expect ( container ) . toMatchSnapshot ( ) ;
5858 } ) ;
59+
60+ it ( "should pass the menuStyle and menuClassName props to the menu correctly" , ( ) => {
61+ const menuStyle : CSSProperties = { color : "red" } ;
62+ const menuClassName = "my-custom-class-name" ;
63+ const { getByRole } = render (
64+ < DropdownMenu
65+ { ...PROPS }
66+ menuStyle = { menuStyle }
67+ menuClassName = { menuClassName }
68+ items = { [ "Item 1" , "Item 2" , "Item 3" ] }
69+ />
70+ ) ;
71+
72+ const button = getByRole ( "button" ) ;
73+ fireEvent . click ( button ) ;
74+
75+ const menu = getByRole ( "menu" ) ;
76+ expect ( menu . style . color ) . toBe ( menuStyle . color ) ;
77+ expect ( menu . className ) . toContain ( menuClassName ) ;
78+ } ) ;
5979} ) ;
Original file line number Diff line number Diff line change 1- import React , { ReactElement , ReactNode } from "react" ;
1+ import React , { CSSProperties , ReactElement , ReactNode } from "react" ;
22import { List } from "@react-md/list" ;
33import { RenderConditionalPortalProps } from "@react-md/portal" ;
44import { LabelRequiredForA11y } from "@react-md/utils" ;
@@ -33,6 +33,8 @@ export interface AllInjectedMenuProps
3333 RenderConditionalPortalProps {
3434 "aria-label" ?: string ;
3535 "aria-labelledby" ?: string ;
36+ style ?: CSSProperties ;
37+ className ?: string ;
3638 onClick ?: React . MouseEventHandler < HTMLDivElement > ;
3739 onKeyDown ?: React . KeyboardEventHandler < HTMLDivElement > ;
3840}
You can’t perform that action at this time.
0 commit comments