Merge pull request #586 from kiprasmel/feat/toggle-checkbox-on-label-click
feat/toggle-checkbox-on-label-clickpull/634/head
commit
afb5e17476
|
@ -7,12 +7,14 @@ import styles from './Checkbox.module.css';
|
||||||
function Checkbox({ name, value, label, onChange }) {
|
function Checkbox({ name, value, label, onChange }) {
|
||||||
const ref = useRef();
|
const ref = useRef();
|
||||||
|
|
||||||
|
const onClick = () => ref.current.click();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<div className={styles.checkbox} onClick={() => ref.current.click()}>
|
<div className={styles.checkbox} onClick={onClick}>
|
||||||
{value && <Icon icon={<Check />} size="small" />}
|
{value && <Icon icon={<Check />} size="small" />}
|
||||||
</div>
|
</div>
|
||||||
<label className={styles.label} htmlFor={name}>
|
<label className={styles.label} htmlFor={name} onClick={onClick}>
|
||||||
{label}
|
{label}
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
.label {
|
.label {
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
|
user-select: none; /* disable text selection when clicking to toggle the checkbox */
|
||||||
}
|
}
|
||||||
|
|
||||||
.input {
|
.input {
|
||||||
|
|
Loading…
Reference in New Issue