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

feat(table): adds single rowselectionmode to table #976

Merged
merged 2 commits into from
Sep 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ exports[`Radio button matches snapshot 1`] = `
-ms-flex-negative: 0;
flex-shrink: 0;
height: var(--size-1x);
margin: 0;
margin-top: var(--spacing-half);
margin: var(--spacing-half) var(--spacing-1x) 0 0;
position: relative;
width: var(--size-1x);
}
Expand Down Expand Up @@ -61,10 +60,10 @@ exports[`Radio button matches snapshot 1`] = `
-webkit-box-align: flex-start;
-ms-flex-align: flex-start;
align-items: flex-start;
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
display: inline-flex;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
position: relative;
}

Expand Down
5 changes: 2 additions & 3 deletions packages/react/src/components/radio-button/radio-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ const StyledInput = styled.input<{ disabled?: boolean }>`
display: inline-block;
flex-shrink: 0;
height: var(--size-1x);
margin: 0;
margin-top: var(--spacing-half);
margin: var(--spacing-half) var(--spacing-1x) 0 0;
position: relative;
width: var(--size-1x);

Expand Down Expand Up @@ -59,7 +58,7 @@ const StyledLabel = styled.label`

const StyledContainer = styled.div`
align-items: flex-start;
display: inline-flex;
display: flex;
position: relative;
`;

Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/table/table-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ function getCell<TData extends object, TValue>(cell: CustomCell<TData, TValue>):
$textAlign={cell.column.columnDef.textAlign}
$startOffset={cell.column.getStart()}
key={cell.id}
id={cell.id}
hasRightBorder={isLastColumnInAGroup(cell.column)}
>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
Expand Down
52 changes: 47 additions & 5 deletions packages/react/src/components/table/table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('Table', () => {
const callback = jest.fn();
const wrapper = mountWithTheme(
<Table
selectableRows
rowSelectionMode="multiple"
columns={columns}
data={data}
onRowClick={callback}
Expand All @@ -205,7 +205,7 @@ describe('Table', () => {

mountWithTheme(
<Table
selectableRows
rowSelectionMode="multiple"
columns={columns}
data={data}
onSelectedRowsChange={callback}
Expand All @@ -220,7 +220,7 @@ describe('Table', () => {
const callback = jest.fn();
const wrapper = mountWithTheme(
<Table
selectableRows
rowSelectionMode="multiple"
columns={columns}
data={data}
onSelectedRowsChange={callback}
Expand All @@ -236,7 +236,7 @@ describe('Table', () => {
const callback = jest.fn();
const wrapper = mountWithTheme(
<Table
selectableRows
rowSelectionMode="multiple"
columns={columns}
data={data}
onSelectedRowsChange={callback}
Expand Down Expand Up @@ -309,7 +309,7 @@ describe('Table', () => {
});

test('has selectable rows styles', () => {
const tree = renderWithProviders(<Table selectableRows columns={columns} data={data} />);
const tree = renderWithProviders(<Table rowSelectionMode="multiple" columns={columns} data={data} />);

expect(tree).toMatchSnapshot();
});
Expand Down Expand Up @@ -347,4 +347,46 @@ describe('Table', () => {

expect(tree).toMatchSnapshot();
});

test('has radio buttons in single selection mode', () => {
ogermain-kronos marked this conversation as resolved.
Show resolved Hide resolved
const callback = jest.fn();
const wrapper = mountWithTheme(
<Table
rowSelectionMode="single"
columns={columns}
data={data}
onSelectedRowsChange={callback}
/>,
);

expect(getByTestId(wrapper, 'row-radiobutton-0')
.find('input')
.prop('type')).toBe('radio');
});

test('has single selection when selecting other row in single selection mode', () => {
const callback = jest.fn();
const wrapper = mountWithTheme(
<Table
rowSelectionMode="single"
columns={columns}
data={data}
onSelectedRowsChange={callback}
/>,
);

getByTestId(wrapper, 'radiobutton-row-radiobutton-0')
.find('input')
.simulate('change', { target: { checked: true } });
getByTestId(wrapper, 'radiobutton-row-radiobutton-1')
.find('input')
.simulate('change', { target: { checked: true } });

expect(getByTestId(wrapper, 'radiobutton-row-radiobutton-0')
.find('input')
.prop('checked')).toBe(false);
expect(getByTestId(wrapper, 'radiobutton-row-radiobutton-1')
.find('input')
.prop('checked')).toBe(true);
});
});
Loading