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

[IndexTable] Allow row click when onClick is passed in on non-selectable tables #11763

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions .changeset/odd-swans-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
sydturn marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ export const Row = memo(function Row({
disabled && styles['TableRow-disabled'],
tone && styles[variationName('tone', tone)],
!selectable &&
!onClick &&
!primaryLinkElement.current &&
styles['TableRow-unclickable'],
);

let handleRowClick;

if ((!disabled && selectable) || primaryLinkElement.current) {
if ((!disabled && selectable) || onClick || primaryLinkElement.current) {
etlgfx marked this conversation as resolved.
Show resolved Hide resolved
handleRowClick = (event: React.MouseEvent) => {
if (rowType === 'subheader') return;

Expand All @@ -141,7 +142,7 @@ export const Row = memo(function Row({
return;
}

if (primaryLinkElement.current && !selectMode) {
if (primaryLinkElement.current && !selectMode && selectable) {
isNavigating.current = true;
const {ctrlKey, metaKey} = event.nativeEvent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,27 @@ describe('<Row />', () => {
);
});

it('fires onClick handler when row has an onclick and is clicked despite no primary link child present and the table not being selectable', () => {
const mockOnClick = jest.fn();
const row = mountWithTable(
<Row {...defaultProps} onClick={mockOnClick}>
<th>
<a href="/">Child without data-primary-link</a>
</th>
</Row>,
{
indexTableProps: {
itemCount: 1,
selectable: false,
},
},
);

triggerOnClick(row, 1, defaultEvent);

expect(mockOnClick).toHaveBeenCalled();
});

it('has an undefined tone by default', () => {
const row = mountWithTable(
<Row {...defaultProps}>
Expand Down
Loading