Skip to content

Commit

Permalink
2947-Dropdown-Field-Change-to-Autocomplete (#3126)
Browse files Browse the repository at this point in the history
  • Loading branch information
geodem127 authored Jan 15, 2025
1 parent a1863cf commit dbcd750
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/apps/content-editor/src/app/components/Editor/Field/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
TextField,
Dialog,
IconButton,
Autocomplete,
} from "@mui/material";

import CloseIcon from "@mui/icons-material/Close";
Expand Down Expand Up @@ -618,21 +619,30 @@ export const Field = ({

return (
<FieldShell settings={fieldData} errors={errors}>
<Select
name={name}
variant="outlined"
displayEmpty
value={value || ""}
onChange={(e) => onChange(e.target.value, name)}
error={errors && Object.values(errors)?.some((error) => !!error)}
>
<MenuItem value="">Select</MenuItem>
{dropdownOptions.map((dropdownOption, idx) => (
<MenuItem key={idx} value={dropdownOption.value}>
{dropdownOption.text}
</MenuItem>
))}
</Select>
<Autocomplete
clearOnBlur
disablePortal
options={dropdownOptions}
value={
dropdownOptions.find((option) => option.value === value) || null
}
onChange={(e, newValue) => onChange(newValue?.value || "", name)}
isOptionEqualToValue={(option, value) =>
option.value === value.value
}
getOptionLabel={(option) => option.text || ""}
renderInput={(params) => (
<TextField
{...params}
name={name}
placeholder="Select"
variant="outlined"
error={
errors && Object.values(errors)?.some((error) => !!error)
}
/>
)}
/>
</FieldShell>
);

Expand Down

0 comments on commit dbcd750

Please sign in to comment.