diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-01-25 16:32:06 +0100 |
---|---|---|
committer | Rigel Kent <sendmemail@rigelk.eu> | 2020-02-13 16:32:21 +0100 |
commit | 6af662a5961b48ac12682df2b8b971060a2cc67d (patch) | |
tree | de1efc71cbe8543b5b832e5de99a407a54c37220 /client/src/app/header/suggestions.component.ts | |
parent | f409f0c3b91d85c66b4841d72ea65b5fbe1483d8 (diff) | |
download | PeerTube-6af662a5961b48ac12682df2b8b971060a2cc67d.tar.gz PeerTube-6af662a5961b48ac12682df2b8b971060a2cc67d.tar.zst PeerTube-6af662a5961b48ac12682df2b8b971060a2cc67d.zip |
Add keyboard navigation and hepler to typeahead
Diffstat (limited to 'client/src/app/header/suggestions.component.ts')
-rw-r--r-- | client/src/app/header/suggestions.component.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/client/src/app/header/suggestions.component.ts b/client/src/app/header/suggestions.component.ts new file mode 100644 index 000000000..122c09388 --- /dev/null +++ b/client/src/app/header/suggestions.component.ts | |||
@@ -0,0 +1,31 @@ | |||
1 | import { Input, QueryList, Component, Output, AfterViewInit, EventEmitter, ViewChildren } from '@angular/core' | ||
2 | import { SuggestionComponent } from './suggestion.component' | ||
3 | |||
4 | @Component({ | ||
5 | selector: 'my-suggestions', | ||
6 | template: ` | ||
7 | <ul role="listbox" class="p-0 m-0"> | ||
8 | <li *ngFor="let result of results; let i = index" class="d-flex flex-justify-start flex-items-center p-0 f5" | ||
9 | role="option" aria-selected="true" (mouseenter)="hoverItem(i)"> | ||
10 | <my-suggestion [result]="result" [highlight]="highlight"></my-suggestion> | ||
11 | </li> | ||
12 | </ul> | ||
13 | ` | ||
14 | }) | ||
15 | export class SuggestionsComponent implements AfterViewInit { | ||
16 | @Input() results: any[] | ||
17 | @Input() highlight: string | ||
18 | @ViewChildren(SuggestionComponent) listItems: QueryList<SuggestionComponent> | ||
19 | @Output() init = new EventEmitter() | ||
20 | |||
21 | ngAfterViewInit () { | ||
22 | this.init.emit({ items: this.listItems }) | ||
23 | this.listItems.changes.subscribe( | ||
24 | val => this.init.emit({ items: this.listItems }) | ||
25 | ) | ||
26 | } | ||
27 | |||
28 | hoverItem (index: number) { | ||
29 | this.init.emit({ items: this.listItems, index: index }) | ||
30 | } | ||
31 | } | ||