web: allow deselecting items using ctrl+click (#1433)

Signed-off-by: Muhammad Ali <alihamuh@gmail.com>
Co-authored-by: Abdullah Atta <abdullahatta@streetwriters.co>
This commit is contained in:
Muhammad Ali
2022-12-05 11:08:32 +05:00
committed by GitHub
parent 5445ee0335
commit a19fa2212a
4 changed files with 10 additions and 3 deletions

View File

@@ -74,6 +74,7 @@ function ListContainer(props: ListContainerProps) {
const [announcements, removeAnnouncement] = useAnnouncements();
const setSelectedItems = useSelectionStore((store) => store.setSelectedItems);
const isSelected = useSelectionStore((store) => store.isSelected);
const selectItem = useSelectionStore((store) => store.selectItem);
const deselectItem = useSelectionStore((store) => store.deselectItem);
const toggleSelection = useSelectionStore(
@@ -98,7 +99,10 @@ function ListContainer(props: ListContainerProps) {
length: items.length,
reset: () => toggleSelection(false),
deselect: (index) => deselectItem(items[index]),
select: (index) => selectItem(items[index]),
select: (index) =>
isSelected(items[index])
? deselectItem(items[index])
: selectItem(items[index]),
bulkSelect: (indices) => setSelectedItems(indices.map((i) => items[i])),
focusItemAt: (index) => {
const item = items[index];

View File

@@ -145,7 +145,7 @@ function ListItem(props) {
}
}}
onClick={(e) => {
if (props.onClick) {
if (!e.metaKey && !e.shiftKey && !e.ctrlKey && props.onClick) {
props.onClick();
}
}}

View File

@@ -52,7 +52,6 @@ export function useKeyboardListNavigation(
} = options;
const cursor = useRef(-1);
const anchor = useRef(-1);
// const { reset, select, deselect } = useSelection();
const direction = useCallback(() => {

View File

@@ -57,6 +57,10 @@ class SelectionStore extends BaseStore {
}
};
isSelected = (item) => {
return this.get().selectedItems.indexOf(item) > -1;
};
setSelectedItems = (items) => {
this.set((state) => (state.selectedItems = items));
};