-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(material/tree): Fix misc PR comments.
Fix miscellaneous PR comments. Take a first pass to fix comments that are easiest to fix. This commit message will be squashed away when merging. * move type definitions in tree-key-manager.ts to a new file, tree-key-manager-strategy.ts * remove unnecessary comment * fix JSDoc comment syntax * remove isNotNullish * consolidate event handling code in CdkTreeNodeToggle * remove unnecessary type coerscion * simply logic for detecting TreeControlMissingError and MultipleTreeControlsError * adopt Input transform * remove unnecessary nesting in _updateActiveItemIndex
- Loading branch information
Showing
11 changed files
with
252 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/** | ||
* @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.io/license | ||
*/ | ||
|
||
import {QueryList} from '@angular/core'; | ||
import {Observable, Subject} from 'rxjs'; | ||
|
||
/** Represents an item within a tree that can be passed to a TreeKeyManager. */ | ||
export interface TreeKeyManagerItem { | ||
/** Whether the item is disabled. */ | ||
isDisabled?: (() => boolean) | boolean; | ||
|
||
/** The user-facing label for this item. */ | ||
getLabel?(): string; | ||
|
||
/** Perform the main action (i.e. selection) for this item. */ | ||
activate(): void; | ||
|
||
/** Retrieves the parent for this item. This is `null` if there is no parent. */ | ||
getParent(): TreeKeyManagerItem | null; | ||
|
||
/** Retrieves the children for this item. */ | ||
getChildren(): TreeKeyManagerItem[] | Observable<TreeKeyManagerItem[]>; | ||
|
||
/** Determines if the item is currently expanded. */ | ||
isExpanded: (() => boolean) | boolean; | ||
|
||
/** Collapses the item, hiding its children. */ | ||
collapse(): void; | ||
|
||
/** Expands the item, showing its children. */ | ||
expand(): void; | ||
|
||
/** | ||
* Focuses the item. This should provide some indication to the user that this item is focused. | ||
*/ | ||
focus(): void; | ||
} | ||
|
||
/** | ||
* Configuration for the TreeKeyManager. | ||
*/ | ||
export interface TreeKeyManagerOptions<T extends TreeKeyManagerItem> { | ||
/** | ||
* If true, then the key manager will call `activate` in addition to calling `focus` when a | ||
* particular item is focused. By default, this is false. | ||
*/ | ||
activationFollowsFocus?: boolean; | ||
|
||
/** | ||
* The direction in which the tree items are laid out horizontally. This influences which key | ||
* will be interpreted as expand or collapse. Defaults to 'ltr'. | ||
*/ | ||
horizontalOrientation?: 'rtl' | 'ltr'; | ||
|
||
/** | ||
* Sets the predicate function that determines which items should be skipped by the tree key | ||
* manager. By default, disabled items are skipped. | ||
* | ||
* If the item is to be skipped, this function should return false. | ||
*/ | ||
skipPredicate?: (item: T) => boolean; | ||
|
||
/** | ||
* If provided, determines how the key manager determines if two items are equivalent. | ||
* | ||
* It should provide a unique key for each unique tree item. If two tree items are equivalent, | ||
* then this function should return the same value. | ||
*/ | ||
trackBy?: (treeItem: T) => unknown; | ||
|
||
/** | ||
* If a value is provided, enables typeahead mode, which allows users to set the active item | ||
* by typing the visible label of the item. | ||
* | ||
* If a number is provided, this will be the time to wait after the last keystroke before | ||
* setting the active item. If `true` is provided, the default interval of 200ms will be used. | ||
*/ | ||
typeAheadDebounceInterval?: true | number; | ||
} | ||
|
||
export interface TreeKeyManagerStrategy<T extends TreeKeyManagerItem> { | ||
/** Stream that emits any time the focused item changes. */ | ||
readonly change: Subject<T | null>; | ||
|
||
/** | ||
* Handles a keyboard event on the tree. | ||
* | ||
* @param event Keyboard event that represents the user interaction with the tree. | ||
*/ | ||
onKeydown(event: KeyboardEvent): void; | ||
|
||
/** Index of the currently active item. */ | ||
getActiveItemIndex(): number | null; | ||
|
||
/** The currently active item. */ | ||
getActiveItem(): T | null; | ||
|
||
/** | ||
* Called the first time the Tree component is focused. This method will only be called once over | ||
* the lifetime of the Tree component. | ||
* | ||
* Intended to be used to focus the first item in the tree. | ||
*/ | ||
onInitialFocus(): void; | ||
|
||
/** | ||
* Focus the provided item by index. | ||
* | ||
* Updates the state of the currently active item. Emits to `change` stream if active item | ||
* Changes. | ||
* @param index The index of the item to focus. | ||
* @param options Additional focusing options. | ||
*/ | ||
focusItem(index: number, options?: {emitChangeEvent?: boolean}): void; | ||
/** | ||
* Focus the provided item. | ||
* | ||
* Updates the state of the currently active item. Emits to `change` stream if active item | ||
* Changes. | ||
* @param item The item to focus. Equality is determined via the trackBy function. | ||
* @param options Additional focusing options. | ||
*/ | ||
focusItem(item: T, options?: {emitChangeEvent?: boolean}): void; | ||
focusItem(itemOrIndex: number | T, options?: {emitChangeEvent?: boolean}): void; | ||
} | ||
|
||
export type TreeKeyManagerFactory<T extends TreeKeyManagerItem> = ( | ||
items: Observable<T[]> | QueryList<T> | T[], | ||
options: TreeKeyManagerOptions<T>, | ||
) => TreeKeyManagerStrategy<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.