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

Do not call onConfirmRow when Enter is pressed in DataTable row children #1574

Merged
merged 1 commit into from
Jun 4, 2024
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
4 changes: 3 additions & 1 deletion src/components/data/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ export default function DataTable<Row>({

const handleKeyDown = useCallback(
(event: KeyboardEvent, row: Row) => {
if (event.key === 'Enter') {
// Avoid preventing Enter key interactions in children elements by
// ignoring events not triggered by the row element itself
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);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test fails without the changes introduced in DataTable, while the test above keeps passing.

});

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