Fixed - Selected option shouldn't be focused before pressing down on AutoComplete.
parent
e5487a8265
commit
18455ed9f8
|
@ -209,7 +209,7 @@ export default {
|
||||||
suggestions() {
|
suggestions() {
|
||||||
if (this.searching) {
|
if (this.searching) {
|
||||||
ObjectUtils.isNotEmpty(this.suggestions) ? this.show() : this.hide();
|
ObjectUtils.isNotEmpty(this.suggestions) ? this.show() : this.hide();
|
||||||
this.focusedOptionIndex = this.overlayVisible && this.autoOptionFocus ? this.findFirstOptionIndex() : -1;
|
this.focusedOptionIndex = this.overlayVisible && this.autoOptionFocus ? this.findFirstFocusedOptionIndex() : -1;
|
||||||
this.searching = false;
|
this.searching = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ export default {
|
||||||
show(isFocus) {
|
show(isFocus) {
|
||||||
this.$emit('before-show');
|
this.$emit('before-show');
|
||||||
this.overlayVisible = true;
|
this.overlayVisible = true;
|
||||||
this.focusedOptionIndex = this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : (this.autoOptionFocus ? this.findFirstOptionIndex() : -1);
|
this.focusedOptionIndex = this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : (this.autoOptionFocus ? this.findFirstFocusedOptionIndex() : -1);
|
||||||
|
|
||||||
isFocus && this.$refs.focusInput.focus();
|
isFocus && this.$refs.focusInput.focus();
|
||||||
},
|
},
|
||||||
|
@ -288,7 +288,7 @@ export default {
|
||||||
},
|
},
|
||||||
onFocus(event) {
|
onFocus(event) {
|
||||||
this.focused = true;
|
this.focused = true;
|
||||||
this.focusedOptionIndex = this.overlayVisible && this.autoOptionFocus ? this.findFirstOptionIndex() : -1;
|
this.focusedOptionIndex = this.overlayVisible && this.autoOptionFocus ? this.findFirstFocusedOptionIndex() : -1;
|
||||||
this.overlayVisible && this.scrollInView(this.focusedOptionIndex);
|
this.overlayVisible && this.scrollInView(this.focusedOptionIndex);
|
||||||
this.$emit('focus', event);
|
this.$emit('focus', event);
|
||||||
},
|
},
|
||||||
|
@ -499,7 +499,7 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const optionIndex = this.focusedOptionIndex !== -1 ? this.findNextOptionIndex(this.focusedOptionIndex) : this.findFirstOptionIndex();
|
const optionIndex = this.focusedOptionIndex !== -1 ? this.findNextOptionIndex(this.focusedOptionIndex) : this.findFirstFocusedOptionIndex();
|
||||||
|
|
||||||
this.changeFocusedOptionIndex(event, optionIndex);
|
this.changeFocusedOptionIndex(event, optionIndex);
|
||||||
|
|
||||||
|
@ -519,7 +519,7 @@ export default {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const optionIndex = this.focusedOptionIndex !== -1 ? this.findPrevOptionIndex(this.focusedOptionIndex) : this.findLastOptionIndex();
|
const optionIndex = this.focusedOptionIndex !== -1 ? this.findPrevOptionIndex(this.focusedOptionIndex) : this.findLastFocusedOptionIndex();
|
||||||
|
|
||||||
this.changeFocusedOptionIndex(event, optionIndex);
|
this.changeFocusedOptionIndex(event, optionIndex);
|
||||||
|
|
||||||
|
@ -719,6 +719,9 @@ export default {
|
||||||
isValidOption(option) {
|
isValidOption(option) {
|
||||||
return option && !(this.isOptionDisabled(option) || this.isOptionGroup(option));
|
return option && !(this.isOptionDisabled(option) || this.isOptionGroup(option));
|
||||||
},
|
},
|
||||||
|
isValidSelectedOption(option) {
|
||||||
|
return this.isValidOption(option) && this.isSelected(option);
|
||||||
|
},
|
||||||
isSelected(option) {
|
isSelected(option) {
|
||||||
return ObjectUtils.equals(this.modelValue, this.getOptionValue(option), this.equalityKey);
|
return ObjectUtils.equals(this.modelValue, this.getOptionValue(option), this.equalityKey);
|
||||||
},
|
},
|
||||||
|
@ -736,6 +739,17 @@ export default {
|
||||||
const matchedOptionIndex = index > 0 ? this.visibleOptions.slice(0, index).findLastIndex(option => this.isValidOption(option)) : -1;
|
const matchedOptionIndex = index > 0 ? this.visibleOptions.slice(0, index).findLastIndex(option => this.isValidOption(option)) : -1;
|
||||||
return matchedOptionIndex > -1 ? matchedOptionIndex : index;
|
return matchedOptionIndex > -1 ? matchedOptionIndex : index;
|
||||||
},
|
},
|
||||||
|
findSelectedOptionIndex() {
|
||||||
|
return this.hasSelectedOption ? this.visibleOptions.findIndex(option => this.isValidSelectedOption(option)) : -1;
|
||||||
|
},
|
||||||
|
findFirstFocusedOptionIndex() {
|
||||||
|
const selectedIndex = this.findSelectedOptionIndex();
|
||||||
|
return selectedIndex < 0 ? this.findFirstOptionIndex() : selectedIndex;
|
||||||
|
},
|
||||||
|
findLastFocusedOptionIndex() {
|
||||||
|
const selectedIndex = this.findSelectedOptionIndex();
|
||||||
|
return selectedIndex < 0 ? this.findLastOptionIndex() : selectedIndex;
|
||||||
|
},
|
||||||
search(event, query, source) {
|
search(event, query, source) {
|
||||||
//allow empty string but not undefined or null
|
//allow empty string but not undefined or null
|
||||||
if (query === undefined || query === null) {
|
if (query === undefined || query === null) {
|
||||||
|
|
Loading…
Reference in New Issue