Skip to content

Commit

Permalink
fix(dropdown): fix dropdown and overlaylist propagating escape event …
Browse files Browse the repository at this point in the history
…when dropdown is opened
  • Loading branch information
WilliamAguera committed Aug 7, 2019
1 parent 57229fa commit 0b9211d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@overlay
(selectOption)="onSelectOption($event)"
(search)="onSearch($event)"
(close)="handleCloseDropdown()"
(defaultOption)="onDefaultOption()"
(findByLetter)="onFindByLetter($event)"
[customInput]="input"
Expand Down
5 changes: 5 additions & 0 deletions projects/truly-ui/src/components/dropdownlist/dropdownlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ export class TlDropDownList extends ValueAccessorBase<any> implements OnChanges,
}
}

handleCloseDropdown() {
this.isOpen = false;
this.setInputFocus();
}

private setInputFocus() {
this.input.nativeElement.focus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<div class="search-input" *ngIf="searchOnList && !customFocus">
<tl-input
(input)="handleInput($event)"
(keydown.escape)="handleEscape($event)"
(keydown.ArrowUp)="keyManager.setPreviousItemActive(); handleScrollIntoView();"
(keydown.ArrowDown)="keyManager.setNextItemActive(); handleScrollIntoView();"
(keydown.enter)="emitSelectOption(); $event.preventDefault()">
Expand Down
7 changes: 7 additions & 0 deletions projects/truly-ui/src/components/overlaylist/overlay-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export class TlOverlayList implements OnInit, AfterViewInit, OnChanges, OnDestro

@Output() findByLetter: EventEmitter<any> = new EventEmitter();

@Output() close: EventEmitter<any> = new EventEmitter();

@ViewChild( 'list', {static: true} ) list: ElementRef;

@ViewChild( TlInput, { static: false } ) tlInput: TlInput;
Expand Down Expand Up @@ -202,6 +204,11 @@ export class TlOverlayList implements OnInit, AfterViewInit, OnChanges, OnDestro
}
}

handleEscape($event) {
this.stopEvent( $event );
this.close.emit();
}

handleInputFocus() {
if (this.searchOnList && !this.customFocus) {
setTimeout(() => {
Expand Down

0 comments on commit 0b9211d

Please sign in to comment.