Skip to content

fix: handle empty strings for Select component #18553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions site/src/modules/workspaces/DynamicParameter/DynamicParameter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,17 @@ const ParameterField: FC<ParameterFieldProps> = ({
id,
}) => {
switch (parameter.form_type) {
case "dropdown":
case "dropdown": {
const EMPTY_VALUE_PLACEHOLDER = "__EMPTY_STRING__";
const selectValue = value === "" ? EMPTY_VALUE_PLACEHOLDER : value;
const handleSelectChange = (newValue: string) => {
onChange(newValue === EMPTY_VALUE_PLACEHOLDER ? "" : newValue);
};

return (
<Select
onValueChange={onChange}
value={value}
onValueChange={handleSelectChange}
value={selectValue}
disabled={disabled}
required={parameter.required}
>
Expand All @@ -393,14 +399,26 @@ const ParameterField: FC<ParameterFieldProps> = ({
/>
</SelectTrigger>
<SelectContent>
{parameter.options.map((option) => (
<SelectItem key={option.value.value} value={option.value.value}>
<OptionDisplay option={option} />
</SelectItem>
))}
{parameter.options.map((option, index) => {
const optionValue =
option.value.value === ""
? EMPTY_VALUE_PLACEHOLDER
: option.value.value;
return (
<SelectItem
key={
option.value.value || `${EMPTY_VALUE_PLACEHOLDER}:${index}`
}
value={optionValue}
>
<OptionDisplay option={option} />
</SelectItem>
);
})}
</SelectContent>
</Select>
);
}

case "multi-select": {
const parsedValues = parseStringArrayValue(value ?? "");
Expand Down
Loading