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.
This commit is contained in:
committed by
Jacob Overgaard
parent
550c7710cc
commit
d67f4f26ef
@@ -57,7 +57,7 @@ export class UmbSelectionManager extends UmbBaseController {
|
||||
public setSelection(value: Array<string | null>) {
|
||||
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]]);
|
||||
|
||||
Reference in New Issue
Block a user