Skip to content

Commit

Permalink
fix(link): rework attributes (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Norf-g authored and pimenovoleg committed Sep 4, 2018
1 parent 2971f19 commit 5d2e000
Showing 1 changed file with 51 additions and 7 deletions.
58 changes: 51 additions & 7 deletions src/lib/link/link.component.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,72 @@
import { Component, ElementRef, OnDestroy, ViewEncapsulation, ChangeDetectionStrategy } from '@angular/core';
import {
Input,
Attribute,
Component,
ElementRef,
OnDestroy,
ViewEncapsulation,
ChangeDetectionStrategy,
ChangeDetectorRef
} from '@angular/core';

import { FocusMonitor } from '@ptsecurity/cdk/a11y';
import {
CanDisable,
HasTabIndex,
mixinDisabled,
mixinTabIndex,
toBoolean
} from '@ptsecurity/mosaic/core';


export class McLinkBase {
constructor(public _elementRef: ElementRef) {
}
}

export const _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', 'tabindex'],
inputs: ['disabled'],
host: {
'[attr.disabled]': 'disabled || null',
'[attr.tabindex]': 'disabled ? -1 : tabindex ? tabindex : 0'
'[attr.tabindex]': 'tabIndex'
}
})

export class McLink implements OnDestroy {
disabled: boolean;
tabindex: number;
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(private elementRef: ElementRef, private _focusMonitor: FocusMonitor) {
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() {
Expand Down

0 comments on commit 5d2e000

Please sign in to comment.