MCPcopy Index your code
hub / github.com/adobe/react-spectrum / useTreeItem

Function useTreeItem

packages/react-aria/src/tree/useTreeItem.ts:51–86  ·  view source on GitHub ↗
(
  props: AriaTreeItemOptions,
  state: TreeState<T>,
  ref: RefObject<FocusableElement | null>
)

Source from the content-addressed store, hash-verified

49 * @param ref - The ref attached to the row element.
50 */
51export function useTreeItem<T>(
52 props: AriaTreeItemOptions,
53 state: TreeState<T>,
54 ref: RefObject<FocusableElement | null>
55): TreeItemAria {
56 let {node} = props;
57 let gridListAria = useGridListItem(props, state, ref);
58 let isExpanded = gridListAria.rowProps['aria-expanded'] === true;
59 let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/tree');
60 let labelProps = useLabels({
61 'aria-label': isExpanded
62 ? stringFormatter.format('collapse')
63 : stringFormatter.format('expand'),
64 'aria-labelledby': gridListAria.rowProps.id
65 });
66
67 let expandButtonProps = {
68 onPress: () => {
69 if (!gridListAria.isDisabled) {
70 state.toggleKey(node.key);
71 state.selectionManager.setFocused(true);
72 state.selectionManager.setFocusedKey(node.key);
73 }
74 },
75 excludeFromTabOrder: true,
76 preventFocusOnPress: true,
77 'data-react-aria-prevent-focus': true,
78 ...labelProps
79 };
80
81 // TODO: should it return a state specifically for isExpanded? Or is aria attribute sufficient?
82 return {
83 ...gridListAria,
84 expandButtonProps
85 };
86}

Callers 1

Tree.tsxFile · 0.90

Calls 7

useGridListItemFunction · 0.90
useLabelsFunction · 0.90
toggleKeyMethod · 0.65
setFocusedMethod · 0.65
setFocusedKeyMethod · 0.65
formatMethod · 0.45

Tested by

no test coverage detected