interface
interface copied to clipboard
`<ColorField>`: `notNull` option is not available
Is there a way to allow user to unset ColorField back to null value like it is possible in SelectField with allowNull prop?
You can create custom ColorField component to allow user unset color.
import { Component, ColorFieldProps, useField, Stack, Button, Field } from '@contember/admin'
export const ColorFieldWithReset = Component<ColorFieldProps>(
({ field, ...rest }) => {
const colorField = useField(field)
const handleColorReset = () => {
colorField.updateValue(null)
}
return (
<Stack horizontal align="end">
<ColorField field={field} {...rest} />
<Button onClick={() => handleColorReset()}>
Reset
</Button>
</Stack>
)
},
({ field }) => (
<>
<Field field={field} />
</>
),
)