File tree Expand file tree Collapse file tree 5 files changed +83
-1
lines changed Expand file tree Collapse file tree 5 files changed +83
-1
lines changed Original file line number Diff line number Diff line change @@ -162,7 +162,7 @@ export class MenuItem extends React.Component {
162162 role : 'option' ,
163163 'aria-selected' : props . isSelected ,
164164 } ;
165- } else if ( attrs . role === null ) {
165+ } else if ( props . role === null ) {
166166 // sometimes we want to specify role inside <li/> element
167167 // <li><a role='menuitem'>Link</a></li> would be a good example
168168 delete attrs . role ;
Original file line number Diff line number Diff line change @@ -39,6 +39,27 @@ describe('Menu', () => {
3939 } ) ;
4040 } ) ;
4141
42+ describe ( 'render role listbox' , ( ) => {
43+ function createMenu ( ) {
44+ return (
45+ < Menu
46+ className = "myMenu"
47+ openAnimation = "fade"
48+ role = "listbox"
49+ >
50+ < MenuItem key = "1" role = "option" > 1</ MenuItem >
51+ < MenuItem key = "2" role = "option" > 2</ MenuItem >
52+ < MenuItem key = "3" role = "option" > 3</ MenuItem >
53+ </ Menu >
54+ ) ;
55+ }
56+
57+ it ( `renders menu correctly` , ( ) => {
58+ const wrapper = render ( createMenu ( ) ) ;
59+ expect ( renderToJson ( wrapper ) ) . toMatchSnapshot ( ) ;
60+ } ) ;
61+ } ) ;
62+
4263 it ( 'set activeKey' , ( ) => {
4364 const wrapper = mount (
4465 < Menu activeKey = "1" >
Original file line number Diff line number Diff line change @@ -112,4 +112,18 @@ describe('MenuItem', () => {
112112 expect ( onClick ) . toHaveBeenCalledTimes ( 3 ) ;
113113 } ) ;
114114 } ) ;
115+
116+ describe ( 'overwrite default role' , ( ) => {
117+ it ( 'should set empty role' , ( ) => {
118+ const wrapper = shallow ( < NakedMenuItem role = { null } > test</ NakedMenuItem > ) ;
119+
120+ expect ( wrapper . render ( ) ) . toMatchSnapshot ( ) ;
121+ } ) ;
122+
123+ it ( 'should set specific role' , ( ) => {
124+ const wrapper = shallow ( < NakedMenuItem role = "option" > test</ NakedMenuItem > ) ;
125+
126+ expect ( wrapper . render ( ) ) . toMatchSnapshot ( ) ;
127+ } ) ;
128+ } ) ;
115129} ) ;
Original file line number Diff line number Diff line change @@ -267,3 +267,33 @@ exports[`Menu render renders vertical menu correctly 1`] = `
267267 </li >
268268</ul >
269269` ;
270+
271+ exports [` Menu render role listbox renders menu correctly 1` ] = `
272+ <ul
273+ class = " rc-menu myMenu rc-menu-root rc-menu-vertical"
274+ role = " listbox"
275+ tabindex = " 0"
276+ >
277+ <li
278+ aria-selected = " false"
279+ class = " rc-menu-item"
280+ role = " option"
281+ >
282+ 1
283+ </li >
284+ <li
285+ aria-selected = " false"
286+ class = " rc-menu-item"
287+ role = " option"
288+ >
289+ 2
290+ </li >
291+ <li
292+ aria-selected = " false"
293+ class = " rc-menu-item"
294+ role = " option"
295+ >
296+ 3
297+ </li >
298+ </ul >
299+ ` ;
Original file line number Diff line number Diff line change 11// Jest Snapshot v1, https://goo.gl/fbAQLP
22
3+ exports [` MenuItem overwrite default role should set empty role 1` ] = `
4+ <li
5+ class = " undefined-item"
6+ >
7+ test
8+ </li >
9+ ` ;
10+
11+ exports [` MenuItem overwrite default role should set specific role 1` ] = `
12+ <li
13+ class = " undefined-item"
14+ role = " option"
15+ >
16+ test
17+ </li >
18+ ` ;
19+
320exports [` MenuItem rest props can render all props to sub component 1` ] = `
421<ul
522 class = " rc-menu rc-menu-root rc-menu-inline"
You can’t perform that action at this time.
0 commit comments