Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added right-click event handler. #741

Merged
merged 1 commit into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Table.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This component expects explicit `width` and `height` parameters.
| onHeaderClick | Function | | Callback invoked when a user clicks on a table header. `({ columnData: any, dataKey: string, event: Event }): void` |
| onRowClick | Function | | Callback invoked when a user clicks on a table row. `({ event: Event, index: number, rowData: any }): void` |
| onRowDoubleClick | Function | | Callback invoked when a user double-clicks on a table row. `({ event: Event, index: number, rowData: any }): void` |
| onRowRightClick | Function | | Callback invoked when a user right-clicks on a table row. `({ event: Event, index: number, rowData: any }): void` |
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating docs too! 😄

nit: Docs should be alpha-sorted

| onRowMouseOut | Function | | Callback invoked when the mouse leaves a table row. `({ event: Event, index: number, rowData: any }): void` |
| onRowMouseOver | Function | | Callback invoked when a user moves the mouse over a table row. `({ event: Event, index: number, rowData: any }): void` |
| onRowsRendered | Function | | Callback invoked with information about the slice of rows that were just rendered: `({ overscanStartIndex: number, overscanStopIndex: number, startIndex: number, stopIndex: number }): void` |
Expand Down
21 changes: 21 additions & 0 deletions source/Table/Table.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,27 @@ describe("Table", () => {
});
});

describe("onRowRightClick", () => {
it("should call :onRowRightClick with the correct :rowIndex when a row is right-clicked", () => {
const onRowRightClick = jest.fn();
const rendered = findDOMNode(
render(
getMarkup({
onRowRightClick
})
)
);
const rows = rendered.querySelectorAll(".ReactVirtualized__Table__row");
Simulate.contextMenu(rows[0]);
Simulate.contextMenu(rows[3]);
expect(onRowRightClick).toHaveBeenCalledTimes(2);
expect(onRowRightClick.mock.calls.map(call => call[0].index)).toEqual([
0,
3
]);
});
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding a test 😁


describe("onRowMouseOver/Out", () => {
it("should call :onRowMouseOver and :onRowMouseOut with the correct :rowIndex when the mouse is moved over rows", () => {
let onRowMouseOver = jest.fn();
Expand Down
8 changes: 8 additions & 0 deletions source/Table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ export default class Table extends PureComponent {
*/
onRowDoubleClick: PropTypes.func,

/**
* Callback invoked when a user right-clicks on a table row.
* ({ index: number }): void
*/
onRowRightClick: PropTypes.func,

/**
* Callback invoked when the mouse leaves a table row.
* ({ index: number }): void
Expand Down Expand Up @@ -527,6 +533,7 @@ export default class Table extends PureComponent {
children,
onRowClick,
onRowDoubleClick,
onRowRightClick,
onRowMouseOver,
onRowMouseOut,
rowClassName,
Expand Down Expand Up @@ -576,6 +583,7 @@ export default class Table extends PureComponent {
key,
onRowClick,
onRowDoubleClick,
onRowRightClick,
onRowMouseOver,
onRowMouseOut,
rowData,
Expand Down
13 changes: 12 additions & 1 deletion source/Table/defaultRowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ export default function defaultRowRenderer({
key,
onRowClick,
onRowDoubleClick,
onRowRightClick,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: alpha-sort

onRowMouseOver,
onRowMouseOut,
rowData,
style
}: RowRendererParams) {
const a11yProps = {};

if (onRowClick || onRowDoubleClick || onRowMouseOver || onRowMouseOut) {
if (
onRowClick ||
onRowDoubleClick ||
onRowRightClick ||
onRowMouseOver ||
onRowMouseOut
) {
a11yProps["aria-label"] = "row";
a11yProps.tabIndex = 0;

Expand All @@ -30,6 +37,10 @@ export default function defaultRowRenderer({
a11yProps.onDoubleClick = event =>
onRowDoubleClick({ event, index, rowData });
}
if (onRowRightClick) {
a11yProps.onContextMenu = event =>
onRowRightClick({ event, index, rowData });
}
if (onRowMouseOut) {
a11yProps.onMouseOut = event => onRowMouseOut({ event, index, rowData });
}
Expand Down