Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QSelect] do not drop selected if key equals value key #22

Merged
merged 3 commits into from
Dec 21, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/qComponents/QSelect/src/QSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,14 @@ export default {
this.popper = null;
},

getKey(value) {
return isPlainObject(value) ? get(value, this.valueKey) : value;
},

getOption(value) {
if (isNil(value)) return null;

const keyByValueKey = isPlainObject(value)
? get(value, this.valueKey)
: value;

const keyByValueKey = this.getKey(value);
const option = this.options.find(({ key }) => key === keyByValueKey);

if (option) return option;
Expand Down Expand Up @@ -516,7 +517,7 @@ export default {
return;
}

const keyByValueKey = get(value, this.valueKey);
const keyByValueKey = this.getKey(value);
const cachedOption = this.selected.find(
({ key }) => key === keyByValueKey
);
Expand All @@ -529,14 +530,17 @@ export default {
}

const option = this.getOption(this.value);
if (!option) {
this.selectedLabel = '';
this.selected = null;
if (option) {
this.selectedLabel = option.preparedLabel;
this.selected = option;
return;
}

this.selectedLabel = option.preparedLabel;
this.selected = option;
const keyByValueKey = this.getKey(this.value);
if (this.selected?.key === keyByValueKey) return;

this.selectedLabel = '';
this.selected = null;
},

handleFocus(event) {
Expand Down