/
githubmirror
/
components
Обзор
Документация
Войти
/
githubmirror
/
components
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/cdk/tree/toggle.ts
46 строк
1 KB
Cheng-Hsuan Tsai
fix(cdk/tree): enter/space key on child node should not toggle parent node expansion (#33125)
24 апр 2026, 16:13
Не верифицирован
24 апр 2026, 16:13
b916ef9
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {Directive, Input, booleanAttribute, inject} from '@angular/core'; import {CdkTree, CdkTreeNode} from './tree'; /** * Node toggle to expand and collapse the node. */ @Directive({ selector: '[cdkTreeNodeToggle]', host: { '(click)': '_toggle($event)', '(keydown.Enter)': '_toggle($event); $event.preventDefault();', '(keydown.Space)': '_toggle($event); $event.preventDefault();', 'tabindex': '-1', }, }) export class CdkTreeNodeToggle<T, K = T> { protected _tree = inject<CdkTree<T, K>>(CdkTree); protected _treeNode = inject<CdkTreeNode<T, K>>(CdkTreeNode); /** Whether expand/collapse the node recursively. */ @Input({alias: 'cdkTreeNodeToggleRecursive', transform: booleanAttribute}) recursive: boolean = false; // Toggle the expanded or collapsed state of this node. // // Focus this node with expanding or collapsing it. This ensures that the active node will always // be visible when expanding and collapsing. _toggle(event: Event): void { event.stopPropagation(); this.recursive ? this._tree.toggleDescendants(this._treeNode.data) : this._tree.toggle(this._treeNode.data); this._tree._keyManager.focusItem(this._treeNode); } }