Skip to content

Commit

Permalink
Merge pull request #565 from lyytioy/select-multiple-checkbox
Browse files Browse the repository at this point in the history
Add checkbox to multi select
  • Loading branch information
mikael-jarvinen authored Aug 21, 2023
2 parents cc77263 + de810ee commit 5bae993
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/components/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Chip from './Chip';
import { forwardRef, Ref } from 'react';
import MenuItem from './MenuItem';
import Typography from './Typography';
import Checkbox from './Checkbox';

declare module '@mui/material' {
interface AutocompleteProps<
Expand Down Expand Up @@ -47,6 +48,7 @@ export interface AutocompleteProps<T = OptionsType>
'data-testid'?: string;
ref?: Ref<HTMLDivElement>;
name?: string;
checkbox?: boolean;
}

const Autocomplete = (
Expand All @@ -67,6 +69,7 @@ const Autocomplete = (
'data-testid': testid,
sx = {},
name,
checkbox,
...props
}: AutocompleteProps,
ref: Ref<HTMLDivElement>
Expand Down Expand Up @@ -128,6 +131,7 @@ const Autocomplete = (
}),
}}
>
{checkbox && (<Checkbox checked={state.selected} />)}
{label}
{description && (
<Typography variant="caption" color="grey.400">
Expand Down
3 changes: 3 additions & 0 deletions src/components/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type CommonProps = {
optionDivider?: boolean;
adornment?: AutocompleteProps<OptionsType>['adornment'];
multiple?: boolean;
checkbox?: boolean;
'data-testid'?: string;
ref?: Ref<HTMLDivElement>;
};
Expand All @@ -29,6 +30,7 @@ const Select = (
multiple = false,
'data-testid': testid,
optionDivider,
checkbox,
...props
}: SelectProps,
ref: Ref<HTMLDivElement>
Expand All @@ -37,6 +39,7 @@ const Select = (
return (
<Autocomplete
multiple={multiple}
checkbox={checkbox}
options={options}
disableClearable
data-testid={testid}
Expand Down
8 changes: 8 additions & 0 deletions stories/Inputs/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ MultipleSelect.args = {
fullWidth: true,
};

export const MultipleSelectCheckbox = MultiSelectTemplate.bind({});
MultipleSelectCheckbox.args = {
multiple: true,
placeholder: 'Select',
fullWidth: true,
checkbox: true,
};

export const MultipleSelectOptionDivider = MultiSelectTemplate.bind({});
MultipleSelectOptionDivider.args = {
multiple: true,
Expand Down

0 comments on commit 5bae993

Please sign in to comment.