Skip to content

Commit

Permalink
fix(list): clear selected values on filtration (#UIM-868) (#817)
Browse files Browse the repository at this point in the history
  • Loading branch information
lskramarov authored Feb 18, 2022
1 parent 7a21b08 commit 350c5f7
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions packages/mosaic/list/list-selection.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,14 @@ export class McListOption implements OnDestroy, OnInit, IFocusableOption {

@Input()
get selected(): boolean {
return this.listSelection.selectionModel && this.listSelection.selectionModel.isSelected(this) || false;
return this.listSelection.selectionModel?.isSelected(this) || false;
}

set selected(value: boolean) {
const isSelected = toBoolean(value);

if (isSelected !== this._selected) {
this.setSelected(isSelected);

this.listSelection.reportValueChange();
}
}

Expand Down Expand Up @@ -251,11 +249,7 @@ export class McListOption implements OnDestroy, OnInit, IFocusableOption {
getHeight(): number {
const clientRects = this.elementRef.nativeElement.getClientRects();

if (clientRects.length) {
return clientRects[0].height;
}

return 0;
return clientRects.length ? clientRects[0].height : 0;
}

handleClick($event) {
Expand Down Expand Up @@ -669,11 +663,7 @@ export class McListSelection extends McListSelectionMixinBase implements CanDisa
getHeight(): number {
const clientRects = this.elementRef.nativeElement.getClientRects();

if (clientRects.length) {
return clientRects[0].height;
}

return 0;
return clientRects.length ? clientRects[0].height : 0;
}

// View to model callback that should be called if the list or its options lost focus.
Expand All @@ -682,15 +672,15 @@ export class McListSelection extends McListSelectionMixinBase implements CanDisa

// Removes an option from the selection list and updates the active item.
removeOptionFromList(option: McListOption) {
if (option.hasFocus) {
const optionIndex = this.getOptionIndex(option);

// Check whether the option is the last item
if (optionIndex > 0) {
this.keyManager.setPreviousItemActive();
} else if (optionIndex === 0 && this.options.length > 1) {
this.keyManager.setNextItemActive();
}
if (!option.hasFocus) { return; }

const optionIndex = this.getOptionIndex(option);

// Check whether the option is the last item
if (optionIndex > 0) {
this.keyManager.setPreviousItemActive();
} else if (optionIndex === 0 && this.options.length > 1) {
this.keyManager.setNextItemActive();
}
}

Expand Down

0 comments on commit 350c5f7

Please sign in to comment.