Skip to content

Commit

Permalink
fix(SelectionList): fix selection list on blur
Browse files Browse the repository at this point in the history
close selection list panel withour reopening if there is no options in the list

ISSUES CLOSED: #2056
  • Loading branch information
IraErshova authored and benjamincharity committed Mar 5, 2020
1 parent c962b99 commit 89ad181
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 2 additions & 5 deletions projects/library/select/src/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ import {
ViewChild,
ViewEncapsulation,
} from '@angular/core';
import {
FormControl,
NgControl,
} from '@angular/forms';
import { NgControl } from '@angular/forms';
import { MAT_CHECKBOX_CLICK_ACTION } from '@angular/material/checkbox';
import { TsDocumentService } from '@terminus/ngx-tools/browser';
import {
Expand Down Expand Up @@ -433,7 +430,7 @@ export class TsSelectComponent implements
// Try to use the 2nd option in case the first option is blank or a filter etc. Fall back to the first item if needed.
const options = this.options.toArray();
const option = options[1] || options[0];
return option.elementRef.nativeElement.offsetHeight;
return option && option.elementRef.nativeElement.offsetHeight;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class TsSelectionListTriggerDirective<ValueType = string> implements Cont
// Try to use the 2nd option in case the first option is blank or a filter etc. Fall back to the first item if needed.
const options = this.selectionListPanel.options.toArray();
const option = options[1] || options[0];
return option.elementRef.nativeElement.offsetHeight;
return option && option.elementRef.nativeElement.offsetHeight;
}

/**
Expand Down Expand Up @@ -375,8 +375,9 @@ export class TsSelectionListTriggerDirective<ValueType = string> implements Cont
this.changeDetectorRef.detectChanges();
}

// Only allow reopening when in multiple mode
if (this.allowMultiple && this.reopenAfterSelection && !overrideReopenFlag) {
const options = this.selectionListPanel.options.toArray();
// Only allow reopening when in multiple mode and when there are options, which could be selected
if (this.allowMultiple && this.reopenAfterSelection && !overrideReopenFlag && options.length) {
this.openPanel();
}
}
Expand Down

0 comments on commit 89ad181

Please sign in to comment.