Fixed error on MultiSelect SideDrawerField

This commit is contained in:
Emmanuel Watila
2023-03-08 01:23:43 +01:00
parent 78cd3deabf
commit 5e9b211ff9
2 changed files with 15 additions and 8 deletions

View File

@@ -77,7 +77,11 @@ export default function MultiSelect({
<FormattedChip
label={item}
onDelete={disabled ? undefined : handleDelete(i)}
sx={{ backgroundColor: colors[item.toLowerCase()][mode] }}
sx={{
backgroundColor:
colors[item.toLowerCase()] &&
colors[item.toLowerCase()][mode],
}}
/>
</Grid>
)

View File

@@ -38,7 +38,7 @@ const getItemStyle = (
export default function Settings({ onChange, config }: ISettingsProps) {
const listEndRef: any = useRef(null);
const options = config.options ?? [];
let options = config.options ?? [];
const [newOption, setNewOption] = useState("");
/* State for holding Chip Colors for Select and MultiSelect */
@@ -62,15 +62,13 @@ export default function Settings({ onChange, config }: ISettingsProps) {
color?: SelectColorThemeOptions
) => {
const _key = key.toLocaleLowerCase();
const { [_key]: _, ...newColors } = colors;
if (type === "save") colors[_key] = color;
else if (type === "delete") return newColors;
else if (type === "delete") delete colors[_key];
onChange("colors")(colors);
};
const handleItemDelete = (option: string) => {
const handleItemDelete = async (option: string) => {
onChange("options")(options.filter((o: string) => o !== option));
onChange("colors")(handleChipColorChange("delete", option));
console.log(options, colors); // Here for debugging reasons
};
const handleOnDragEnd = (result: any) => {
@@ -146,7 +144,12 @@ export default function Settings({ onChange, config }: ISettingsProps) {
<Grid item>
<IconButton
aria-label="Remove"
onClick={() => handleItemDelete(option)}
onClick={() =>
handleItemDelete(option).then(() => {
handleChipColorChange("delete", option);
console.log(options, colors); // Here for debugging purposes
})
}
>
{<RemoveIcon />}
</IconButton>