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

Add ability to change SelectArrayInput's size prop and fix outlined variant #8562

Merged
merged 1 commit into from
Mar 13, 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
47 changes: 47 additions & 0 deletions packages/ra-ui-materialui/src/input/SelectArrayInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,50 @@ export const DifferentIdTypes = () => {
</AdminContext>
);
};

export const DifferentSizes = () => {
const fakeData = {
bands: [{ id: 1, name: 'band_1', members: [1, '2'] }],
artists: [
{ id: 1, name: 'artist_1' },
{ id: 2, name: 'artist_2' },
{ id: 3, name: 'artist_3' },
],
};
const dataProvider = fakeRestProvider(fakeData, false);
return (
<AdminContext dataProvider={dataProvider}>
<Edit resource="bands" id={1} sx={{ width: 600 }}>
<SimpleForm>
<TextInput source="name" fullWidth />
<SelectArrayInput
fullWidth
source="members"
choices={fakeData.artists}
size="small"
/>
<SelectArrayInput
fullWidth
source="members"
choices={fakeData.artists}
size="medium"
/>
<SelectArrayInput
fullWidth
source="members"
choices={fakeData.artists}
size="small"
variant="outlined"
/>
<SelectArrayInput
fullWidth
source="members"
choices={fakeData.artists}
size="medium"
variant="outlined"
/>
</SimpleForm>
</Edit>
</AdminContext>
);
};
24 changes: 23 additions & 1 deletion packages/ra-ui-materialui/src/input/SelectArrayInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
FormHelperText,
FormControl,
Chip,
OutlinedInput,
} from '@mui/material';
import {
ChoicesProps,
Expand Down Expand Up @@ -108,6 +109,7 @@ export const SelectArrayInput = (props: SelectArrayInputProps) => {
optionValue,
parse,
resource: resourceProp,
size = 'small',
source: sourceProp,
translateChoice,
validate,
Expand Down Expand Up @@ -254,6 +256,25 @@ export const SelectArrayInput = (props: SelectArrayInputProps) => {
? [field.value]
: [];

const outlinedInputProps =
variant === 'outlined'
? {
input: (
<OutlinedInput
id="select-multiple-chip"
label={
<FieldTitle
label={label}
source={source}
resource={resource}
isRequired={isRequired}
/>
}
/>
),
}
: {};

return (
<>
<StyledFormControl
Expand Down Expand Up @@ -299,11 +320,12 @@ export const SelectArrayInput = (props: SelectArrayInputProps) => {
</div>
)}
data-testid="selectArray"
size="small"
size={size}
{...field}
{...options}
onChange={handleChangeWithCreateSupport}
value={finalValue}
{...outlinedInputProps}
>
{finalChoices.map(renderMenuItem)}
</Select>
Expand Down