Skip to content

Commit

Permalink
fix(dropdown): starts with search and clear active when hiding
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Godi committed Jun 21, 2017
1 parent 08bc5af commit 191204c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 6 additions & 6 deletions demo/pages/elements/dropdown/templates/DropdownDemo.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<button type="button" theme="secondary" icon="collapse" inverse>Actions</button>
<list>
<dropdown-item-header>Section 1</dropdown-item-header>
<item (action)="clickMe('Hello!')">Action 1</item>
<item (action)="clickMe('Another!')">Action 2</item>
<item tooltip="Test tooltip :)" tooltipPosition="right" [disabled]="true" (action)="clickMe()">Action 3</item>
<item (action)="clickMe('Hello!')">Test</item>
<item (action)="clickMe('Another!')">Josh</item>
<item tooltip="Test tooltip :)" tooltipPosition="right" [disabled]="true" (action)="clickMe()">Poop</item>
<dropdown-item-header>Section 2</dropdown-item-header>
<item (action)="clickMe('Hello!')">Action 4</item>
<item (action)="clickMe('Another!')">Action 5</item>
<item tooltip="Test tooltip :)" tooltipPosition="right" [disabled]="true" (action)="clickMe()">Action 6</item>
<item (action)="clickMe('Hello!')">Germany</item>
<item (action)="clickMe('Another!')">Algerbra</item>
<item tooltip="Test tooltip :)" tooltipPosition="right" [disabled]="true" (action)="clickMe()">Blah</item>
</list>
</novo-dropdown>
<novo-dropdown side="right">
Expand Down
7 changes: 6 additions & 1 deletion src/elements/dropdown/Dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ export class NovoDropdownElement extends OutsideClick implements OnInit, OnDestr
this.parentScrollElement.removeEventListener('scroll', this.closeHandler);
}
}
// Clear active index
if (this.activeIndex !== -1) {
this._items.toArray()[this.activeIndex].active = false;
}
this.activeIndex = -1;
}

@HostListener('keydown', ['$event'])
Expand Down Expand Up @@ -234,7 +239,7 @@ export class NovoDropdownElement extends OutsideClick implements OnInit, OnDestr
let char = String.fromCharCode(event.keyCode);
this.filterTerm = this.filterTerm.concat(char);
let index = this._textItems.findIndex((value: string) => {
return value.toLocaleLowerCase().indexOf(this.filterTerm.toLowerCase()) !== -1;
return new RegExp(`^${this.filterTerm.toLowerCase()}`).test(value.toLocaleLowerCase());
});
if (index !== -1) {
if (this.activeIndex !== -1) {
Expand Down

0 comments on commit 191204c

Please sign in to comment.