From 46af2bc90c5a8758b9429d248a9c887a61ac1695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Jo=C3=A3o=20Motta?= Date: Fri, 27 Jan 2023 19:34:54 -0300 Subject: [PATCH] Fix first render of SelectField (#119) * Return useEffect * Bump up version --- examples/package.json | 2 +- package.json | 2 +- src/SelectField.tsx | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/examples/package.json b/examples/package.json index 362d3d5..b7a7c01 100644 --- a/examples/package.json +++ b/examples/package.json @@ -19,7 +19,7 @@ "uniforms-bridge-json-schema": "3.5.1", "uniforms-bridge-simple-schema": "3.5.1", "uniforms-bridge-simple-schema-2": "3.5.1", - "uniforms-patternfly": "4.7.8" + "uniforms-patternfly": "4.7.9" }, "devDependencies": { "parcel-bundler": "^1.12.5", diff --git a/package.json b/package.json index 5873c3b..5f756b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uniforms-patternfly", - "version": "4.7.8", + "version": "4.7.9", "description": "Patternfly forms for uniforms", "repository": "git@github.com:aerogear/uniforms-patternfly.git", "author": "Gianluca ", diff --git a/src/SelectField.tsx b/src/SelectField.tsx index f4b084a..54f74b0 100644 --- a/src/SelectField.tsx +++ b/src/SelectField.tsx @@ -117,6 +117,19 @@ function SelectField(props: SelectFieldProps) { ); } + useEffect(() => { + if (!props.value) { + setSelected([]); + setExpanded(false); + } else if (Array.isArray(props.value)) { + setSelected([...props.value]); + setExpanded(false); + } else { + setSelected(props.value); + setExpanded(false); + } + }, [props.value]); + const [expanded, setExpanded] = useState(false); const [selected, setSelected] = useState([]);