toggle.ts (material2-7.3.4) | : | toggle.ts (material2-7.3.5) | ||
---|---|---|---|---|
/** | /** | |||
* @license | * @license | |||
* Copyright Google LLC All Rights Reserved. | * Copyright Google LLC All Rights Reserved. | |||
* | * | |||
* Use of this source code is governed by an MIT-style license that can be | * Use of this source code is governed by an MIT-style license that can be | |||
* found in the LICENSE file at https://angular.io/license | * found in the LICENSE file at https://angular.io/license | |||
*/ | */ | |||
import {coerceBooleanProperty} from '@angular/cdk/coercion'; | import {coerceBooleanProperty} from '@angular/cdk/coercion'; | |||
import { | import {Directive, HostListener, Input} from '@angular/core'; | |||
Directive, | ||||
Input, | ||||
} from '@angular/core'; | ||||
import {CdkTree, CdkTreeNode} from './tree'; | import {CdkTree, CdkTreeNode} from './tree'; | |||
/** | /** | |||
* Node toggle to expand/collapse the node. | * Node toggle to expand/collapse the node. | |||
*/ | */ | |||
@Directive({ | @Directive({selector: '[cdkTreeNodeToggle]'}) | |||
selector: '[cdkTreeNodeToggle]', | ||||
host: { | ||||
'(click)': '_toggle($event)', | ||||
} | ||||
}) | ||||
export class CdkTreeNodeToggle<T> { | export class CdkTreeNodeToggle<T> { | |||
/** Whether expand/collapse the node recursively. */ | /** Whether expand/collapse the node recursively. */ | |||
@Input('cdkTreeNodeToggleRecursive') | @Input('cdkTreeNodeToggleRecursive') | |||
get recursive(): boolean { return this._recursive; } | get recursive(): boolean { return this._recursive; } | |||
set recursive(value: boolean) { this._recursive = coerceBooleanProperty(value) ; } | set recursive(value: boolean) { this._recursive = coerceBooleanProperty(value) ; } | |||
protected _recursive = false; | protected _recursive = false; | |||
constructor(protected _tree: CdkTree<T>, | constructor(protected _tree: CdkTree<T>, | |||
protected _treeNode: CdkTreeNode<T>) {} | protected _treeNode: CdkTreeNode<T>) {} | |||
// We have to use a `HostListener` here in order to support both Ivy and ViewE | ||||
ngine. | ||||
// In Ivy the `host` bindings will be merged when this class is extended, wher | ||||
eas in | ||||
// ViewEngine they're overwritten. | ||||
// TODO(crisbeto): we move this back into `host` once Ivy is turned on by defa | ||||
ult. | ||||
// tslint:disable-next-line:no-host-decorator-in-concrete | ||||
@HostListener('click', ['$event']) | ||||
_toggle(event: Event): void { | _toggle(event: Event): void { | |||
this.recursive | this.recursive | |||
? this._tree.treeControl.toggleDescendants(this._treeNode.data) | ? this._tree.treeControl.toggleDescendants(this._treeNode.data) | |||
: this._tree.treeControl.toggle(this._treeNode.data); | : this._tree.treeControl.toggle(this._treeNode.data); | |||
event.stopPropagation(); | event.stopPropagation(); | |||
} | } | |||
} | } | |||
End of changes. 3 change blocks. | ||||
10 lines changed or deleted | 12 lines changed or added |