1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
---|
9 | import { Directive, HostListener, Input } from '@angular/core';
|
---|
10 | import { CdkTree, CdkTreeNode } from './tree';
|
---|
11 | /**
|
---|
12 | * Node toggle to expand/collapse the node.
|
---|
13 | */
|
---|
14 | export class CdkTreeNodeToggle {
|
---|
15 | constructor(_tree, _treeNode) {
|
---|
16 | this._tree = _tree;
|
---|
17 | this._treeNode = _treeNode;
|
---|
18 | this._recursive = false;
|
---|
19 | }
|
---|
20 | /** Whether expand/collapse the node recursively. */
|
---|
21 | get recursive() { return this._recursive; }
|
---|
22 | set recursive(value) { this._recursive = coerceBooleanProperty(value); }
|
---|
23 | // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
|
---|
24 | // In Ivy the `host` bindings will be merged when this class is extended, whereas in
|
---|
25 | // ViewEngine they're overwritten.
|
---|
26 | // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default.
|
---|
27 | // tslint:disable-next-line:no-host-decorator-in-concrete
|
---|
28 | _toggle(event) {
|
---|
29 | this.recursive
|
---|
30 | ? this._tree.treeControl.toggleDescendants(this._treeNode.data)
|
---|
31 | : this._tree.treeControl.toggle(this._treeNode.data);
|
---|
32 | event.stopPropagation();
|
---|
33 | }
|
---|
34 | }
|
---|
35 | CdkTreeNodeToggle.decorators = [
|
---|
36 | { type: Directive, args: [{ selector: '[cdkTreeNodeToggle]' },] }
|
---|
37 | ];
|
---|
38 | CdkTreeNodeToggle.ctorParameters = () => [
|
---|
39 | { type: CdkTree },
|
---|
40 | { type: CdkTreeNode }
|
---|
41 | ];
|
---|
42 | CdkTreeNodeToggle.propDecorators = {
|
---|
43 | recursive: [{ type: Input, args: ['cdkTreeNodeToggleRecursive',] }],
|
---|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