mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-27 12:12:03 +08:00
[portal][ui] add error message to checkbox input
This commit is contained in:
@ -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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user