From 35433c02b30074372ac642625aaa796c74b7ab3f Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Fri, 7 Apr 2023 16:46:05 +0530 Subject: [PATCH] dropdown_list_widget: Select first option on pressing enter in search. This commit updates the code for MultiSelectDropdownListWidget and DropdownListWidget components to select the first option on pressing enter when focus is on search input. Fixes #25024. --- web/src/dropdown_list_widget.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/web/src/dropdown_list_widget.js b/web/src/dropdown_list_widget.js index 34a0b3e407..7c524cb737 100644 --- a/web/src/dropdown_list_widget.js +++ b/web/src/dropdown_list_widget.js @@ -201,6 +201,14 @@ export class DropdownListWidget { break; } } + + if (keydown_util.is_enter_event(e) && e.target === $search_input[0]) { + e.stopPropagation(); + e.preventDefault(); + // Select the first option from the menu on pressing + // "Enter" when focus is on the search input. + dropdown_elements().first().trigger("click"); + } }); } @@ -525,6 +533,14 @@ export class MultiSelectDropdownListWidget extends DropdownListWidget { break; } } + + if (keydown_util.is_enter_event(e) && e.target === $search_input[0]) { + e.stopPropagation(); + e.preventDefault(); + // Select the first option from the menu on pressing + // "Enter" when focus is on the search input. + dropdown_elements().first().trigger("click"); + } }); }