Hi. I’m trying to implement a Color Picker for my React app, but I’m having trouble. I’m using a schema where I pass the “color” format to be used later by my custom renderer. But I can never render specifically the fields that should be Color Picker. In fact, it’s rendering the entire form incorrectly as if it were a Color Picker, which breaks the app.
Here is my Control:
import React from ‘react’;
import { TextField } from ‘@mui/material’;
import { SketchPicker } from ‘react-color’;
const ColorPickerControl = ({ data, handleChange }) => {
const handleColorChange = (color) => {
handleChange(color.hex);
};
return (
<div style={{ display: ‘flex’, alignItems: ‘center’ }}>
<TextField
type=“text”
value={data}
onChange={(e) => handleChange(e.target.value)}
style={{ marginRight: ‘10px’, width: ‘100px’ }}
/>
);
};
export default ColorPickerControl;
And my custom renderer:
const customRenderers = [
…materialRenderers,
{
tester: (uischema, schema) => {
if (schema && schema.format === ‘color’ && uischema.type === ‘Control’) {
return 3;
}
return -1;
},
renderer: ColorPickerControl
}
];