-
Notifications
You must be signed in to change notification settings - Fork 40
/
link.component.ts
84 lines (69 loc) · 1.95 KB
/
link.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {
Input,
Attribute,
Component,
ElementRef,
OnDestroy,
ViewEncapsulation,
ChangeDetectionStrategy,
ChangeDetectorRef
} from '@angular/core';
import { FocusMonitor } from '@ptsecurity/cdk/a11y';
import {
CanDisable, CanDisableCtor,
HasTabIndex, HasTabIndexCtor,
mixinDisabled,
mixinTabIndex,
toBoolean
} from '@ptsecurity/mosaic/core';
export class McLinkBase {
constructor(public _elementRef: ElementRef) {
}
}
export const _McLinkBase: HasTabIndexCtor & CanDisableCtor & typeof McLinkBase
= mixinTabIndex(mixinDisabled(McLinkBase));
@Component({
selector: 'a.mc-link',
template: `<ng-content></ng-content>`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
exportAs: 'mcLink',
styleUrls: ['./link.css'],
inputs: ['disabled'],
host: {
'[attr.disabled]': 'disabled || null',
'[attr.tabindex]': 'tabIndex'
}
})
export class McLink extends _McLinkBase implements OnDestroy, HasTabIndex, CanDisable {
@Input()
get disabled() {
return this._disabled;
}
set disabled(value: any) {
const newValue = toBoolean(value);
if (newValue !== this._disabled) {
this._disabled = newValue;
this._changeDetector.markForCheck();
}
}
private _disabled = false;
constructor(
@Attribute('tabindex') tabIndex: string,
public elementRef: ElementRef,
private _focusMonitor: FocusMonitor,
private _changeDetector: ChangeDetectorRef) {
super(elementRef);
this._focusMonitor.monitor(elementRef.nativeElement, true);
this.tabIndex = parseInt(tabIndex) || 0;
}
ngOnDestroy() {
this._focusMonitor.stopMonitoring(this.elementRef.nativeElement);
}
focus(): void {
this._getHostElement().focus();
}
_getHostElement() {
return this.elementRef.nativeElement;
}
}