From d67f4f26effdcad74b20e5b7be85470459893cc2 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Wed, 3 Jan 2024 12:04:35 +0000 Subject: [PATCH] Selection manager: fixes initial value When the modal initially opens, the `#multiple` is `false`, (regardless of how it is configured), so the initial value is set to `[undefined]`. Then when the `#multiple` is observed as `true` (there must be an underlying bug with the modal context code here), then the `#selection` array already has an initial value of `[undefined]` so will append newly selected values to that array. I discovered this issue due to a bug with the Tree Picker editor. --- .../src/shared/utils/selection-manager/selection.manager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/shared/utils/selection-manager/selection.manager.ts b/src/Umbraco.Web.UI.Client/src/shared/utils/selection-manager/selection.manager.ts index b71f1a66d6..ff63bfd93d 100644 --- a/src/Umbraco.Web.UI.Client/src/shared/utils/selection-manager/selection.manager.ts +++ b/src/Umbraco.Web.UI.Client/src/shared/utils/selection-manager/selection.manager.ts @@ -57,7 +57,7 @@ export class UmbSelectionManager extends UmbBaseController { public setSelection(value: Array) { if (this.getSelectable() === false) return; if (value === undefined) throw new Error('Value cannot be undefined'); - const newSelection = this.getMultiple() ? value : [value[0]]; + const newSelection = this.getMultiple() ? value : value.length > 0 ? [value[0]] : value; this.#selection.next(newSelection); } @@ -78,7 +78,7 @@ export class UmbSelectionManager extends UmbBaseController { public setMultiple(value: boolean) { this.#multiple.next(value); - /* If multiple is set to false, and the current selection is more than one, + /* If multiple is set to false, and the current selection is more than one, then we need to set the selection to the first item. */ if (value === false && this.getSelection().length > 1) { this.setSelection([this.getSelection()[0]]);