use FormControlLabel and prevent defaults

Signed-off-by: Frederic Kayser <frederic@frederic-kayser.de>
This commit is contained in:
Frederic Kayser
2023-03-31 18:47:28 +02:00
parent 193aef4c31
commit 3c12037330
4 changed files with 27 additions and 27 deletions
@@ -154,13 +154,9 @@ describe('<EntityLifecyclePicker/>', () => {
lifecycles: new EntityLifecycleFilter(['production']),
});
fireEvent.click(screen.getByTestId('lifecycle-picker-expand'));
expect(
screen
.getByTestId('lifecycle-checkbox-production')
.querySelector('input[type="checkbox"]'),
).toBeChecked();
expect(screen.getByLabelText('production')).toBeChecked();
fireEvent.click(screen.getByTestId('lifecycle-checkbox-label-production'));
fireEvent.click(screen.getByLabelText('production'));
expect(updateFilters).toHaveBeenLastCalledWith({
lifecycles: undefined,
});
@@ -18,6 +18,7 @@ import { Entity } from '@backstage/catalog-model';
import {
Box,
Checkbox,
FormControlLabel,
makeStyles,
TextField,
Typography,
@@ -111,15 +112,17 @@ export const EntityLifecyclePicker = (props: { initialFilter?: string[] }) => {
setSelectedLifecycles(value)
}
renderOption={(option, { selected }) => (
<div data-testid={`lifecycle-checkbox-label-${option}`}>
<Checkbox
icon={icon}
checkedIcon={checkedIcon}
checked={selected}
data-testid={`lifecycle-checkbox-${option}`}
/>
{option}
</div>
<FormControlLabel
control={
<Checkbox
icon={icon}
checkedIcon={checkedIcon}
checked={selected}
/>
}
onClick={event => event.preventDefault()}
label={option}
/>
)}
size="small"
popupIcon={<ExpandMoreIcon data-testid="lifecycle-picker-expand" />}
@@ -123,10 +123,7 @@ describe('<EntityProcessingStatusPicker/>', () => {
);
fireEvent.click(screen.getByTestId('processing-status-picker-expand'));
fireEvent.click(
screen.getByTestId('processing-status-checkbox-label-Is Orphan'),
);
fireEvent.click(screen.getByText('Is Orphan'));
expect(updateFilters).toHaveBeenCalledWith({
orphan: undefined,
});
@@ -18,6 +18,7 @@ import { EntityErrorFilter, EntityOrphanFilter } from '../../filters';
import {
Box,
Checkbox,
FormControlLabel,
makeStyles,
TextField,
Typography,
@@ -82,14 +83,17 @@ export const EntityProcessingStatusPicker = () => {
errorChange(value.includes('Has Error'));
}}
renderOption={(option, { selected }) => (
<div data-testid={`processing-status-checkbox-label-${option}`}>
<Checkbox
icon={icon}
checkedIcon={checkedIcon}
checked={selected}
/>
{option}
</div>
<FormControlLabel
control={
<Checkbox
icon={icon}
checkedIcon={checkedIcon}
checked={selected}
/>
}
onClick={event => event.preventDefault()}
label={option}
/>
)}
size="small"
popupIcon={