@@ -14,6 +14,11 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
1414 mutationObserver : MutationObserver ;
1515 lastWidth : number ;
1616
17+ updateButtonActivationState ( ) {
18+ if ( ! this . button || ! this . tippyContent ) return ;
19+ toggleClass ( this . button , 'active' , Boolean ( this . tippyContent . querySelector ( '.item.active' ) ) ) ;
20+ }
21+
1722 updateItems = throttle ( 100 , ( ) => {
1823 if ( ! this . tippyContent ) {
1924 const div = document . createElement ( 'div' ) ;
@@ -125,9 +130,18 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
125130 this . tippyContent . append ( item ) ;
126131 }
127132
133+ // close tippy when clicking item of tippy
134+ const items = this . tippyContent . querySelectorAll < HTMLElement > ( '.item' ) ;
135+ for ( const item of items ) {
136+ item . addEventListener ( 'click' , ( ) => {
137+ this . button ?. _tippy . hide ( ) ;
138+ } ) ;
139+ }
140+
128141 // update existing tippy
129142 if ( this . button ?. _tippy ) {
130143 this . button . _tippy . setContent ( this . tippyContent ) ;
144+ this . updateButtonActivationState ( ) ;
131145 return ;
132146 }
133147
@@ -138,6 +152,7 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
138152 btn . innerHTML = octiconKebabHorizontal ;
139153 this . append ( btn ) ;
140154 this . button = btn ;
155+ this . updateButtonActivationState ( ) ;
141156
142157 createTippy ( btn , {
143158 trigger : 'click' ,
@@ -153,10 +168,6 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
153168 } , 0 ) ;
154169 } ,
155170 } ) ;
156-
157- this . tippyContent . querySelector ( '.item' ) . addEventListener ( 'click' , ( ) => {
158- this . button . _tippy . hide ( ) ;
159- } ) ;
160171 } ) ;
161172
162173 init ( ) {
@@ -225,9 +236,7 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
225236 }
226237
227238 attributeChangedCallback ( ) {
228- if ( ! this . button || ! this . tippyContent ) return ;
229- const containActiveInTippy = this . tippyContent . querySelector ( '.item.active' ) ;
230- toggleClass ( this . button , 'active' , Boolean ( containActiveInTippy ) ) ;
239+ this . updateButtonActivationState ( ) ;
231240 }
232241
233242 disconnectedCallback ( ) {
0 commit comments