MCPcopy Create free account
hub / github.com/angular/components / Dir

Class Dir

src/cdk/bidi/dir.ts:33–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31 exportAs: 'dir',
32})
33export class Dir implements Directionality, AfterContentInit, OnDestroy {
34 /** Whether the `value` has been set to its initial value. */
35 private _isInitialized: boolean = false;
36
37 /** Direction as passed in by the consumer. */
38 _rawDir: string = '';
39
40 /** Event emitted when the direction changes. */
41 @Output('dirChange') readonly change = new EventEmitter<Direction>();
42
43 /** @docs-private */
44 @Input()
45 get dir(): Direction {
46 return this.valueSignal();
47 }
48 set dir(value: Direction | 'auto') {
49 const previousValue = this.valueSignal();
50
51 // Note: `_resolveDirectionality` resolves the language based on the browser's language,
52 // whereas the browser does it based on the content of the element. Since doing so based
53 // on the content can be expensive, for now we're doing the simpler matching.
54 this.valueSignal.set(_resolveDirectionality(value));
55 this._rawDir = value;
56
57 if (previousValue !== this.valueSignal() && this._isInitialized) {
58 this.change.emit(this.valueSignal());
59 }
60 }
61
62 /** Current layout direction of the element. */
63 get value(): Direction {
64 return this.dir;
65 }
66
67 readonly valueSignal = signal<Direction>('ltr');
68
69 /** Initialize once default value has been set. */
70 ngAfterContentInit() {
71 this._isInitialized = true;
72 }
73
74 ngOnDestroy() {
75 this.change.complete();
76 }
77}

Callers

nothing calls this directly

Calls 1

signalFunction · 0.85

Tested by

no test coverage detected