@@ -8,7 +8,7 @@ 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 . tabIndex = '-1' ; // for initial focus, programmatic focus only
11+ div . tabIndex = - 1 ; // for initial focus, programmatic focus only
1212 div . addEventListener ( 'keydown' , ( e ) => {
1313 if ( e . key === 'Tab' ) {
1414 const items = this . tippyContent . querySelectorAll ( '[role="menuitem"]' ) ;
@@ -60,21 +60,35 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
6060 this . tippyContent = div ;
6161 }
6262
63+ const itemFlexSpace = this . menuItemsEl . querySelector ( '.item-flex-space' ) ;
64+
6365 // move items in tippy back into the menu items for subsequent measurement
6466 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+ }
6672 }
6773
6874 // measure which items are partially outside the element and move them into the button menu
75+ itemFlexSpace ?. style . setProperty ( 'display' , 'none' , 'important' ) ;
6976 this . tippyItems = [ ] ;
7077 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 ;
7280 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' ) ;
7386 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
7588 this . tippyItems . push ( item ) ;
7689 }
7790 }
91+ itemFlexSpace ?. style . removeProperty ( 'display' ) ;
7892
7993 // if there are no overflown items, remove any previously created button
8094 if ( ! this . tippyItems ?. length ) {
@@ -105,7 +119,7 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
105119
106120 // create button initially
107121 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' ) ;
109123 btn . setAttribute ( 'aria-label' , window . config . i18n . more_items ) ;
110124 btn . innerHTML = octiconKebabHorizontal ;
111125 this . append ( btn ) ;
0 commit comments