mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 15:23:33 +00:00
Extract core functionality from `libs/angular` to allow teams to depend on `libs/ui-common` instead. Moves the following functionality to `ui-common`. - `I18nPipe`. `libs/angular` still has an old copy but `components` depends on the new variant from `ui-common`. - `safeProvider`, `SafeProvider` and `SafeInjectionToken`. `libs/angular`re-exports these to avoid needing to update all consumers.
83 lines
2.0 KiB
TypeScript
83 lines
2.0 KiB
TypeScript
// FIXME: Update this file to be type safe and remove this and next line
|
|
// @ts-strict-ignore
|
|
import { Component, ElementRef, Input, ViewChild } from "@angular/core";
|
|
import {
|
|
ControlValueAccessor,
|
|
NG_VALUE_ACCESSOR,
|
|
ReactiveFormsModule,
|
|
FormsModule,
|
|
} from "@angular/forms";
|
|
|
|
import { isBrowserSafariApi } from "@bitwarden/platform";
|
|
import { I18nPipe } from "@bitwarden/ui-common";
|
|
|
|
import { InputModule } from "../input/input.module";
|
|
import { FocusableElement } from "../shared/focusable-element";
|
|
|
|
let nextId = 0;
|
|
|
|
@Component({
|
|
selector: "bit-search",
|
|
templateUrl: "./search.component.html",
|
|
providers: [
|
|
{
|
|
provide: NG_VALUE_ACCESSOR,
|
|
multi: true,
|
|
useExisting: SearchComponent,
|
|
},
|
|
{
|
|
provide: FocusableElement,
|
|
useExisting: SearchComponent,
|
|
},
|
|
],
|
|
standalone: true,
|
|
imports: [InputModule, ReactiveFormsModule, FormsModule, I18nPipe],
|
|
})
|
|
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;
|
|
// Use `type="text"` for Safari to improve rendering performance
|
|
protected inputType = isBrowserSafariApi() ? ("text" as const) : ("search" as const);
|
|
|
|
@Input() disabled: boolean;
|
|
@Input() placeholder: string;
|
|
@Input() autocomplete: string;
|
|
|
|
getFocusTarget() {
|
|
return this.input.nativeElement;
|
|
}
|
|
|
|
onChange(searchText: string) {
|
|
if (this.notifyOnChange != undefined) {
|
|
this.notifyOnChange(searchText);
|
|
}
|
|
}
|
|
|
|
onTouch() {
|
|
if (this.notifyOnTouch != undefined) {
|
|
this.notifyOnTouch();
|
|
}
|
|
}
|
|
|
|
registerOnChange(fn: (v: string) => void): void {
|
|
this.notifyOnChange = fn;
|
|
}
|
|
|
|
registerOnTouched(fn: () => void): void {
|
|
this.notifyOnTouch = fn;
|
|
}
|
|
|
|
writeValue(searchText: string): void {
|
|
this.searchText = searchText;
|
|
}
|
|
|
|
setDisabledState(isDisabled: boolean) {
|
|
this.disabled = isDisabled;
|
|
}
|
|
}
|