Skip to content

Commit dfc0d12

Browse files
wxiaoguangGiteaBot
authored andcommitted
Improve dropdown's behavior when there is a search input in menu (go-gitea#27526)
Follow go-gitea#27225 The change in go-gitea#27225 is not ideal, this should be the complete fix: support the layout which Fomantic doesn't support.
1 parent fb5ae2a commit dfc0d12

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

web_src/js/modules/aria/dropdown.js

+9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ function updateSelectionLabel($label) {
5757
function delegateOne($dropdown) {
5858
const dropdownCall = fomanticDropdownFn.bind($dropdown);
5959

60+
// If there is a "search input" in the "menu", Fomantic will only "focus the input" but not "toggle the menu" when the "dropdown icon" is clicked.
61+
// Actually, Fomantic UI doesn't support such layout/usage. It needs to patch the "focusSearch" / "blurSearch" functions to make sure it toggles the menu.
62+
const oldFocusSearch = dropdownCall('internal', 'focusSearch');
63+
const oldBlurSearch = dropdownCall('internal', 'blurSearch');
64+
// * If the "dropdown icon" is clicked, Fomantic calls "focusSearch", so show the menu
65+
dropdownCall('internal', 'focusSearch', function () { dropdownCall('show'); oldFocusSearch.call(this) });
66+
// * If the "dropdown icon" is clicked again when the menu is visible, Fomantic calls "blurSearch", so hide the menu
67+
dropdownCall('internal', 'blurSearch', function () { oldBlurSearch.call(this); dropdownCall('hide') });
68+
6069
// the "template" functions are used for dynamic creation (eg: AJAX)
6170
const dropdownTemplates = {...dropdownCall('setting', 'templates'), t: performance.now()};
6271
const dropdownTemplatesMenuOld = dropdownTemplates.menu;

web_src/js/modules/fomantic.js

-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ export function initGiteaFomantic() {
1616
$.fn.dropdown.settings.fullTextSearch = 'exact';
1717
// Do not use "cursor: pointer" for dropdown labels
1818
$.fn.dropdown.settings.className.label += ' gt-cursor-default';
19-
// The default selector has a bug: if there is a "search input" in the "menu", Fomantic will only "focus the input" but not "toggle the menu" when the "dropdown icon" is clicked.
20-
// Actually, the "search input in menu" shouldn't be considered as the dropdown's input
21-
$.fn.dropdown.settings.selector.search = '> input.search, :not(.menu) > .search > input, :not(.menu) input.search';
2219
// Always use Gitea's SVG icons
2320
$.fn.dropdown.settings.templates.label = function(_value, text, preserveHTML, className) {
2421
const escape = $.fn.dropdown.settings.templates.escape;

0 commit comments

Comments
 (0)