interface icon indicating copy to clipboard operation
interface copied to clipboard

`<ColorField>`: `notNull` option is not available

Open FilipChalupa opened this issue 2 years ago • 1 comments

Is there a way to allow user to unset ColorField back to null value like it is possible in SelectField with allowNull prop?

FilipChalupa avatar Sep 26 '23 11:09 FilipChalupa

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} />
		</>
	),
)

jonasnobile avatar Sep 26 '23 16:09 jonasnobile