From 25727c9c030f3f743f5b865a543700cb65453661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Eikeland?= Date: Tue, 19 Nov 2024 14:44:56 +0100 Subject: [PATCH] fix(person): personselect should now clear on setting selectedPerson to null --- .changeset/two-carrots-marry.md | 13 +++++++++++++ packages/person/src/components/select/controller.ts | 12 ++++++++++-- packages/person/src/components/select/element.ts | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 .changeset/two-carrots-marry.md diff --git a/.changeset/two-carrots-marry.md b/.changeset/two-carrots-marry.md new file mode 100644 index 000000000..aa36a470c --- /dev/null +++ b/.changeset/two-carrots-marry.md @@ -0,0 +1,13 @@ +--- +"@equinor/fusion-wc-person": patch +--- + +### Changes in `PersonSelectController` + +- Renamed the `attrSelectPerson` method to `attrSelectedPerson`. +- Updated the `attrSelectedPerson` method to clear `selectedIds` when `select` is null or an empty string and `selectedIds` size is greater than zero. +- Added logic to clear previous selections when the `selectedPerson` property changes. + +### Changes in `PersonSelectElement` + +- Updated the `updated` method to call `attrSelectedPerson` instead of `attrSelectPerson`. \ No newline at end of file diff --git a/packages/person/src/components/select/controller.ts b/packages/person/src/components/select/controller.ts index 373df7bbc..6f459aa24 100644 --- a/packages/person/src/components/select/controller.ts +++ b/packages/person/src/components/select/controller.ts @@ -54,12 +54,20 @@ export class PersonSelectController implements ReactiveController { * Resolve personInfo task from selectedPerson property. * Runs on host updated when property is changed */ - public attrSelectPerson(select: string | null | undefined) { - /* Do not trigger task if undefined or null */ + public attrSelectedPerson(select: string | null | undefined) { + if (select === null || select === '' && this.selectedIds.size) { + this.clear(); + return; + } + + /* Do not trigger task if undefined */ if (!select) { return; } + // clear previous selections since property has changed + this.selectedIds.clear(); + /* Trigger PersonInfo task with upn or azureId */ if (select.match('@')) { this.#host.upn = select; diff --git a/packages/person/src/components/select/element.ts b/packages/person/src/components/select/element.ts index 728bb529b..7df19af62 100644 --- a/packages/person/src/components/select/element.ts +++ b/packages/person/src/components/select/element.ts @@ -168,7 +168,7 @@ export class PersonSelectElement updated(props: Map) { if (props.has('selectedPerson')) { - this.controllers.element.attrSelectPerson( + this.controllers.element.attrSelectedPerson( this.selectedPerson?.upn ?? this.selectedPerson?.azureId ?? (this.selectedPerson as null | undefined), ); }