Skip to content
Open
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
10 changes: 9 additions & 1 deletion src/utils/expandUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ export function DefaultExpandIcon<RecordType>({
);
}

return <span className={className} onClick={onClick} />;
return (
<button
type="button"
aria-expanded={expanded}
aria-label={expanded ? 'Collapse row' : 'Expand row'}
className={className}
onClick={onClick}
/>
);
}

export function renderExpandIcon<RecordType>({
Expand Down
17 changes: 17 additions & 0 deletions tests/ExpandRow.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ describe('Table.Expand', () => {
errorSpy.mockRestore();
});

it('renders keyboard-accessible row expand controls', () => {
const { getAllByRole } = render(
createTable({
expandable: { expandedRowRender },
}),
);

const [expandButton] = getAllByRole('button', { name: 'Expand row' });
expect(expandButton).toHaveAttribute('type', 'button');
expect(expandButton).toHaveAttribute('aria-expanded', 'false');

fireEvent.click(expandButton);

expect(expandButton).toHaveAccessibleName('Collapse row');
expect(expandButton).toHaveAttribute('aria-expanded', 'true');
});

it('pass proper parameters to expandedRowRender', () => {
const rowRender = vi.fn(() => <div>expanded row</div>);
const expandableProps = props => ({ expandable: { expandedRowRender: rowRender, ...props } });
Expand Down
2 changes: 1 addition & 1 deletion tests/Table.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ describe('Table.Basic', () => {
/>,
);

const getExpandIcons = () => container.querySelectorAll('span.rc-table-row-expand-icon');
const getExpandIcons = () => container.querySelectorAll('.rc-table-row-expand-icon');

fireEvent.click(getExpandIcons()[0]);
expect(getExpandIcons()[0].classList.contains('rc-table-row-expanded')).toBeTruthy();
Expand Down
70 changes: 56 additions & 14 deletions tests/__snapshots__/ExpandRow.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ exports[`Table.Expand > childrenColumnName 1`] = `
<span
class="rc-table-row-indent indent-level-0"
/>
<span
<button
aria-expanded="true"
aria-label="Collapse row"
class="rc-table-row-expand-icon rc-table-row-expanded"
type="button"
/>
Lucy
</td>
Expand Down Expand Up @@ -204,8 +207,11 @@ exports[`Table.Expand > does not crash if scroll is not set 1`] = `
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix rc-table-cell-fix-start rc-table-cell-fix-start-shadow"
style="inset-inline-start: 0px; --z-offset: 8; --z-offset-reverse: 4;"
>
<span
<button
aria-expanded="false"
aria-label="Expand row"
class="rc-table-row-expand-icon rc-table-row-collapsed"
type="button"
/>
</td>
<td
Expand All @@ -232,8 +238,11 @@ exports[`Table.Expand > does not crash if scroll is not set 1`] = `
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix rc-table-cell-fix-start rc-table-cell-fix-start-shadow"
style="inset-inline-start: 0px; --z-offset: 8; --z-offset-reverse: 4;"
>
<span
<button
aria-expanded="false"
aria-label="Expand row"
class="rc-table-row-expand-icon rc-table-row-collapsed"
type="button"
/>
</td>
<td
Expand Down Expand Up @@ -359,8 +368,11 @@ exports[`Table.Expand > does not crash if scroll is not set 2`] = `
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix rc-table-cell-fix-start rc-table-cell-fix-start-shadow"
style="inset-inline-start: 0px; --z-offset: 8; --z-offset-reverse: 4;"
>
<span
<button
aria-expanded="false"
aria-label="Expand row"
class="rc-table-row-expand-icon rc-table-row-collapsed"
type="button"
/>
</td>
<td
Expand All @@ -387,8 +399,11 @@ exports[`Table.Expand > does not crash if scroll is not set 2`] = `
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix rc-table-cell-fix-start rc-table-cell-fix-start-shadow"
style="inset-inline-start: 0px; --z-offset: 8; --z-offset-reverse: 4;"
>
<span
<button
aria-expanded="false"
aria-label="Expand row"
class="rc-table-row-expand-icon rc-table-row-collapsed"
type="button"
/>
</td>
<td
Expand Down Expand Up @@ -602,8 +617,11 @@ exports[`Table.Expand > renders fixed column correctly > work 1`] = `
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix rc-table-cell-fix-start"
style="inset-inline-start: 0px; --z-offset: 8; --z-offset-reverse: 4;"
>
<span
<button
aria-expanded="true"
aria-label="Collapse row"
class="rc-table-row-expand-icon rc-table-row-expanded"
type="button"
/>
</td>
<td
Expand Down Expand Up @@ -649,8 +667,11 @@ exports[`Table.Expand > renders fixed column correctly > work 1`] = `
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix rc-table-cell-fix-start"
style="inset-inline-start: 0px; --z-offset: 8; --z-offset-reverse: 4;"
>
<span
<button
aria-expanded="true"
aria-label="Collapse row"
class="rc-table-row-expand-icon rc-table-row-expanded"
type="button"
/>
</td>
<td
Expand Down Expand Up @@ -739,8 +760,11 @@ exports[`Table.Expand > renders tree row correctly 1`] = `
<span
class="rc-table-row-indent indent-level-0"
/>
<span
<button
aria-expanded="true"
aria-label="Collapse row"
class="rc-table-row-expand-icon rc-table-row-expanded"
type="button"
/>
Lucy
</td>
Expand Down Expand Up @@ -843,8 +867,11 @@ exports[`Table.Expand > renders tree row correctly with different children 1`] =
<span
class="rc-table-row-indent indent-level-0"
/>
<span
<button
aria-expanded="false"
aria-label="Expand row"
class="rc-table-row-expand-icon rc-table-row-collapsed"
type="button"
/>
Lucy
</td>
Expand Down Expand Up @@ -906,8 +933,11 @@ exports[`Table.Expand > renders tree row correctly with different children 1`] =
<span
class="rc-table-row-indent indent-level-0"
/>
<span
<button
aria-expanded="false"
aria-label="Expand row"
class="rc-table-row-expand-icon rc-table-row-collapsed"
type="button"
/>
Jack
</td>
Expand Down Expand Up @@ -1066,8 +1096,11 @@ exports[`Table.Expand > work in expandable fix 1`] = `
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix rc-table-cell-fix-start rc-table-cell-fix-start-shadow"
style="inset-inline-start: 0px; --z-offset: 8; --z-offset-reverse: 4;"
>
<span
<button
aria-expanded="false"
aria-label="Expand row"
class="rc-table-row-expand-icon rc-table-row-collapsed"
type="button"
/>
</td>
<td
Expand All @@ -1094,8 +1127,11 @@ exports[`Table.Expand > work in expandable fix 1`] = `
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix rc-table-cell-fix-start rc-table-cell-fix-start-shadow"
style="inset-inline-start: 0px; --z-offset: 8; --z-offset-reverse: 4;"
>
<span
<button
aria-expanded="false"
aria-label="Expand row"
class="rc-table-row-expand-icon rc-table-row-collapsed"
type="button"
/>
</td>
<td
Expand Down Expand Up @@ -1239,8 +1275,11 @@ exports[`Table.Expand > work in expandable fix 2`] = `
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix rc-table-cell-fix-start rc-table-cell-fix-start-shadow"
style="inset-inline-start: 0px; --z-offset: 5; --z-offset-reverse: 7;"
>
<span
<button
aria-expanded="false"
aria-label="Expand row"
class="rc-table-row-expand-icon rc-table-row-collapsed"
type="button"
/>
</td>
</tr>
Expand All @@ -1267,8 +1306,11 @@ exports[`Table.Expand > work in expandable fix 2`] = `
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix rc-table-cell-fix-start rc-table-cell-fix-start-shadow"
style="inset-inline-start: 0px; --z-offset: 5; --z-offset-reverse: 7;"
>
<span
<button
aria-expanded="false"
aria-label="Expand row"
class="rc-table-row-expand-icon rc-table-row-collapsed"
type="button"
/>
</td>
</tr>
Expand Down