Change the checkbox colour dynamically #2833
-
Hi, For UX reasons I want to change the checkbox colour dynamically. Scenario: I've looked online and I couldn't find a simple way of doing it. I have my fingers crossed that Formik makes this less painful. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hey @DiegoMcDipster <Checkbox color={values.tac ? 'green' : 'red'} /> |
Beta Was this translation helpful? Give feedback.
-
I was just giving an example of how you can style conditionally. Would recommend you to follow https://stackoverflow.com/questions/4148499/how-to-style-a-checkbox-using-css |
Beta Was this translation helpful? Give feedback.
Hey @DiegoMcDipster
The easiest was you can achieve this is -
let's say the checkbox field name is
tac
, so now formik (useFormik) can give you an object of all the values on your form (which can be signup/login, depends upon your use case) and now you can simply usevalues.tac
to refer if the checkbox is selected or not. And on the basis of this value (values.tac
) you can change the corresponding properties/stylings for the checkbox