Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the color of a check box in antd?

Tags:

reactjs

antd

import { Checkbox } from 'antd' 

<Checkbox style={{ color: 'red', backgroundColor: 'black' }}>Dr John</Checkbox>

How to change the color of the check box not the label 'Dr John'? The above style only change the styles of the label not the check box?

like image 514
Henok Tesfaye Avatar asked Apr 12 '19 07:04

Henok Tesfaye


People also ask

How can I change the color of my ANTD checkbox?

I was able to dynamically change the checkbox's color using @humanbean's and This answer. Using var() function in css and providing the color in inline style of the component. Show activity on this post. Override the default antd checkbox classes in your css and provide the necessary attributes to custom it.

How do I change the color of a checkbox in CSS?

“:hover” is used to style the checkbox when user hovers over it. Notice that when the mouse pointer move over the checkbox the color of it changes to yellow. “:active” is used to style the checkbox when it is active. Notice that when click the checkbox it will first notice a red color and then the green color.


2 Answers

You can use simple css

.ant-checkbox-checked .ant-checkbox-inner {
  background-color: red;
  border-color: red;
}
like image 61
humanbean Avatar answered Sep 24 '22 23:09

humanbean


const CustomCheckbox = styled(Checkbox)`
  ${props =>
    props.backgroundColor &&
    css`
      & .ant-checkbox-checked .ant-checkbox-inner {
        background-color: ${props.backgroundColor};
        border-color: ${props.backgroundColor};
      }
    `}
`;

with styled-component package you can do something like this.

<CustomCheckbox backgroundColor='green' />

like image 44
Henok Tesfaye Avatar answered Sep 25 '22 23:09

Henok Tesfaye