Skip to content
Snippets Groups Projects
Verified Commit ade8b9e7 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Allow submitting from the filter bar with only one filter remaining

parent bb497964
No related branches found
No related tags found
1 merge request!1327Allow submitting from the filter bar with only one filter remaining
......@@ -21,6 +21,7 @@
ref="filterinput"
:placeholder="computedPlaceholder"
:suggestions="inputSuggestions || []"
:select-single-suggestion="selectedFilterName !== null"
:is-loading="isLoading"
:disabled="disabled"
v-model:is-active="isActive"
......
......@@ -72,7 +72,7 @@ export default {
},
/**
* Enables the suggestions. This property is synchronous; it should be bound
* with :is-active.sync and allows this component to let the parent know that
* with v-model.is-active and allows this component to let the parent know that
* the user is focusing on it or has performed a keyboard action that toggles
* the suggestions.
*/
......@@ -80,6 +80,14 @@ export default {
type: Boolean,
default: false
},
/**
* Whether or not to automatically select a suggestion when the user presser Enter
* and there is only one suggestion in the list.
*/
selectSingleSuggestion: {
type: Boolean,
default: false
},
// Allows the input to behave just like a normal text input for a parent
modelValue: {
type: String,
......@@ -112,7 +120,7 @@ export default {
navigate (event) {
this.$emit('update:isActive', true)
// If there is only one filtered suggestion, it gets selected when hitting enter
if (this.filteredSuggestions.length === 1) this.current = this.filteredSuggestions[0][0]
if (this.filteredSuggestions.length === 1 && this.selectSingleSuggestion) this.current = this.filteredSuggestions[0][0]
const currentIndex = this.filteredSuggestions.findIndex(([key]) => key === this.current)
if (['ArrowUp', 'ArrowDown'].includes(event.key) && this.filteredSuggestions.length) {
let newIndex = currentIndex
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment