From 08c3e4dbf6190570cbfd58623d0be64f07c4ad32 Mon Sep 17 00:00:00 2001 From: wsuwt Date: Mon, 30 Oct 2023 16:54:42 +0700 Subject: [PATCH] fix(list): selectItem() should always require a param --- packages/elements/src/list/elements/list.ts | 37 +++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/packages/elements/src/list/elements/list.ts b/packages/elements/src/list/elements/list.ts index 7ef16636e3..54ba85d4fc 100644 --- a/packages/elements/src/list/elements/list.ts +++ b/packages/elements/src/list/elements/list.ts @@ -200,22 +200,31 @@ export class List extends ControlElement { * @param {T | HTMLElement} item Data Item or Item Element * @returns If a selection has been made or not */ - public selectItem(item?: T | HTMLElement): boolean { - if (!this.stateless) { - if (item instanceof HTMLElement) { - item = this.itemFromElement(item); - } - if (item && this.multiple) { - const value = this.composer.getItemPropertyValue(item, 'selected'); - this.composer.setItemPropertyValue(item, 'selected', !value); - return true; - } - if (item && this.composer.getItemPropertyValue(item, 'selected') !== true) { - this.clearSelection(); - this.composer.setItemPropertyValue(item, 'selected', true); - return true; + public selectItem(item: T | HTMLElement): boolean { + if (this.stateless) { + return false; + } + + if (item instanceof HTMLElement) { + const itemFromElement = this.itemFromElement(item); + if (itemFromElement) { + item = itemFromElement; + } else { + return false; } } + + if (this.multiple) { + const value = this.composer.getItemPropertyValue(item, 'selected'); + this.composer.setItemPropertyValue(item, 'selected', !value); + return true; + } + if (this.composer.getItemPropertyValue(item, 'selected') !== true) { + this.clearSelection(); + this.composer.setItemPropertyValue(item, 'selected', true); + return true; + } + return false; }