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

Improve Table component API #960

Merged
merged 15 commits into from
Jun 9, 2021
4 changes: 1 addition & 3 deletions .changeset/silent-nails-hide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
'@sumup/circuit-ui': major
---

Update the Table component's onSortBy method signature.

The signature of the Table's custom onSortBy method changed. The `nextDirection` argument moved to the third position (`(index, nextDirection, rows)` 👉 `(index, rows, nextDirection)`) and can now be `undefined` (instead of `null` in the previous implementation).
Changed the signature of the Table's custom onSortBy method. The `nextDirection` argument moved to the third position (`(index, nextDirection, rows)` 👉 `(index, rows, nextDirection)`) and can now be `undefined` (instead of `null` in the previous implementation).
13 changes: 9 additions & 4 deletions packages/circuit-ui/components/Table/Table.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,15 @@ describe('Table', () => {
it('should call the row click callback', () => {
const onRowClickMock = jest.fn();
const index = 0;
const { getAllByTestId } = render(
const { getAllByRole } = render(
<Table onRowClick={onRowClickMock} headers={headers} rows={rows} />,
);

const rowElements = getAllByRole('row');

act(() => {
userEvent.click(getAllByTestId('table-row')[0]);
// rowElements[0] is the hidden first row
userEvent.click(rowElements[1]);
});

expect(onRowClickMock).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -190,12 +193,14 @@ describe('Table', () => {
const onSortByMock = jest.fn();
const index = 0;
const nextDirection = 'ascending';
const { getAllByTestId } = render(
const { getAllByRole } = render(
<Table onSortBy={onSortByMock} headers={headers} rows={rows} />,
);

const headerElements = getAllByRole('columnheader');

act(() => {
userEvent.click(getAllByTestId('table-header')[0]);
userEvent.click(headerElements[0]);
});

expect(onSortByMock).toHaveBeenCalledTimes(1);
Expand Down
Loading