Skip to content

Commit

Permalink
Do not call onConfirmRow when Enter is pressed in DataTable row children
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Jun 4, 2024
1 parent 7c15e79 commit 4d9d82b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/data/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ export default function DataTable<Row>({

const handleKeyDown = useCallback(
(event: KeyboardEvent, row: Row) => {
if (event.key === 'Enter') {
// Ignore events triggered in children elements
if (event.key === 'Enter' && event.target === event.currentTarget) {
confirmRow(row);
event.preventDefault();
event.stopPropagation();
Expand Down
12 changes: 12 additions & 0 deletions src/components/data/test/DataTable-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,18 @@ describe('DataTable', () => {

assert.calledWith(onConfirmRow, fakeRows[0]);
});

it("does not invoke `onConfirmRow` callback when `Enter` is pressed on a row's child", () => {
const onConfirmRow = sinon.stub();
const wrapper = createComponent({
onConfirmRow,
renderItem: (row, field) => <a href="/">{field}</a>,
});

wrapper.find('tbody tr a').first().simulate('keydown', { key: 'Enter' });

assert.notCalled(onConfirmRow);
});
});

context('when loading', () => {
Expand Down

0 comments on commit 4d9d82b

Please sign in to comment.