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

Loading…
Cancel
Save