Skip to content

Commit

Permalink
fix(tree): replacing mixins with methods (#UIM-129) (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
lskramarov authored and pimenovoleg committed Aug 13, 2019
1 parent 4f5cc53 commit 46de5c2
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions packages/mosaic/tree/tree-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ import {
import { CdkTree, CdkTreeNodeOutlet } from '@ptsecurity/cdk/tree';
import {
CanDisable,
CanDisableCtor,
HasTabIndex,
HasTabIndexCtor,
mixinDisabled,
mixinTabIndex,
toBoolean
} from '@ptsecurity/mosaic/core';
import { Subject } from 'rxjs';
Expand All @@ -59,16 +55,6 @@ export class McTreeSelectionChange {
constructor(public source: McTreeSelection, public option: McTreeOption) {}
}

class McTreeSelectionBase<T> extends CdkTree<T> {
constructor(differs: IterableDiffers, changeDetectorRef: ChangeDetectorRef) {
super(differs, changeDetectorRef);
}
}

/* tslint:disable-next-line:naming-convention */
const McTreeSelectionBaseMixin: HasTabIndexCtor & CanDisableCtor &
typeof McTreeSelectionBase = mixinTabIndex(mixinDisabled(McTreeSelectionBase));


@Component({
selector: 'mc-tree-selection',
Expand All @@ -90,7 +76,7 @@ const McTreeSelectionBaseMixin: HasTabIndexCtor & CanDisableCtor &
{ provide: CdkTree, useExisting: McTreeSelection }
]
})
export class McTreeSelection extends McTreeSelectionBaseMixin<McTreeOption>
export class McTreeSelection extends CdkTree<any>
implements ControlValueAccessor, AfterContentInit, CanDisable, HasTabIndex {

@ViewChild(CdkTreeNodeOutlet, { static: true }) nodeOutlet: CdkTreeNodeOutlet;
Expand All @@ -101,7 +87,6 @@ export class McTreeSelection extends McTreeSelectionBaseMixin<McTreeOption>

selectionModel: SelectionModel<any>;

tabIndex: number;
multiple: boolean;
autoSelect: boolean;
noUnselectLastSelected: boolean;
Expand Down Expand Up @@ -133,14 +118,24 @@ export class McTreeSelection extends McTreeSelectionBaseMixin<McTreeOption>

private _disabled: boolean = false;

@Input()
get tabIndex(): number {
return this.disabled ? -1 : this._tabIndex;
}

set tabIndex(value: number) {
this._tabIndex = value != null ? value : 0;
}

private _tabIndex: number;

private readonly destroy = new Subject<void>();

constructor(
private elementRef: ElementRef,
differs: IterableDiffers,
changeDetectorRef: ChangeDetectorRef,
@Self() @Optional() public ngControl: NgControl,
@Attribute('tabindex') tabIndex: string,
@Attribute('multiple') multiple: string,
@Attribute('auto-select') autoSelect: string,
@Attribute('no-unselect') noUnselect: string
Expand All @@ -153,8 +148,6 @@ export class McTreeSelection extends McTreeSelectionBaseMixin<McTreeOption>
this.ngControl.valueAccessor = this;
}

this.tabIndex = parseInt(tabIndex) || 0;

this.multiple = multiple === null ? false : toBoolean(multiple);
this.autoSelect = autoSelect === null ? true : toBoolean(autoSelect);
this.noUnselectLastSelected = noUnselect === null ? true : toBoolean(noUnselect);
Expand Down

0 comments on commit 46de5c2

Please sign in to comment.