Update checkbox API (#663)

* Update checkbox API

* Fix test
This commit is contained in:
Emilien Chauvet
2023-07-14 18:44:32 -07:00
committed by GitHub
parent b971464fe5
commit efd4ed16d6
7 changed files with 14 additions and 26 deletions

View File

@ -132,9 +132,7 @@ export function CompanyBoardCard() {
/> />
<span>{company.name}</span> <span>{company.name}</span>
<div style={{ display: 'flex', flex: 1 }} /> <div style={{ display: 'flex', flex: 1 }} />
<div onClick={handleCheckboxChange}> <Checkbox checked={selected} onChange={handleCheckboxChange} />
<Checkbox checked={selected} />
</div>
</StyledBoardCardHeader> </StyledBoardCardHeader>
<StyledBoardCardBody> <StyledBoardCardBody>
<span> <span>

View File

@ -21,7 +21,6 @@ export function getOptimisticlyUpdatedBoard(
board: BoardPipelineStageColumn[], board: BoardPipelineStageColumn[],
result: DropResult, result: DropResult,
) { ) {
// TODO: review any types
const newBoard = JSON.parse(JSON.stringify(board)); const newBoard = JSON.parse(JSON.stringify(board));
const { destination, source } = result; const { destination, source } = result;
if (!destination) return; if (!destination) return;

View File

@ -6,7 +6,7 @@ import { IconCheck } from '@/ui/icons/index';
type OwnProps = { type OwnProps = {
checked: boolean; checked: boolean;
indeterminate?: boolean; indeterminate?: boolean;
onChange?: (newCheckedValue: boolean) => void; onChange: () => void;
}; };
const StyledContainer = styled.div` const StyledContainer = styled.div`
@ -65,18 +65,13 @@ export function Checkbox({ checked, onChange, indeterminate }: OwnProps) {
} }
}, [ref, indeterminate, checked]); }, [ref, indeterminate, checked]);
function handleChange(event: React.ChangeEvent<HTMLInputElement>) {
onChange?.(event.target.checked);
}
return ( return (
<StyledContainer> <StyledContainer onClick={onChange}>
<input <input
ref={ref} ref={ref}
type="checkbox" type="checkbox"
data-testid="input-checkbox" data-testid="input-checkbox"
checked={checked} checked={checked}
onChange={handleChange}
/> />
{checked && <IconCheck />} {checked && <IconCheck />}
</StyledContainer> </StyledContainer>

View File

@ -42,9 +42,9 @@ export function DropdownMenuCheckableItem({
} }
return ( return (
<DropdownMenuCheckableItemContainer onClick={handleClick}> <DropdownMenuCheckableItemContainer>
<StyledLeftContainer> <StyledLeftContainer>
<Checkbox checked={checked} /> <Checkbox checked={checked} onChange={handleClick} />
<StyledChildrenContainer>{children}</StyledChildrenContainer> <StyledChildrenContainer>{children}</StyledChildrenContainer>
</StyledLeftContainer> </StyledLeftContainer>
</DropdownMenuCheckableItemContainer> </DropdownMenuCheckableItemContainer>

View File

@ -10,7 +10,6 @@ import { Checkbox } from '../form/Checkbox';
const StyledContainer = styled.div` const StyledContainer = styled.div`
align-items: center; align-items: center;
cursor: pointer;
display: flex; display: flex;
height: 32px; height: 32px;
@ -33,11 +32,8 @@ export function CheckboxCell() {
} }
return ( return (
<StyledContainer <StyledContainer>
onClick={handleContainerClick} <Checkbox checked={currentRowSelected} onChange={handleContainerClick} />
data-testid="input-checkbox-cell-container"
>
<Checkbox checked={currentRowSelected} />
</StyledContainer> </StyledContainer>
); );
} }

View File

@ -8,7 +8,6 @@ import { Checkbox } from '../form/Checkbox';
const StyledContainer = styled.div` const StyledContainer = styled.div`
align-items: center; align-items: center;
cursor: pointer;
display: flex; display: flex;
height: 32px; height: 32px;
@ -26,11 +25,12 @@ export const SelectAllCheckbox = () => {
const indeterminate = allRowsSelectedStatus === 'some'; const indeterminate = allRowsSelectedStatus === 'some';
return ( return (
<StyledContainer <StyledContainer>
onClick={handleContainerClick} <Checkbox
data-testid="input-checkbox-cell-container" checked={checked}
> onChange={handleContainerClick}
<Checkbox checked={checked} indeterminate={indeterminate} /> indeterminate={indeterminate}
/>
</StyledContainer> </StyledContainer>
); );
}; };

View File

@ -81,7 +81,7 @@ export const CheckCheckboxes: Story = {
await canvas.findByText(mockedPeopleData[0].email); await canvas.findByText(mockedPeopleData[0].email);
const inputCheckboxContainers = await canvas.findAllByTestId( const inputCheckboxContainers = await canvas.findAllByTestId(
'input-checkbox-cell-container', 'input-checkbox',
); );
const inputCheckboxes = await canvas.findAllByTestId('input-checkbox'); const inputCheckboxes = await canvas.findAllByTestId('input-checkbox');