Skip to content

Commit

Permalink
update rowClick
Browse files Browse the repository at this point in the history
  • Loading branch information
mckervinc committed Jun 14, 2024
1 parent 4219bb0 commit 0e1b27e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## 0.5.5

_2024-06-13_

### Features

- Update `onRowClick` signature to include the event in one argument

## 0.5.4

_2024-06-13_
Expand Down
6 changes: 5 additions & 1 deletion example/src/Props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,11 @@ interface TableProps<T> {
/**
* The callback that gets called every time a row is clicked.
*/
onRowClick?: (event: React.MouseEvent<Element, MouseEvent>, data: { index: number }) => void;
onRowClick?: (data: {
row: T;
index: number;
event: React.MouseEvent<Element, MouseEvent>;
}) => void;
/**
* Custom component to wrap a table row. This provides another way of providing
* more row customization options.
Expand Down
6 changes: 5 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,11 @@ export type TableProps<T> = {
/**
* The callback that gets called every time a row is clicked.
*/
onRowClick?: (event: React.MouseEvent<Element, MouseEvent>, data: { index: number }) => void;
onRowClick?: (data: {
row: T;
index: number;
event: React.MouseEvent<Element, MouseEvent>;
}) => void;
/**
* Custom component to wrap a table row. This provides another way of providing
* more row customization options.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-fluid-table",
"version": "0.5.4",
"version": "0.5.5",
"description": "A React table inspired by react-window",
"author": "Mckervin Ceme <mckervinc@live.com>",
"license": "MIT",
Expand Down
16 changes: 12 additions & 4 deletions src/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ type RowContainerProps<T> = {
className?: string;
children: React.ReactNode;
containerStyle: React.CSSProperties;
onRowClick: (event: React.MouseEvent<Element, MouseEvent>, data: { index: number }) => void;
onRowClick: (data: {
row: T;
index: number;
event: React.MouseEvent<Element, MouseEvent>;
}) => void;
rowRenderer: (props: RowRenderProps<T>) => JSX.Element;
};

Expand All @@ -46,7 +50,11 @@ interface RowProps<T> extends Omit<ListChildComponentProps<T>, "data"> {
optionalDataIndex?: number | null
) => number;
generateKeyFromRow: (row: T, defaultValue: number) => string | number;
onRowClick: (event: React.MouseEvent<Element, MouseEvent>, data: { index: number }) => void;
onRowClick: (data: {
row: T;
index: number;
event: React.MouseEvent<Element, MouseEvent>;
}) => void;
subComponent?: (props: SubComponentProps<T>) => React.ReactNode;
onExpandRow?: (value: { row: T; index: number; isExpanded: boolean }) => void;
rowRenderer: (props: RowRenderProps<T>) => JSX.Element;
Expand Down Expand Up @@ -156,10 +164,10 @@ function RowContainer<T>({
const onContainerClick = useCallback(
(event: React.MouseEvent<Element, MouseEvent>) => {
if (onRowClick) {
onRowClick(event, { index });
onRowClick({ row, index, event });
}
},
[index, onRowClick]
[row, index, onRowClick]
);

if (RowRenderer) {
Expand Down

0 comments on commit 0e1b27e

Please sign in to comment.