Skip to content

Commit

Permalink
Add selectOnRightClick to SimpleTable
Browse files Browse the repository at this point in the history
  • Loading branch information
egbertbouman committed Feb 18, 2025
1 parent 36453a2 commit 5563b91
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/tribler/ui/src/components/ui/simple-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ interface ReactTableProps<T extends object> {
expandable?: boolean;
storeSortingState?: string;
rowId?: (originalRow: T, index: number, parent?: Row<T>) => string,
selectOnRightClick?: boolean,
}

function SimpleTable<T extends object>({
Expand All @@ -156,7 +157,8 @@ function SimpleTable<T extends object>({
maxHeight,
expandable,
storeSortingState,
rowId
rowId,
selectOnRightClick
}: ReactTableProps<T>) {
const [pagination, setPagination] = useState<PaginationState>({
pageIndex: pageIndex ?? 0,
Expand Down Expand Up @@ -348,6 +350,15 @@ function SimpleTable<T extends object>({
key={row.id}
data-state={row.getIsSelected() && "selected"}
className={`select-none ${allowSelect || allowMultiSelect ? "cursor-pointer" : ""}`}
onContextMenu={(event) => {
if (selectOnRightClick && !row.getIsSelected()) {
event.target.dispatchEvent(new MouseEvent("click", {
bubbles: true,
cancelable: true,
view: window,
}));
}
}}
onClick={(event) => {
if (!allowSelect && !allowMultiSelect)
return;
Expand Down
1 change: 1 addition & 0 deletions src/tribler/ui/src/pages/Downloads/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export default function Downloads({ statusFilter }: { statusFilter: number[] })
allowColumnToggle="download-columns"
storeSortingState="download-sorting"
rowId={(row) => row.infohash}
selectOnRightClick={true}
/>
</ContextMenuTrigger>
<ActionMenu selectedDownloads={selectedDownloads.filter((d) => d.status !== "LOADING")} />
Expand Down

0 comments on commit 5563b91

Please sign in to comment.