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

[DSM] Add mixed capability to checkbox in TableRow component #20343

Merged
merged 2 commits into from
Nov 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ To compare information, for example how many products are completed versus how m
<Canvas>
<Story name="Complex table">
{args => {
const [selectedLines, setSelectedLines] = useState([2]);
const [selectedLines, setSelectedLines] = useState([2, 3]);
const handleToggleSelected = lineId => {
if (selectedLines.indexOf(lineId) === -1) {
setSelectedLines([...selectedLines, lineId]);
Expand Down Expand Up @@ -410,7 +410,7 @@ To compare information, for example how many products are completed versus how m
key={row.id}
onClick={() => handleClick(row.id)}
onSelectToggle={() => handleToggleSelected(row.id)}
isSelected={selectedLines.indexOf(row.id) !== -1}
isSelected={selectedLines.indexOf(row.id) !== -1 ? (row.id == 3 ? 'mixed' : true) : false}
>
<Table.Cell>
<Image src={row.image} alt="The alt" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type TableRowProps = Override<
/**
* Define if the row is selected, required when table is selectable
*/
isSelected?: boolean;
isSelected?: boolean | 'mixed';

/**
* Define if the row has a warning
Expand Down Expand Up @@ -165,7 +165,7 @@ const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(
(
{
rowIndex = 0,
isSelected,
isSelected = false,
level,
onSelectToggle,
onClick,
Expand Down Expand Up @@ -228,7 +228,7 @@ const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(
onClick={handleCheckboxChange}
>
<Checkbox
checked={!!isSelected}
checked={isSelected}
onChange={(_value, e) => {
handleCheckboxChange(e);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,6 @@ test('it throws when onSelectToggle is not given on selectable table', () => {
mockConsole.mockRestore();
});

test('it throws when isSelected is not given on selectable table', () => {
const mockConsole = jest.spyOn(console, 'error').mockImplementation();

const onSelectToggle = jest.fn();
const cellRender = () =>
render(
<Table isSelectable={true}>
<Table.Body>
<Table.Row onSelectToggle={onSelectToggle}>
<Table.Cell>A value</Table.Cell>
<Table.Cell>Another value</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
);

expect(cellRender).toThrowError();

mockConsole.mockRestore();
});

test('Table.Row supports forwardRef', () => {
const ref = {current: null};
render(
Expand Down
Loading