@@ -25,15 +25,15 @@ export function useMenuProps(id) {
25
25
* MenubarTrigger
26
26
* -----------------------------------------------------------------------------------------------*/
27
27
28
- function MenubarTrigger ( { id, title, ...props } ) {
28
+ function MenubarTrigger ( { id, title, role , hasPopup , ...props } ) {
29
29
const { isOpen, handlers } = useMenuProps ( id ) ;
30
30
31
31
return (
32
32
< button
33
33
{ ...handlers }
34
34
{ ...props }
35
- role = "menuitem"
36
- aria-haspopup = "menu"
35
+ role = { role }
36
+ aria-haspopup = { hasPopup }
37
37
aria-expanded = { isOpen }
38
38
>
39
39
< span className = "nav__item-header" > { title } </ span >
@@ -48,16 +48,23 @@ function MenubarTrigger({ id, title, ...props }) {
48
48
49
49
MenubarTrigger . propTypes = {
50
50
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'
52
59
} ;
53
60
54
61
/* -------------------------------------------------------------------------------------------------
55
62
* MenubarList
56
63
* -----------------------------------------------------------------------------------------------*/
57
64
58
- function MenubarList ( { id, children } ) {
65
+ function MenubarList ( { id, children, role , ... props } ) {
59
66
return (
60
- < ul className = "nav__dropdown" role = "menu" >
67
+ < ul className = "nav__dropdown" role = { role } { ... props } >
61
68
< ParentMenuContext . Provider value = { id } >
62
69
{ children }
63
70
</ ParentMenuContext . Provider >
@@ -67,36 +74,62 @@ function MenubarList({ id, children }) {
67
74
68
75
MenubarList . propTypes = {
69
76
id : PropTypes . string . isRequired ,
70
- children : PropTypes . node
77
+ children : PropTypes . node ,
78
+ role : PropTypes . oneOf ( [ 'menu' , 'listbox' ] )
71
79
} ;
72
80
73
81
MenubarList . defaultProps = {
74
- children : null
82
+ children : null ,
83
+ role : 'menu'
75
84
} ;
76
85
77
86
/* -------------------------------------------------------------------------------------------------
78
87
* MenubarSubmenu
79
88
* -----------------------------------------------------------------------------------------------*/
80
89
81
- function MenubarSubmenu ( { id, title, children } ) {
90
+ function MenubarSubmenu ( {
91
+ id,
92
+ title,
93
+ children,
94
+ triggerRole : customTriggerRole ,
95
+ listRole : customListRole ,
96
+ ...props
97
+ } ) {
82
98
const { isOpen } = useMenuProps ( id ) ;
83
99
100
+ const triggerRole = customTriggerRole || 'menuitem' ;
101
+ const listRole = customListRole || 'menu' ;
102
+
103
+ const hasPopup = listRole === 'listbox' ? 'listbox' : 'menu' ;
104
+
84
105
return (
85
106
< 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 >
88
117
</ li >
89
118
) ;
90
119
}
91
120
92
121
MenubarSubmenu . propTypes = {
93
122
id : PropTypes . string . isRequired ,
94
123
title : PropTypes . node . isRequired ,
95
- children : PropTypes . node
124
+ children : PropTypes . node ,
125
+ triggerRole : PropTypes . string ,
126
+ listRole : PropTypes . string
96
127
} ;
97
128
98
129
MenubarSubmenu . defaultProps = {
99
- children : null
130
+ children : null ,
131
+ triggerRole : 'menuitem' ,
132
+ listRole : 'menu'
100
133
} ;
101
134
102
135
export default MenubarSubmenu ;
0 commit comments