Skip to content

Commit

Permalink
rename mainSelection to lastSelectedId
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterShershov committed Dec 19, 2024
1 parent c69cf01 commit 26adf4f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/components/src/hooks/use-keyboard-nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const getHandleKeyboardNav = (
break;
case KeyCodes.Space:
case KeyCodes.Enter:
setSelectedIds({ mainSelection: focusedId, ids: [focusedId] });
setSelectedIds({ lastSelectedId: focusedId, ids: [focusedId] });
break;
default:
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const useTreeViewKeyboardInteraction = ({
if (!itemId) return;

if (selectionFollowsFocus) {
select({ mainSelection: itemId, ids: [itemId] }, 'keyboard');
select({ lastSelectedId: itemId, ids: [itemId] }, 'keyboard');
} else {
focus(itemId);
}
Expand All @@ -75,7 +75,7 @@ export const useTreeViewKeyboardInteraction = ({
if (!focusedItemId) {
return;
}
select({ mainSelection: focusedItemId, ids: [focusedItemId] });
select({ lastSelectedId: focusedItemId, ids: [focusedItemId] });
}, [focusedItemId, select]);

const handleArrowRight = useCallback(() => {
Expand Down Expand Up @@ -112,9 +112,12 @@ export const useTreeViewKeyboardInteraction = ({

if (event.shiftKey) {
if (!selectedIds.includes(previous)) {
select({ mainSelection: previous, ids: [...selectedIds, previous] });
select({ lastSelectedId: previous, ids: [...selectedIds, previous] });
} else {
select({ mainSelection: focusedItemId, ids: selectedIds.filter((id) => id !== focusedItemId) });
select({
lastSelectedId: focusedItemId,
ids: selectedIds.filter((id) => id !== focusedItemId),
});
}
}
}
Expand All @@ -131,9 +134,12 @@ export const useTreeViewKeyboardInteraction = ({

if (event.shiftKey) {
if (!selectedIds.includes(next)) {
select({ mainSelection: next, ids: [...selectedIds, next] });
select({ lastSelectedId: next, ids: [...selectedIds, next] });
} else {
select({ mainSelection: focusedItemId, ids: selectedIds.filter((id) => id !== focusedItemId) });
select({
lastSelectedId: focusedItemId,
ids: selectedIds.filter((id) => id !== focusedItemId),
});
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/components/src/list/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function List<T, EL extends HTMLElement = HTMLDivElement>({
return;
}

setSelectedIds({ mainSelection: id, ids: [id] });
setSelectedIds({ lastSelectedId: id, ids: [id] });
return;
}

Expand All @@ -166,14 +166,14 @@ export function List<T, EL extends HTMLElement = HTMLDivElement>({

if (isCtrlPressed && isAlreadySelected) {
setSelectedIds({
mainSelection: id,
lastSelectedId: id,
ids: selectedIds.ids.filter((selectedId) => selectedId !== id),
});
} else if (isCtrlPressed) {
setSelectedIds({ mainSelection: id, ids: [...selectedIds.ids, id] });
setSelectedIds({ lastSelectedId: id, ids: [...selectedIds.ids, id] });
} else if (isShiftPressed) {
setSelectedIds({
mainSelection: id,
lastSelectedId: id,
ids: getRangeSelection({
items,
id,
Expand All @@ -184,7 +184,7 @@ export function List<T, EL extends HTMLElement = HTMLDivElement>({
}),
});
} else {
setSelectedIds({ mainSelection: id, ids: [id] });
setSelectedIds({ lastSelectedId: id, ids: [id] });
}
},
[setFocusedId, selectedIds, enableMultiselect, setSelectedIds, items, indexMap, getId],
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/list/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface ListSelection {
mainSelection?: string;
lastSelectedId?: string;
ids: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export default createBoard({
getParents,
selectItem: (item) => {
updateSelection({
mainSelection: item.id,
lastSelectedId: item.id,
ids: [item.id],
});
},
Expand Down

0 comments on commit 26adf4f

Please sign in to comment.