File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ export function createTippy(target, opts = {}) {
43
43
} ) ;
44
44
45
45
if ( role === 'menu' ) {
46
- target . setAttribute ( 'aria-haspopup' , 'menu ' ) ;
46
+ target . setAttribute ( 'aria-haspopup' , 'true ' ) ;
47
47
}
48
48
49
49
return instance ;
Original file line number Diff line number Diff line change @@ -8,6 +8,33 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
8
8
if ( ! this . tippyContent ) {
9
9
const div = document . createElement ( 'div' ) ;
10
10
div . classList . add ( 'tippy-target' ) ;
11
+ div . addEventListener ( 'keydown' , ( e ) => {
12
+ if ( e . code === 'Tab' ) {
13
+ const items = this . tippyContent . querySelectorAll ( '[role="menuitem"]' ) ;
14
+ if ( e . shiftKey ) {
15
+ if ( document . activeElement === items [ 0 ] ) {
16
+ e . preventDefault ( ) ;
17
+ items [ items . length - 1 ] . focus ( ) ;
18
+ }
19
+ } else {
20
+ if ( document . activeElement === items [ items . length - 1 ] ) {
21
+ e . preventDefault ( ) ;
22
+ items [ 0 ] . focus ( ) ;
23
+ }
24
+ }
25
+ } else if ( e . code === 'Escape' ) {
26
+ e . preventDefault ( ) ;
27
+ this . button . _tippy . hide ( ) ;
28
+ this . button . focus ( ) ;
29
+ } else if ( e . code === 'Space' ) {
30
+ // eslint-disable-next-line unicorn/no-lonely-if
31
+ if ( document . activeElement . matches ( '[role="menuitem"]' ) ) {
32
+ e . preventDefault ( ) ;
33
+ document . activeElement . click ( ) ;
34
+ }
35
+ }
36
+ // TODO: handle arrow keys (at the moment, tab&shift-tab also work)
37
+ } ) ;
11
38
this . append ( div ) ;
12
39
this . tippyContent = div ;
13
40
}
@@ -70,6 +97,9 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
70
97
placement : 'bottom-end' ,
71
98
role : 'menu' ,
72
99
content : this . tippyContent ,
100
+ onShow : ( ) => { // FIXME: onShown doesn't work (never be called)
101
+ setTimeout ( ( ) => this . tippyContent . querySelector ( '[role="menuitem"]' ) . focus ( ) ) ;
102
+ } ,
73
103
} ) ;
74
104
} ) ;
75
105
You can’t perform that action at this time.
0 commit comments