Skip to content

Commit

Permalink
chore(dropdown): Adding "Home" key functionality/"Up" key skipping he…
Browse files Browse the repository at this point in the history
…aders #984
  • Loading branch information
dafo committed Apr 24, 2018
1 parent 203e31b commit 914123b
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/drop-down/dropDown.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ export class IgxDropDownComponent implements OnInit, AfterViewInit {
public onArrowUpKeyDown(event) {
if (this._focusedItem) {
let focusedItemIndex = this._focusedItem.index;
while ((this.items.toArray()[focusedItemIndex - 1]) && (this.items.toArray()[focusedItemIndex - 1]).isDisabled) {
while ((this.items.toArray()[focusedItemIndex - 1]) &&
(this.items.toArray()[focusedItemIndex - 1].isDisabled || this.items.toArray()[focusedItemIndex - 1].isHeader)) {
focusedItemIndex--;
}
if (focusedItemIndex > 0) {
Expand All @@ -129,7 +130,7 @@ export class IgxDropDownComponent implements OnInit, AfterViewInit {
@HostListener("keydown.End", ["$event"])
public onEndKeyDown(event) {
let focusedItemIndex = (this.items.length - 1);
while ((this.items.toArray()[focusedItemIndex]) && ((this.items.toArray()[focusedItemIndex]).isDisabled
while ((this.items.toArray()[focusedItemIndex]) && ((this.items.toArray()[focusedItemIndex]).isDisabled
|| (this.items.toArray()[focusedItemIndex]).isHeader)) {
focusedItemIndex--;
}
Expand All @@ -147,6 +148,27 @@ export class IgxDropDownComponent implements OnInit, AfterViewInit {
}
}

@HostListener("keydown.Home", ["$event"])
public onHomeKeyDown(event) {
let focusedItemIndex = 0;
while ((this.items.toArray()[focusedItemIndex]) && ((this.items.toArray()[focusedItemIndex]).isDisabled
|| (this.items.toArray()[focusedItemIndex]).isHeader)) {
focusedItemIndex++;
}
if (focusedItemIndex < this.items.length - 1) {
if (this._focusedItem) {
this._focusedItem.isFocused = false;
}
this._focusedItem = this.items.toArray()[focusedItemIndex];
this._focusedItem.isFocused = true;
}
const rect = this._focusedItem.element.nativeElement.getBoundingClientRect();
const parentRect = this.toggle.element.getBoundingClientRect();
if (parentRect.top > rect.top) {
this.toggle.element.scrollTop -= (parentRect.top - rect.bottom + rect.height);
}
}

ngOnInit() {
this.toggleAction.target = this.toggle;
this.toggleAction.closeOnOutsideClick = true;
Expand Down

0 comments on commit 914123b

Please sign in to comment.