Skip to content

Commit

Permalink
fix: scroll to top should activate the first category
Browse files Browse the repository at this point in the history
  • Loading branch information
scttcper committed Apr 13, 2018
1 parent a29514d commit 2768d0d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/lib/picker/picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class PickerComponent implements OnInit, AfterViewInit {
@Input() emoji = 'department_store';
@Input() color = '#ae65c5';
@Input() hideObsolete = true;
/** all categories */
/** all categories shown */
@Input() categories: EmojiCategory[] = [];
/** used to temporarily draw categories */
@Input() activeCategories: EmojiCategory[] = [];
Expand Down Expand Up @@ -276,17 +276,21 @@ export class PickerComponent implements OnInit, AfterViewInit {
} else {
const target = this.scrollRef.nativeElement;
// check scroll is not at bottom
if (target.scrollHeight - target.scrollTop !== this.clientHeight) {
if (target.scrollTop === 0) {
// hit the TOP
activeCategory = this.categories.find(n => n.first === true);
} else if (target.scrollHeight - target.scrollTop === this.clientHeight) {
// scrolled to bottom activate last category
activeCategory = this.categories[this.categories.length - 1];
} else {
// scrolling
for (const category of this.categories) {
const component = this.categoryRefs!.find(n => n.id === category.id);
const active = component!.handleScroll(target.scrollTop);
if (active) {
activeCategory = category;
}
}
} else {
// scrolled to bottom activate last category
activeCategory = this.categories[this.categories.length - 1];
}

this.scrollTop = target.scrollTop;
Expand Down

0 comments on commit 2768d0d

Please sign in to comment.