@@ -106,6 +106,21 @@ export type ActionBarProps = {
106106
107107export type ActionBarIconButtonProps = { disabled ?: boolean } & IconButtonProps
108108
109+ export type ActionBarMenuItem = {
110+ disabled ?: boolean
111+ icon ?: ActionBarIconButtonProps [ 'icon' ]
112+ label : string
113+ onClick ?: ActionListItemProps [ 'onSelect' ]
114+ } & Pick < ActionListItemProps , 'variant' >
115+
116+ export type ActionBarMenuProps = {
117+ /** Accessible label for the menu button */
118+ 'aria-label' : string
119+ /** Icon for the menu button */
120+ icon : ActionBarIconButtonProps [ 'icon' ]
121+ items ?: ActionBarMenuItem [ ]
122+ } & IconButtonProps
123+
109124const MORE_BTN_WIDTH = 32
110125
111126const calculatePossibleItems = (
@@ -488,59 +503,38 @@ export const ActionBarGroup = forwardRef(({children}: React.PropsWithChildren, f
488503 )
489504} )
490505
491- type ActionBarMenuItem = {
492- disabled ?: boolean
493- icon ?: ActionBarIconButtonProps [ 'icon' ]
494- label : string
495- onClick ?: ActionListItemProps [ 'onSelect' ]
496- } & Pick < ActionListItemProps , 'variant' >
497-
498- type ActionBarMenuProps = {
499- /** Accessible label for the menu button */
500- 'aria-label' : string // TODO: Change to label
501- /** Icon for the menu button */
502- icon : ActionBarIconButtonProps [ 'icon' ]
503- items ?: ActionBarMenuItem [ ]
504- }
505-
506- const ActionBarMenuContext = React . createContext < {
507- menuId : string
508- menuVisible : boolean
509- label : string
510- } > ( { menuId : '' , menuVisible : false , label : '' } )
511-
512- export const ActionBarMenu = forwardRef ( ( { 'aria-label' : ariaLabel , icon, items} : ActionBarMenuProps , forwardedRef ) => {
513- const backupRef = useRef < HTMLButtonElement > ( null )
514- const ref = ( forwardedRef ?? backupRef ) as RefObject < HTMLButtonElement >
515- const id = useId ( )
516- const { registerChild, unregisterChild, isVisibleChild} = React . useContext ( ActionBarContext )
506+ export const ActionBarMenu = forwardRef (
507+ ( { 'aria-label' : ariaLabel , icon, items, ...props } : ActionBarMenuProps , forwardedRef ) => {
508+ const backupRef = useRef < HTMLButtonElement > ( null )
509+ const ref = ( forwardedRef ?? backupRef ) as RefObject < HTMLButtonElement >
510+ const id = useId ( )
511+ const { registerChild, unregisterChild, isVisibleChild} = React . useContext ( ActionBarContext )
517512
518- const [ menuOpen , setMenuOpen ] = useState ( false )
513+ const [ menuOpen , setMenuOpen ] = useState ( false )
519514
520- // Like IconButton, we store the width in a ref to ensure that we don't forget about it when not visible
521- // If a child has a groupId, it won't be visible if the group isn't visible, so we don't need to check isVisibleChild here
522- const widthRef = useRef < number > ( )
515+ // Like IconButton, we store the width in a ref to ensure that we don't forget about it when not visible
516+ // If a child has a groupId, it won't be visible if the group isn't visible, so we don't need to check isVisibleChild here
517+ const widthRef = useRef < number > ( )
523518
524- useIsomorphicLayoutEffect ( ( ) => {
525- const width = ref . current ?. getBoundingClientRect ( ) . width
526- if ( width ) widthRef . current = width
519+ useIsomorphicLayoutEffect ( ( ) => {
520+ const width = ref . current ?. getBoundingClientRect ( ) . width
521+ if ( width ) widthRef . current = width
527522
528- if ( ! widthRef . current ) return
523+ if ( ! widthRef . current ) return
529524
530- registerChild ( id , { type : 'menu' , width : widthRef . current , label : ariaLabel , icon, items} )
525+ registerChild ( id , { type : 'menu' , width : widthRef . current , label : ariaLabel , icon, items} )
531526
532- return ( ) => {
533- unregisterChild ( id )
534- }
535- } , [ registerChild , unregisterChild ] )
527+ return ( ) => {
528+ unregisterChild ( id )
529+ }
530+ } , [ registerChild , unregisterChild ] )
536531
537- if ( ! isVisibleChild ( id ) ) return null
532+ if ( ! isVisibleChild ( id ) ) return null
538533
539- return (
540- < ActionBarMenuContext . Provider value = { { menuId : id , menuVisible : isVisibleChild ( id ) , label : ariaLabel } } >
534+ return (
541535 < ActionMenu anchorRef = { ref } open = { menuOpen } onOpenChange = { setMenuOpen } >
542536 < ActionMenu . Anchor >
543- < IconButton variant = "invisible" aria-label = { ariaLabel } icon = { icon } />
537+ < IconButton variant = "invisible" aria-label = { ariaLabel } icon = { icon } { ... props } />
544538 </ ActionMenu . Anchor >
545539 < ActionMenu . Overlay >
546540 < ActionList className = { styles . Menu } >
@@ -553,9 +547,9 @@ export const ActionBarMenu = forwardRef(({'aria-label': ariaLabel, icon, items}:
553547 </ ActionList >
554548 </ ActionMenu . Overlay >
555549 </ ActionMenu >
556- </ ActionBarMenuContext . Provider >
557- )
558- } )
550+ )
551+ } ,
552+ )
559553
560554export const VerticalDivider = ( ) => {
561555 const ref = useRef < HTMLDivElement > ( null )
0 commit comments