Skip to content

Commit f3fa4dd

Browse files
committed
Optimized the overflow-menu:
1. Close the tippy when a menu item inside the tippy is clicked. 2. When a menu item inside the tippy is selected, move the active state of the menu to the tippy's button.
1 parent d725b78 commit f3fa4dd

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

web_src/css/base.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,14 @@ overflow-menu .overflow-menu-button {
747747
padding: 0;
748748
}
749749

750+
overflow-menu .overflow-menu-button.active {
751+
margin: 0 0 -2px;
752+
border-bottom: 2px solid transparent;
753+
background-color: transparent;
754+
border-color: currentcolor;
755+
font-weight: var(--font-weight-medium);
756+
}
757+
750758
overflow-menu .overflow-menu-button:hover {
751759
color: var(--color-text-dark);
752760
}

web_src/js/components/DashboardRepoList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ export default defineComponent({
391391
</div>
392392
</div>
393393
</div>
394-
<overflow-menu class="ui secondary pointing tabular borderless menu repos-filter">
394+
<overflow-menu class="ui secondary pointing tabular borderless menu repos-filter" :active="reposFilter">
395395
<div class="overflow-menu-items tw-justify-center">
396396
<a class="item" tabindex="0" :class="{active: reposFilter === 'all'}" @click="changeReposFilter('all')">
397397
{{ textAll }}

web_src/js/webcomponents/overflow-menu.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {throttle} from 'throttle-debounce';
22
import {createTippy} from '../modules/tippy.ts';
3-
import {isDocumentFragmentOrElementNode} from '../utils/dom.ts';
3+
import {isDocumentFragmentOrElementNode, toggleClass} from '../utils/dom.ts';
44
import octiconKebabHorizontal from '../../../public/assets/img/svg/octicon-kebab-horizontal.svg';
55

66
window.customElements.define('overflow-menu', class extends HTMLElement {
7+
static observedAttributes = ['active'];
8+
79
tippyContent: HTMLDivElement;
810
tippyItems: Array<HTMLElement>;
911
button: HTMLButtonElement;
@@ -151,6 +153,10 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
151153
}, 0);
152154
},
153155
});
156+
157+
this.tippyContent.querySelector('.item').addEventListener('click', () => {
158+
this.button._tippy.hide();
159+
});
154160
});
155161

156162
init() {
@@ -218,6 +224,12 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
218224
}
219225
}
220226

227+
attributeChangedCallback() {
228+
if (!this.button || !this.tippyContent) return;
229+
const containActiveInTippy = this.tippyContent.querySelector('.item.active');
230+
toggleClass(this.button, 'active', Boolean(containActiveInTippy));
231+
}
232+
221233
disconnectedCallback() {
222234
this.mutationObserver?.disconnect();
223235
this.resizeObserver?.disconnect();

0 commit comments

Comments
 (0)