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

COM-218: Remove endAdornment from FinalFormSelect #1703

Merged
merged 4 commits into from
Mar 14, 2024
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
7 changes: 7 additions & 0 deletions .changeset/tricky-paws-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/admin": major
---

Remove `endAdornment` prop from `FinalFormSelect` component

The reason were conflicts with the clearable prop. This decision was based on the fact that MUI doesn't support endAdornment on selects (see: [mui/material-ui#17799](https://github.com/mui/material-ui/issues/17799)), and that there are no common use cases where both `endAdornment` and `clearable` are needed simultaneously.
13 changes: 5 additions & 8 deletions packages/admin/admin/src/form/FinalFormSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,26 @@ export const FinalFormSelect = <T,>({
}
},
children,
endAdornment,
clearable,
...rest
}: FinalFormSelectProps<T> & Partial<AsyncOptionsProps<T>> & Omit<SelectProps, "input">) => {
}: FinalFormSelectProps<T> & Partial<AsyncOptionsProps<T>> & Omit<SelectProps, "input" | "endAdornment">) => {
// Depending on the usage, `multiple` is either a root prop or in the `input` prop.
// 1. <Field component={FinalFormSelect} multiple /> -> multiple is in restInput
// 2. <Field>{(props) => <FinalFormSelect {...props} multiple />}</Field> -> multiple is in rest
const multiple = restInput.multiple ?? rest.multiple;

const selectEndAdornment = clearable ? (
const endAdornment = clearable ? (
<ClearInputAdornment
position="end"
hasClearableContent={Boolean(multiple ? (Array.isArray(value) ? value.length : value) : value)}
onClick={() => onChange(multiple ? [] : undefined)}
/>
) : (
endAdornment
);
) : null;

const selectProps = {
...rest,
multiple,
endAdornment: selectEndAdornment,
endAdornment,
name,
onChange,
onFocus,
Expand All @@ -83,7 +80,7 @@ export const FinalFormSelect = <T,>({
<CircularProgress size={16} color="inherit" />
</InputAdornment>
)}
{selectEndAdornment}
{endAdornment}
</>
}
onChange={(event) => {
Expand Down
Loading