Skip to content

Commit

Permalink
fix(select): enable defaultValue to work correctly by removing rehydr…
Browse files Browse the repository at this point in the history
…ation hack
  • Loading branch information
SiTaggart committed Oct 12, 2023
1 parent 1a70ec0 commit cd1e044
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
"author": "Twilio Inc.",
"license": "MIT",
"workspaces": {
"packages": ["apps/**/*", "packages/**/*", "templates/**/*", "!packages/paste-core/core-bundle/**/*"]
"packages": [
"apps/**/*",
"packages/**/*",
"templates/**/*",
"!packages/paste-core/core-bundle/**/*"
]
},
"types": "./types/index.d.ts",
"engines": {
Expand Down Expand Up @@ -228,5 +233,9 @@
}
},
"packageManager": "[email protected]",
"browserslist": ["last 2 versions", "not dead", "not IE 11"]
"browserslist": [
"last 2 versions",
"not dead",
"not IE 11"
]
}
7 changes: 1 addition & 6 deletions packages/paste-core/components/select/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
},
ref,
) => {
const [showOptions, setShowOptions] = React.useState(false);
React.useEffect(() => {
setShowOptions(true);
}, []);

return (
<InputBox
disabled={disabled}
Expand All @@ -108,7 +103,7 @@ const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
size={multiple ? size : 0}
variant={variant}
>
{showOptions && children}
{children}
</SelectElement>
{!multiple && (
<InputChevronWrapper element={`${element}_CHEVRON_WRAPPER`}>
Expand Down
17 changes: 16 additions & 1 deletion packages/paste-core/components/select/stories/select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,24 @@ export const DefaultSelect = (): React.ReactNode => {
</>
);
};

DefaultSelect.storyName = "Select";

export const DefaultValueSelect = (): React.ReactNode => {
const uid = useUID();
return (
<>
<Label htmlFor={uid}>Label</Label>
<Select id={uid} defaultValue="option-2" onFocus={action("handleFocus")} onBlur={action("handleBlur")}>
<Option value="option-1">Option 1</Option>
<Option value="option-2">Option 2</Option>
<Option value="option-3">Option 3</Option>
<Option value="option-4">Option 4</Option>
</Select>
<HelpText>Info that helps a user with this field.</HelpText>
</>
);
};

export const SelectRequired = (): React.ReactNode => {
const uid = useUID();
const [value, setValue] = React.useState("Select - Required");
Expand Down

0 comments on commit cd1e044

Please sign in to comment.