@@ -8,7 +8,7 @@ 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 . tabIndex = '-1' ; // for initial focus, programmatic focus only
11
+ div . tabIndex = - 1 ; // for initial focus, programmatic focus only
12
12
div . addEventListener ( 'keydown' , ( e ) => {
13
13
if ( e . key === 'Tab' ) {
14
14
const items = this . tippyContent . querySelectorAll ( '[role="menuitem"]' ) ;
@@ -60,21 +60,35 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
60
60
this . tippyContent = div ;
61
61
}
62
62
63
+ const itemFlexSpace = this . menuItemsEl . querySelector ( '.item-flex-space' ) ;
64
+
63
65
// move items in tippy back into the menu items for subsequent measurement
64
66
for ( const item of this . tippyItems || [ ] ) {
65
- this . menuItemsEl . append ( item ) ;
67
+ if ( ! itemFlexSpace || item . getAttribute ( 'data-after-flex-space' ) ) {
68
+ this . menuItemsEl . append ( item ) ;
69
+ } else {
70
+ itemFlexSpace . insertAdjacentElement ( 'beforebegin' , item ) ;
71
+ }
66
72
}
67
73
68
74
// measure which items are partially outside the element and move them into the button menu
75
+ itemFlexSpace ?. style . setProperty ( 'display' , 'none' , 'important' ) ;
69
76
this . tippyItems = [ ] ;
70
77
const menuRight = this . offsetLeft + this . offsetWidth ;
71
- const menuItems = this . menuItemsEl . querySelectorAll ( '.item' ) ;
78
+ const menuItems = this . menuItemsEl . querySelectorAll ( '.item, .item-flex-space' ) ;
79
+ let afterFlexSpace = false ;
72
80
for ( const item of menuItems ) {
81
+ if ( item . classList . contains ( 'item-flex-space' ) ) {
82
+ afterFlexSpace = true ;
83
+ continue ;
84
+ }
85
+ if ( afterFlexSpace ) item . setAttribute ( 'data-after-flex-space' , 'true' ) ;
73
86
const itemRight = item . offsetLeft + item . offsetWidth ;
74
- if ( menuRight - itemRight < 38 ) { // roughly the width of .overflow-menu-button
87
+ if ( menuRight - itemRight < 38 ) { // roughly the width of .overflow-menu-button with some extra space
75
88
this . tippyItems . push ( item ) ;
76
89
}
77
90
}
91
+ itemFlexSpace ?. style . removeProperty ( 'display' ) ;
78
92
79
93
// if there are no overflown items, remove any previously created button
80
94
if ( ! this . tippyItems ?. length ) {
@@ -105,7 +119,7 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
105
119
106
120
// create button initially
107
121
const btn = document . createElement ( 'button' ) ;
108
- btn . classList . add ( 'overflow-menu-button' , 'btn' , 'tw-px-2' , 'hover:tw-text-text-dark' ) ;
122
+ btn . classList . add ( 'overflow-menu-button' ) ;
109
123
btn . setAttribute ( 'aria-label' , window . config . i18n . more_items ) ;
110
124
btn . innerHTML = octiconKebabHorizontal ;
111
125
this . append ( btn ) ;
0 commit comments