diff --git a/docs/resources/changelog.md b/docs/resources/changelog.md index 0f91036ec..abf3ae678 100644 --- a/docs/resources/changelog.md +++ b/docs/resources/changelog.md @@ -6,6 +6,10 @@ Components with the Experimental badge _During the beta period, these restrictions may be relaxed in the event of a mission-critical bug._ 🐛 +## Next + +- Fixed a bug in `sl-select` where no selection with `multiple` resulted in an incorrect value [#457](https://github.com/shoelace-style/shoelace/issues/457) + ## 2.0.0-beta.43 - Added `?` to optional arguments in methods tables diff --git a/src/components/select/select.ts b/src/components/select/select.ts index 0a1109510..b1ac61da1 100644 --- a/src/components/select/select.ts +++ b/src/components/select/select.ts @@ -159,6 +159,11 @@ export default class SlSelect extends LitElement { } getValueAsArray() { + // Single selects use '' as an empty selection value, so convert this to [] for an empty multi select + if (this.multiple && this.value === '') { + return []; + } + return Array.isArray(this.value) ? this.value : [this.value]; }