Hi,
I am trying to create a custom renderer for a password text field having a right handed icon to disclose the password on click. This is usually implemented using input adornments. Problem is that it seems to be impossible to pass another property to the material renderers except defined in the ControlProps type. So the following implementation has no effect:
import { Unwrapped } from '@jsonforms/material-renderers';
import IconButton from '@mui/material/IconButton';
import InputAdornment from '@mui/material/InputAdornment';
import { Visibility, VisibilityOff } from '@mui/icons-material';
const { MaterialTextControl } = Unwrapped;
const DisclosedPasswordRenderer = ( props ) => {
const [showPassword, setShowPassword] = useState(false);
const togglePasswordVisibility = () => {
setShowPassword(!showPassword);
};
const endAdornment = (
<InputAdornment position="end">
<IconButton
aria-label="toggle password visibility"
onClick={togglePasswordVisibility}
edge="end"
>
{showPassword ? <Visibility /> : <VisibilityOff />}
</IconButton>
</InputAdornment>
);
return (
<MaterialTextControl {...props} endAdornmemt={endAdornment} />
);
};
export default withJsonFormsControlProps(DisclosedPasswordRenderer);
They only way to get it to work is to create a custom renderer not using the built-in material renderer but I fail to implement all the nitty-gritty control properties to get the same look and feel. Here is my attempt:
const DisclosedPasswordControl = ({ data, handleChange, path, label, required }) => {
const [showPassword, setShowPassword] = useState(false);
const togglePasswordVisibility = () => {
setShowPassword(!showPassword);
};
return (
<TextField
type={showPassword ? 'text' : 'password'}
label={label}
value={data || ''}
onChange={(e) => handleChange(path, e.target.value)}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton
aria-label="toggle password visibility"
onClick={togglePasswordVisibility}
edge="end"
>
{showPassword ? <Visibility /> : <VisibilityOff />}
</IconButton>
</InputAdornment>
),
}}
fullWidth
required={showAsRequired(required, '')}
/>
);
};
Any ideas how this can be implemented either using a “wrapped” version using the material renderer or in any other way so it has the same look-and-feel as the material renderer?
All on JSONForms 3.2.1
Thanks
Dirk