|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2025 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +import type {IFocusableNode} from './i_focusable_node.js'; |
| 8 | + |
| 9 | +/** |
| 10 | + * Represents a tree of focusable elements with its own active/passive focus |
| 11 | + * context. |
| 12 | + * |
| 13 | + * Note that focus is handled by FocusManager, and tree implementations can have |
| 14 | + * at most one IFocusableNode focused at one time. If the tree itself has focus, |
| 15 | + * then the tree's focused node is considered 'active' ('passive' if another |
| 16 | + * tree has focus). |
| 17 | + * |
| 18 | + * Focus is shared between one or more trees, where each tree can have exactly |
| 19 | + * one active or passive node (and only one active node can exist on the whole |
| 20 | + * page at any given time). The idea of passive focus is to provide context to |
| 21 | + * users on where their focus will be restored upon navigating back to a |
| 22 | + * previously focused tree. |
| 23 | + */ |
| 24 | +export interface IFocusableTree { |
| 25 | + /** |
| 26 | + * Returns the current node with focus in this tree, or null if none (or if |
| 27 | + * the root has focus). |
| 28 | + * |
| 29 | + * Note that this will never return a node from a nested sub-tree as that tree |
| 30 | + * should specifically be called in order to retrieve its focused node. |
| 31 | + */ |
| 32 | + getFocusedNode(): IFocusableNode | null; |
| 33 | + |
| 34 | + /** |
| 35 | + * Returns the top-level focusable node of the tree. |
| 36 | + * |
| 37 | + * It's expected that the returned node will be focused in cases where |
| 38 | + * FocusManager wants to focus a tree in a situation where it does not |
| 39 | + * currently have a focused node. |
| 40 | + */ |
| 41 | + getRootFocusableNode(): IFocusableNode; |
| 42 | + |
| 43 | + /** |
| 44 | + * Returns the IFocusableNode corresponding to the select element, or null if |
| 45 | + * the element does not have such a node. |
| 46 | + * |
| 47 | + * The provided element must have a non-null ID that conforms to the contract |
| 48 | + * mentioned in IFocusableNode. |
| 49 | + */ |
| 50 | + findFocusableNodeFor( |
| 51 | + element: HTMLElement | SVGElement, |
| 52 | + ): IFocusableNode | null; |
| 53 | +} |
0 commit comments