Skip to content

Commit

Permalink
fix(list): selectItem() should always require a param (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsuwt authored Oct 31, 2023
1 parent 11ce611 commit 3ac0c7b
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions packages/elements/src/list/elements/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,31 @@ export class List<T extends DataItem = ItemData> 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;
}

Expand Down

0 comments on commit 3ac0c7b

Please sign in to comment.