1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

[CL-161] Update bit-search support autofocus (#7272)

appAutofocus currently doesn't work on the bit-search component. This PR resolves this issue by introducing a FocusableElement interface components can implement, which is respected by the autofocus directive.
This commit is contained in:
Oscar Hinton
2024-01-11 16:52:22 +01:00
committed by GitHub
parent 7112f44375
commit 280cb7e2c0
6 changed files with 72 additions and 33 deletions

View File

@@ -8,6 +8,7 @@
<i class="bwi bwi-search bwi-fw tw-text-muted"></i>
</label>
<input
#input
bitInput
type="search"
[id]="id"

View File

@@ -1,6 +1,8 @@
import { Component, Input } from "@angular/core";
import { Component, ElementRef, Input, ViewChild } from "@angular/core";
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from "@angular/forms";
import { FocusableElement } from "../input/autofocus.directive";
let nextId = 0;
@Component({
@@ -12,18 +14,28 @@ let nextId = 0;
multi: true,
useExisting: SearchComponent,
},
{
provide: FocusableElement,
useExisting: SearchComponent,
},
],
})
export class SearchComponent implements ControlValueAccessor {
export class SearchComponent implements ControlValueAccessor, FocusableElement {
private notifyOnChange: (v: string) => void;
private notifyOnTouch: () => void;
@ViewChild("input") private input: ElementRef<HTMLInputElement>;
protected id = `search-id-${nextId++}`;
protected searchText: string;
@Input() disabled: boolean;
@Input() placeholder: string;
focus() {
this.input.nativeElement.focus();
}
onChange(searchText: string) {
if (this.notifyOnChange != undefined) {
this.notifyOnChange(searchText);