@@ -3,6 +3,62 @@ import { arrowDown, arrowRight, enter, fixtureSync, nextRender, outsideClick } f
33import { getDeepActiveElement } from '@vaadin/a11y-base/src/focus-utils.js' ;
44
55describe ( 'a11y' , ( ) => {
6+ describe ( 'ARIA attributes' , ( ) => {
7+ let menu , buttons , subMenu , overflow ;
8+
9+ beforeEach ( async ( ) => {
10+ menu = fixtureSync ( '<vaadin-menu-bar></vaadin-menu-bar>' ) ;
11+ menu . items = [
12+ {
13+ text : 'Menu Item 1' ,
14+ children : [ { text : 'Menu Item 1 1' } , { text : 'Menu Item 1 2' } ] ,
15+ } ,
16+ { text : 'Menu Item 2' } ,
17+ {
18+ text : 'Menu Item 3' ,
19+ children : [ { text : 'Menu Item 3 1' } , { text : 'Menu Item 3 2' } ] ,
20+ } ,
21+ ] ;
22+ await nextRender ( menu ) ;
23+ subMenu = menu . _subMenu ;
24+ buttons = menu . _buttons ;
25+ overflow = menu . _overflow ;
26+ } ) ;
27+
28+ it ( 'should set role attribute on host element' , ( ) => {
29+ expect ( menu . getAttribute ( 'role' ) ) . to . equal ( 'menubar' ) ;
30+ } ) ;
31+
32+ it ( 'should set role attribute on menu bar buttons' , ( ) => {
33+ buttons . forEach ( ( btn ) => {
34+ expect ( btn . getAttribute ( 'role' ) ) . to . equal ( 'menuitem' ) ;
35+ } ) ;
36+ } ) ;
37+
38+ it ( 'should set aria-haspopup attribute on buttons with nested items' , ( ) => {
39+ buttons . forEach ( ( btn ) => {
40+ const hasPopup = btn === overflow || btn . item . children ? 'true' : null ;
41+ expect ( btn . getAttribute ( 'aria-haspopup' ) ) . to . equal ( hasPopup ) ;
42+ } ) ;
43+ } ) ;
44+
45+ it ( 'should set aria-expanded attribute on buttons with nested items' , ( ) => {
46+ buttons . forEach ( ( btn ) => {
47+ const expanded = btn === overflow || btn . item . children ? 'false' : null ;
48+ expect ( btn . getAttribute ( 'aria-expanded' ) ) . to . equal ( expanded ) ;
49+ } ) ;
50+ } ) ;
51+
52+ it ( 'should toggle aria-expanded attribute on submenu open / close' , async ( ) => {
53+ buttons [ 0 ] . click ( ) ;
54+ await nextRender ( subMenu ) ;
55+ expect ( buttons [ 0 ] . getAttribute ( 'aria-expanded' ) ) . to . equal ( 'true' ) ;
56+
57+ buttons [ 0 ] . click ( ) ;
58+ expect ( buttons [ 0 ] . getAttribute ( 'aria-expanded' ) ) . to . equal ( 'false' ) ;
59+ } ) ;
60+ } ) ;
61+
662 describe ( 'focus restoration' , ( ) => {
763 let menuBar , overlay , buttons ;
864
0 commit comments