( props: AriaTreeItemOptions, state: TreeState<T>, ref: RefObject<FocusableElement | null> )
| 49 | * @param ref - The ref attached to the row element. |
| 50 | */ |
| 51 | export 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 | } |
no test coverage detected