Skip to content

Commit

Permalink
Toggle the checkbox when clicking on the label
Browse files Browse the repository at this point in the history
Pretty sure the `user-select: none` could be employed
in other places aswell

Signed-off-by: Kipras Melnikovas <[email protected]>
  • Loading branch information
kiprasmel committed Mar 28, 2021
1 parent ce35a2d commit 4e4ae0a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions components/common/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import styles from './Checkbox.module.css';
function Checkbox({ name, value, label, onChange }) {
const ref = useRef();

const onClick = () => ref.current.click();

return (
<div className={styles.container}>
<div className={styles.checkbox} onClick={() => ref.current.click()}>
<div className={styles.checkbox} onClick={onClick}>
{value && <Icon icon={<Check />} size="small" />}
</div>
<label className={styles.label} htmlFor={name}>
<label className={styles.label} htmlFor={name} onClick={onClick}>
{label}
</label>
<input
Expand Down
1 change: 1 addition & 0 deletions components/common/Checkbox.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

.label {
margin-left: 10px;
user-select: none; /* disable text selection when clicking to toggle the checkbox */
}

.input {
Expand Down

0 comments on commit 4e4ae0a

Please sign in to comment.