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

Function useTable

packages/react-aria/src/table/useTable.ts:64–150  ·  view source on GitHub ↗
(
  props: AriaTableProps,
  state: TableState<T> | TreeGridState<T>,
  ref: RefObject<HTMLElement | null>
)

Source from the content-addressed store, hash-verified

62 * @param ref - The ref attached to the table element.
63 */
64export function useTable<T>(
65 props: AriaTableProps,
66 state: TableState<T> | TreeGridState<T>,
67 ref: RefObject<HTMLElement | null>
68): GridAria {
69 let {keyboardDelegate, isVirtualized, layoutDelegate, layout} = props;
70
71 // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
72 // When virtualized, the layout object will be passed in as a prop and override this.
73 let collator = useCollator({usage: 'search', sensitivity: 'base'});
74 let {direction} = useLocale();
75 let disabledBehavior = state.selectionManager.disabledBehavior;
76 let delegate = useMemo(
77 () =>
78 keyboardDelegate ||
79 new TableKeyboardDelegate({
80 collection: state.collection,
81 disabledKeys: state.disabledKeys,
82 disabledBehavior,
83 ref,
84 direction,
85 collator,
86 layoutDelegate,
87 layout
88 }),
89 [
90 keyboardDelegate,
91 state.collection,
92 state.disabledKeys,
93 disabledBehavior,
94 ref,
95 direction,
96 collator,
97 layoutDelegate,
98 layout
99 ]
100 );
101 let id = useId(props.id);
102 gridIds.set(state as TableState<T>, id);
103
104 let {gridProps} = useGrid(
105 {
106 ...props,
107 id,
108 keyboardDelegate: delegate
109 },
110 state,
111 ref
112 );
113
114 // Override to include header rows
115 if (isVirtualized) {
116 gridProps['aria-rowcount'] = state.collection.size + state.collection.headerRows.length;
117 }
118
119 if (state.treeColumn != null) {
120 gridProps.role = 'treegrid';
121 }

Callers 8

TableFunction · 0.90
TableFunction · 0.90
TableFunction · 0.90
TableFunction · 0.90
TableFunction · 0.90
TableFunction · 0.90
TableInnerFunction · 0.90
TableViewBaseFunction · 0.90

Calls 12

useCollatorFunction · 0.90
useLocaleFunction · 0.90
useIdFunction · 0.90
useGridFunction · 0.90
useDescriptionFunction · 0.90
useUpdateEffectFunction · 0.90
announceFunction · 0.90
mergePropsFunction · 0.90
filterMethod · 0.65
setMethod · 0.45
formatMethod · 0.45

Tested by 2

TableFunction · 0.72
TableFunction · 0.72