[portal][ui] add error message to checkbox input

pull/424/head
Keane Chan 2 years ago
parent 471a28be8a
commit b52f15a937
No known key found for this signature in database
GPG Key ID: 32718398E1E9F87C

@ -7,6 +7,7 @@ type Props = Readonly<{
defaultValue?: boolean; defaultValue?: boolean;
description?: string; description?: string;
disabled?: boolean; disabled?: boolean;
errorMessage?: string;
label: string; label: string;
name?: string; name?: string;
onChange?: ( onChange?: (
@ -21,6 +22,7 @@ function CheckboxInput(
defaultValue, defaultValue,
description, description,
disabled = false, disabled = false,
errorMessage,
label, label,
name, name,
value, value,
@ -30,8 +32,10 @@ function CheckboxInput(
) { ) {
const id = useId(); const id = useId();
const descriptionId = useId(); const descriptionId = useId();
const errorId = useId();
return ( return (
<div>
<div <div
className={clsx( className={clsx(
'relative flex', 'relative flex',
@ -54,13 +58,13 @@ function CheckboxInput(
id={id} id={id}
name={name} name={name}
type="checkbox" type="checkbox"
onChange={ onChange={(event) => {
onChange != null if (!onChange) {
? (event) => { return;
onChange?.(event.target.checked, event);
}
: undefined
} }
onChange(event.target.checked, event);
}}
/> />
</div> </div>
<div className="ml-3 text-sm"> <div className="ml-3 text-sm">
@ -84,6 +88,12 @@ function CheckboxInput(
)} )}
</div> </div>
</div> </div>
{errorMessage && (
<p className="text-danger-600 mt-2 text-sm" id={errorId}>
{errorMessage}
</p>
)}
</div>
); );
} }

Loading…
Cancel
Save