Allows clicking on label to edit checkbox
This commit is contained in:
parent
28f5a2bd1c
commit
2fe142b6d3
1 changed files with 5 additions and 2 deletions
|
@ -1,7 +1,8 @@
|
||||||
// Copyright 2021 Signal Messenger, LLC
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
|
import { v4 as uuid } from 'uuid';
|
||||||
|
|
||||||
import { getClassNamesFor } from '../util/getClassNamesFor';
|
import { getClassNamesFor } from '../util/getClassNamesFor';
|
||||||
|
|
||||||
|
@ -25,6 +26,7 @@ export const Checkbox = ({
|
||||||
onChange,
|
onChange,
|
||||||
}: PropsType): JSX.Element => {
|
}: PropsType): JSX.Element => {
|
||||||
const getClassName = getClassNamesFor('Checkbox', moduleClassName);
|
const getClassName = getClassNamesFor('Checkbox', moduleClassName);
|
||||||
|
const id = useMemo(() => `${name}::${uuid()}`, [name]);
|
||||||
return (
|
return (
|
||||||
<div className={getClassName('')}>
|
<div className={getClassName('')}>
|
||||||
<div className={getClassName('__container')}>
|
<div className={getClassName('__container')}>
|
||||||
|
@ -32,13 +34,14 @@ export const Checkbox = ({
|
||||||
<input
|
<input
|
||||||
checked={Boolean(checked)}
|
checked={Boolean(checked)}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
id={id}
|
||||||
name={name}
|
name={name}
|
||||||
onChange={ev => onChange(ev.target.checked)}
|
onChange={ev => onChange(ev.target.checked)}
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor={name}>{label}</label>
|
<label htmlFor={id}>{label}</label>
|
||||||
<div className={getClassName('__description')}>{description}</div>
|
<div className={getClassName('__description')}>{description}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue