Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
Fix first render of SelectField (#119)
Browse files Browse the repository at this point in the history
* Return useEffect

* Bump up version
  • Loading branch information
ljmotta authored Jan 27, 2023
1 parent e342555 commit 46af2bc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uniforms-patternfly",
"version": "4.7.8",
"version": "4.7.9",
"description": "Patternfly forms for uniforms",
"repository": "[email protected]:aerogear/uniforms-patternfly.git",
"author": "Gianluca <[email protected]>",
Expand Down
13 changes: 13 additions & 0 deletions src/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>(false);
const [selected, setSelected] = useState<string | string[] | number | number[] | undefined>([]);

Expand Down

0 comments on commit 46af2bc

Please sign in to comment.