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

ReactTableModule #332

Merged
merged 1 commit into from
Mar 28, 2023
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
3 changes: 2 additions & 1 deletion src/components/TableModule/TableModule.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,8 @@ export const RowSelection: ComponentStory<typeof TableModule> = (args) => {
cell: {
content: (rowData: RowSelectionRow) => (
<Checkbox
label=" "
label=""
aria-label="select row"
checked={rowData.getIsSelected()}
disabled={!rowData.getCanSelect()}
onChange={rowData.getToggleSelectedHandler()}
Expand Down
36 changes: 36 additions & 0 deletions src/components/TableModule/TableModuleRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { renderWithTheme } from '../../testUtils/renderWithTheme';
import { TableModuleRow } from './TableModuleRow';
import * as React from 'react';
import { testIds } from './TableModule';
import { Checkbox } from '../Checkbox';

test('it renders a TableModuleRow', async () => {
const { findByTestId } = renderWithTheme(
Expand Down Expand Up @@ -126,3 +127,38 @@ test('it does not render row actions when the `rowActions` function returns null
const td = await findByRole('cell');
expect(td.innerHTML).toBe('');
});

test('it does not trigger row click when target is a checkbox input', async () => {
const mockFn = jest.fn();
const mockCheckboxClick = jest.fn();

const { findByLabelText } = renderWithTheme(
<table>
<tbody>
<TableModuleRow
data={{}}
row={{
id: 'row',
}}
cells={[
{
content: () => (
<Checkbox label="Select Row" onClick={mockCheckboxClick} />
),
},
]}
headingsLength={0}
onRowClick={mockFn}
/>
</tbody>
</table>
);

const checkbox = await findByLabelText('Select Row');

fireEvent.click(checkbox);

expect(mockCheckboxClick).toBeCalledTimes(1);
// does not trigger row click
expect(mockFn).toBeCalledTimes(0);
});
4 changes: 4 additions & 0 deletions src/components/TableModule/TableModuleRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ const TableModuleRow: React.FC<TableModuleRowProps> = React.memo(
return;
}

if (e.target?.tagName === 'INPUT' && e.target?.type === 'checkbox') {
return;
}

e?.currentTarget?.blur();

onRowClick?.(row);
Expand Down