]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-forms/input-toggle-hidden.component.ts
Fix some accessibility issues
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-forms / input-toggle-hidden.component.ts
CommitLineData
f8b530e0
RK
1import { Component, forwardRef, Input } from '@angular/core'
2import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
3import { Notifier } from '@app/core'
4
5@Component({
6 selector: 'my-input-toggle-hidden',
7 templateUrl: './input-toggle-hidden.component.html',
8 styleUrls: [ './input-toggle-hidden.component.scss' ],
9 providers: [
10 {
11 provide: NG_VALUE_ACCESSOR,
12 useExisting: forwardRef(() => InputToggleHiddenComponent),
13 multi: true
14 }
15 ]
16})
17export class InputToggleHiddenComponent implements ControlValueAccessor {
1916c966 18 @Input() inputId = Math.random().toString(11).slice(2, 8) // id cannot be left empty or undefined
f8b530e0
RK
19 @Input() value = ''
20 @Input() autocomplete = 'off'
21 @Input() placeholder = ''
23cd3129 22 @Input() tabindex = 0
f8b530e0
RK
23 @Input() withToggle = true
24 @Input() withCopy = false
25 @Input() readonly = false
26 @Input() show = false
27
28 constructor (private notifier: Notifier) { }
29
30 get inputType () {
31 return this.show
32 ? 'text'
33 : 'password'
34 }
35
36 get toggleTitle () {
37 return this.show
38 ? $localize`Hide`
39 : $localize`Show`
40 }
41
42 toggle () {
43 this.show = !this.show
44 }
45
46 activateCopiedMessage () {
47 this.notifier.success($localize`Copied`)
48 }
49
50 propagateChange = (_: any) => { /* empty */ }
51
52 writeValue (value: string) {
53 this.value = value
54 }
55
56 registerOnChange (fn: (_: any) => void) {
57 this.propagateChange = fn
58 }
59
60 registerOnTouched () {
61 // Unused
62 }
63
64 update () {
65 this.propagateChange(this.value)
66 }
67}