Skip to content

Commit

Permalink
Merge pull request #295 from storyblok/hotfix/str-1272
Browse files Browse the repository at this point in the history
fix(str-1272): fix SbSelect to deal properly with created options when multiple
  • Loading branch information
Thiago Saife authored Sep 5, 2022
2 parents b3d8951 + afcaa30 commit 584c1f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/components/Select/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,24 @@ export default {
* @param {Array<String>|String} value
*/
handleEmitValue(value) {
// doesn't close the list
if (this.multiple) {
const valueExists = this.options.find(
(option) =>
option === value ||
option[this.itemValue] === value ||
option[this.itemLabel] === value
)
if (valueExists) {
const parsedValue = this.emitOption ? valueExists : value
const inputValue = this.processMultipleValue(parsedValue)
this.$emit('input', inputValue)
} else if (this.allowCreate) {
this.handleOptionCreated(value)
}
this.searchInput = ''
const $value = this.processMultipleValue(value)
this.$emit('input', $value)
return
}
Expand All @@ -385,6 +398,9 @@ export default {
handleOptionCreated(value) {
this.searchInput = ''
this.$emit('option-created', value)
if (this.multiple) return
this.$_focusInner()
this.hideList()
},
Expand Down
1 change: 1 addition & 0 deletions src/components/Select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@

&__empty {
display: block;
padding-top: 13px;
color: $sb-dark-blue-50;
font-size: 1.3rem;
text-align: center;
Expand Down

1 comment on commit 584c1f6

@vercel
Copy link

@vercel vercel bot commented on 584c1f6 Sep 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.