From b52f15a937a0cc4b90fddd76c42638a22a3b7cb6 Mon Sep 17 00:00:00 2001 From: Keane Chan Date: Mon, 24 Oct 2022 23:00:37 +0800 Subject: [PATCH] [portal][ui] add error message to checkbox input --- .../ui/src/CheckboxInput/CheckboxInput.tsx | 106 ++++++++++-------- 1 file changed, 58 insertions(+), 48 deletions(-) diff --git a/packages/ui/src/CheckboxInput/CheckboxInput.tsx b/packages/ui/src/CheckboxInput/CheckboxInput.tsx index edeb9d3a..fec43b7e 100644 --- a/packages/ui/src/CheckboxInput/CheckboxInput.tsx +++ b/packages/ui/src/CheckboxInput/CheckboxInput.tsx @@ -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,59 +32,67 @@ function CheckboxInput( ) { const id = useId(); const descriptionId = useId(); + const errorId = useId(); return ( -
-
- { - onChange?.(event.target.checked, event); - } - : undefined - } - /> -
-
- - {description && ( -

+

+
+ - {description} -

- )} + defaultChecked={defaultValue} + disabled={disabled} + id={id} + name={name} + type="checkbox" + onChange={(event) => { + if (!onChange) { + return; + } + + onChange(event.target.checked, event); + }} + /> +
+
+ + {description && ( +

+ {description} +

+ )} +
+ {errorMessage && ( +

+ {errorMessage} +

+ )}
); }