Skip to content

Commit 8cd7684

Browse files
committed
fix
1 parent 9d08d3f commit 8cd7684

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

Diff for: web_src/js/features/repo-issue-sidebar-combolist.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {fomanticQuery} from '../modules/fomantic/base.ts';
22
import {POST} from '../modules/fetch.ts';
33
import {queryElemChildren, queryElems, toggleElem} from '../utils/dom.ts';
4+
import {dropdownHideEmptyDividers} from '../modules/fomantic/dropdown.ts';
45

56
// if there are draft comments, confirm before reloading, to avoid losing comments
67
function issueSidebarReloadConfirmDraftComment() {
@@ -149,8 +150,10 @@ class IssueSidebarComboList {
149150
fomanticQuery(this.elDropdown).dropdown('setting', {
150151
action: 'nothing', // do not hide the menu if user presses Enter
151152
fullTextSearch: 'exact',
153+
onShow: () => dropdownHideEmptyDividers(this.elDropdown),
154+
onAfterFilterItems: () => dropdownHideEmptyDividers(this.elDropdown),
152155
onHide: () => this.onHide(),
153-
});
156+
}).dropdown('refresh');
154157
}
155158
}
156159

Diff for: web_src/js/modules/fomantic/dropdown.ts

+32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import $ from 'jquery';
22
import {generateAriaId} from './base.ts';
33
import type {FomanticInitFunction} from '../../types.ts';
4+
import {hideElem} from '../../utils/dom.ts';
45

56
const ariaPatchKey = '_giteaAriaPatchDropdown';
67
const fomanticDropdownFn = $.fn.dropdown;
@@ -59,6 +60,30 @@ function updateSelectionLabel(label: HTMLElement) {
5960
}
6061
}
6162

63+
export function dropdownHideEmptyDividers(elDropdown: HTMLElement) {
64+
const itemsContainer = elDropdown.querySelector('.scrolling.menu') ?? elDropdown.querySelector('.menu');
65+
if (!itemsContainer) return;
66+
let lastVisibleItemType: '' | 'divider' | 'item' = '';
67+
let lastVisibleItem: Element;
68+
for (const item of itemsContainer.children) {
69+
if (!lastVisibleItemType && item.matches('.divider')) {
70+
hideElem(item);
71+
continue;
72+
}
73+
if (item.matches('.tw-hidden, .filtered')) continue;
74+
// now, the item is visible
75+
if (lastVisibleItemType === 'divider' && item.matches('.divider')) {
76+
hideElem(item);
77+
continue;
78+
}
79+
lastVisibleItemType = item.matches('.divider') ? 'divider' : 'item';
80+
lastVisibleItem = item;
81+
}
82+
if (lastVisibleItemType === 'divider') {
83+
hideElem(lastVisibleItem);
84+
}
85+
}
86+
6287
// delegate the dropdown's template functions and callback functions to add aria attributes.
6388
function delegateOne($dropdown: any) {
6489
const dropdownCall = fomanticDropdownFn.bind($dropdown);
@@ -72,6 +97,13 @@ function delegateOne($dropdown: any) {
7297
// * If the "dropdown icon" is clicked again when the menu is visible, Fomantic calls "blurSearch", so hide the menu
7398
dropdownCall('internal', 'blurSearch', function () { oldBlurSearch.call(this); dropdownCall('hide') });
7499

100+
const oldFilterItems = dropdownCall('internal', 'filterItems');
101+
dropdownCall('internal', 'filterItems', function () {
102+
oldFilterItems.call(this);
103+
const onAfterFilterItems = dropdownCall('setting', 'onAfterFilterItems');
104+
if (onAfterFilterItems) onAfterFilterItems();
105+
});
106+
75107
// the "template" functions are used for dynamic creation (eg: AJAX)
76108
const dropdownTemplates = {...dropdownCall('setting', 'templates'), t: performance.now()};
77109
const dropdownTemplatesMenuOld = dropdownTemplates.menu;

0 commit comments

Comments
 (0)