@@ -25,15 +25,15 @@ export function useMenuProps(id) {
2525 * MenubarTrigger
2626 * -----------------------------------------------------------------------------------------------*/
2727
28- function MenubarTrigger ( { id, title, ...props } ) {
28+ function MenubarTrigger ( { id, title, role , hasPopup , ...props } ) {
2929 const { isOpen, handlers } = useMenuProps ( id ) ;
3030
3131 return (
3232 < button
3333 { ...handlers }
3434 { ...props }
35- role = "menuitem"
36- aria-haspopup = "menu"
35+ role = { role }
36+ aria-haspopup = { hasPopup }
3737 aria-expanded = { isOpen }
3838 >
3939 < span className = "nav__item-header" > { title } </ span >
@@ -48,16 +48,23 @@ function MenubarTrigger({ id, title, ...props }) {
4848
4949MenubarTrigger . propTypes = {
5050 id : PropTypes . string . isRequired ,
51- title : PropTypes . node . isRequired
51+ title : PropTypes . node . isRequired ,
52+ role : PropTypes . string ,
53+ hasPopup : PropTypes . oneOf ( [ 'menu' , 'listbox' , 'true' ] )
54+ } ;
55+
56+ MenubarTrigger . defaultProps = {
57+ role : 'menuitem' ,
58+ hasPopup : 'menu'
5259} ;
5360
5461/* -------------------------------------------------------------------------------------------------
5562 * MenubarList
5663 * -----------------------------------------------------------------------------------------------*/
5764
58- function MenubarList ( { id, children } ) {
65+ function MenubarList ( { id, children, role , ... props } ) {
5966 return (
60- < ul className = "nav__dropdown" role = "menu" >
67+ < ul className = "nav__dropdown" role = { role } { ... props } >
6168 < ParentMenuContext . Provider value = { id } >
6269 { children }
6370 </ ParentMenuContext . Provider >
@@ -67,36 +74,62 @@ function MenubarList({ id, children }) {
6774
6875MenubarList . propTypes = {
6976 id : PropTypes . string . isRequired ,
70- children : PropTypes . node
77+ children : PropTypes . node ,
78+ role : PropTypes . oneOf ( [ 'menu' , 'listbox' ] )
7179} ;
7280
7381MenubarList . defaultProps = {
74- children : null
82+ children : null ,
83+ role : 'menu'
7584} ;
7685
7786/* -------------------------------------------------------------------------------------------------
7887 * MenubarSubmenu
7988 * -----------------------------------------------------------------------------------------------*/
8089
81- function MenubarSubmenu ( { id, title, children } ) {
90+ function MenubarSubmenu ( {
91+ id,
92+ title,
93+ children,
94+ triggerRole : customTriggerRole ,
95+ listRole : customListRole ,
96+ ...props
97+ } ) {
8298 const { isOpen } = useMenuProps ( id ) ;
8399
100+ const triggerRole = customTriggerRole || 'menuitem' ;
101+ const listRole = customListRole || 'menu' ;
102+
103+ const hasPopup = listRole === 'listbox' ? 'listbox' : 'menu' ;
104+
84105 return (
85106 < li className = { classNames ( 'nav__item' , isOpen && 'nav__item--open' ) } >
86- < MenubarTrigger id = { id } title = { title } />
87- < MenubarList id = { id } > { children } </ MenubarList >
107+ < MenubarTrigger
108+ id = { id }
109+ title = { title }
110+ role = { triggerRole }
111+ hasPopup = { hasPopup }
112+ { ...props }
113+ />
114+ < MenubarList id = { id } role = { listRole } >
115+ { children }
116+ </ MenubarList >
88117 </ li >
89118 ) ;
90119}
91120
92121MenubarSubmenu . propTypes = {
93122 id : PropTypes . string . isRequired ,
94123 title : PropTypes . node . isRequired ,
95- children : PropTypes . node
124+ children : PropTypes . node ,
125+ triggerRole : PropTypes . string ,
126+ listRole : PropTypes . string
96127} ;
97128
98129MenubarSubmenu . defaultProps = {
99- children : null
130+ children : null ,
131+ triggerRole : 'menuitem' ,
132+ listRole : 'menu'
100133} ;
101134
102135export default MenubarSubmenu ;
0 commit comments