MCPcopy Create free account
hub / github.com/adobe/react-spectrum / toggleKey

Function toggleKey

packages/react-stately/src/table/useTreeGridState.ts:113–139  ·  view source on GitHub ↗
(
  currentExpandedKeys: 'all' | Set<Key>,
  key: Key,
  collection: TreeGridCollection<T>
)

Source from the content-addressed store, hash-verified

111}
112
113function toggleKey<T>(
114 currentExpandedKeys: 'all' | Set<Key>,
115 key: Key,
116 collection: TreeGridCollection<T>
117): Set<Key> {
118 let updatedExpandedKeys: Set<Key>;
119 if (currentExpandedKeys === 'all') {
120 updatedExpandedKeys = new Set(
121 collection.flattenedRows
122 .filter(
123 row =>
124 row.props.UNSTABLE_childItems || row.props.children.length > collection.userColumnCount
125 )
126 .map(row => row.key)
127 );
128 updatedExpandedKeys.delete(key);
129 } else {
130 updatedExpandedKeys = new Set(currentExpandedKeys);
131 if (updatedExpandedKeys.has(key)) {
132 updatedExpandedKeys.delete(key);
133 } else {
134 updatedExpandedKeys.add(key);
135 }
136 }
137
138 return updatedExpandedKeys;
139}
140
141function convertExpanded(expanded: 'all' | Iterable<Key>): 'all' | Set<Key> {
142 if (!expanded) {

Callers 1

onToggleFunction · 0.70

Calls 4

deleteMethod · 0.80
filterMethod · 0.65
hasMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected