Skip to content

Commit

Permalink
reset filter when opening dropdown with multiple=False
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Dec 14, 2023
1 parent 25df06a commit 0943d77
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions nicegui/elements/select.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export default {
props: ["options"],
props: ["multiple", "options"],
template: `
<q-select
ref="qRef"
v-bind="$attrs"
:multiple="multiple"
:options="filteredOptions"
@filter="filterFn"
>
Expand All @@ -20,7 +21,7 @@ export default {
},
methods: {
filterFn(val, update, abort) {
update(() => (this.filteredOptions = this.findFilteredOptions()));
update(() => (this.filteredOptions = val ? this.findFilteredOptions() : this.initialOptions));
},
findFilteredOptions() {
const needle = this.$el.querySelector("input[type=search]")?.value.toLocaleLowerCase();
Expand All @@ -30,6 +31,7 @@ export default {
},
},
updated() {
if (!this.multiple) return;
const newFilteredOptions = this.findFilteredOptions();
if (newFilteredOptions.length !== this.filteredOptions.length) {
this.filteredOptions = newFilteredOptions;
Expand Down
14 changes: 14 additions & 0 deletions tests/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,17 @@ def test_keep_filtered_options(screen: Screen):
screen.should_contain('A2')
screen.should_not_contain('B1')
screen.should_not_contain('B2')


def test_do_not_keep_filtered_options(screen: Screen):
# https://github.com/zauberzeug/nicegui/issues/2076
ui.select(options=['Alice', 'Bob', 'Carol'], with_input=True)

screen.open('/')
screen.find_by_tag('input').click()
screen.click('Alice')

screen.find_by_tag('input').click()
screen.should_contain('Alice')
screen.should_contain('Bob')
screen.should_contain('Carol')

0 comments on commit 0943d77

Please sign in to comment.