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 = {}) {
4343 } ) ;
4444
4545 if ( role === 'menu' ) {
46- target . setAttribute ( 'aria-haspopup' , 'menu ' ) ;
46+ target . setAttribute ( 'aria-haspopup' , 'true ' ) ;
4747 }
4848
4949 return instance ;
Original file line number Diff line number Diff line change @@ -8,6 +8,33 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
88 if ( ! this . tippyContent ) {
99 const div = document . createElement ( 'div' ) ;
1010 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+ } ) ;
1138 this . append ( div ) ;
1239 this . tippyContent = div ;
1340 }
@@ -70,6 +97,9 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
7097 placement : 'bottom-end' ,
7198 role : 'menu' ,
7299 content : this . tippyContent ,
100+ onShow : ( ) => { // FIXME: onShown doesn't work (never be called)
101+ setTimeout ( ( ) => this . tippyContent . querySelector ( '[role="menuitem"]' ) . focus ( ) ) ;
102+ } ,
73103 } ) ;
74104 } ) ;
75105
You can’t perform that action at this time.
0 commit comments