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

Function moveBefore

packages/react-stately/src/data/useListData.ts:341–355  ·  view source on GitHub ↗
(key: Key, keys: Iterable<Key>)

Source from the content-addressed store, hash-verified

339 });
340 },
341 moveBefore(key: Key, keys: Iterable<Key>) {
342 dispatch(state => {
343 let toIndex = state.items.findIndex(item => getKey!(item) === key);
344 if (toIndex === -1) {
345 return state;
346 }
347
348 // Find indices of keys to move. Sort them so that the order in the list is retained.
349 let keyArray = Array.isArray(keys) ? keys : [...keys];
350 let indices = keyArray
351 .map(key => state.items.findIndex(item => getKey!(item) === key))
352 .sort((a, b) => a - b);
353 return move(state, indices, toIndex);
354 });
355 },
356 moveAfter(key: Key, keys: Iterable<Key>) {
357 dispatch(state => {
358 let toIndex = state.items.findIndex(item => getKey!(item) === key);

Callers

nothing calls this directly

Calls 2

moveFunction · 0.70
sortMethod · 0.65

Tested by

no test coverage detected