Skip to content

Commit 8bab94a

Browse files
committed
fix
1 parent f3fa4dd commit 8bab94a

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

web_src/css/base.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ overflow-menu .overflow-menu-button {
748748
}
749749

750750
overflow-menu .overflow-menu-button.active {
751-
margin: 0 0 -2px;
751+
padding: 2px 0 0;
752752
border-bottom: 2px solid transparent;
753753
background-color: transparent;
754754
border-color: currentcolor;

web_src/js/webcomponents/overflow-menu.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)