fix: keep free-solo dropdown values#6594
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the AsyncDropdown and Dropdown components by extracting common helper functions into a new utility file dropdownUtils.js and adding corresponding unit tests. The review feedback highlights a potential bug in isOptionEqualToValue where empty values and options with missing names could incorrectly evaluate to equal, suggesting a fix and an accompanying test case. Additionally, it recommends using loose equality (== null) for nullish checks in isEmptyDropdownValue to adhere to standard JavaScript idioms.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| return selection?.name ?? '' | ||
| } | ||
|
|
||
| export const isOptionEqualToValue = (option, value) => getOptionName(option) === getOptionName(value) |
There was a problem hiding this comment.
If value is empty (e.g., '' or null when cleared) and an option does not have a name property (or has an empty name), isOptionEqualToValue will return true because both getOptionName(option) and getOptionName(value) evaluate to ''. This causes MUI Autocomplete to incorrectly treat that option as selected. To prevent this, we should ensure that the option name is truthy before performing the equality check.
| export const isOptionEqualToValue = (option, value) => getOptionName(option) === getOptionName(value) | |
| export const isOptionEqualToValue = (option, value) => { | |
| const optionName = getOptionName(option) | |
| const valueName = getOptionName(value) | |
| return !!optionName && optionName === valueName | |
| } |
| return option?.label ?? option?.name ?? '' | ||
| } | ||
|
|
||
| export const isEmptyDropdownValue = (value) => value === undefined || value === null || value === '' || value === DEFAULT_DROPDOWN_VALUE |
There was a problem hiding this comment.
According to the repository's general rules, loose equality (== null) should be used as a standard idiom for a 'nullish' check that covers both null and undefined in JavaScript/TypeScript.
| export const isEmptyDropdownValue = (value) => value === undefined || value === null || value === '' || value === DEFAULT_DROPDOWN_VALUE | |
| export const isEmptyDropdownValue = (value) => value == null || value === '' || value === DEFAULT_DROPDOWN_VALUE |
References
- In JavaScript/TypeScript, use loose equality (
== null) as a standard idiom for a 'nullish' check that covers bothnullandundefined.
| it('handles option labels and equality for string values', () => { | ||
| expect(getOptionLabel('gpt-5.4-nano-suporte-juridico')).toBe('gpt-5.4-nano-suporte-juridico') | ||
| expect(isOptionEqualToValue(options[0], 'gpt-5')).toBe(true) | ||
| }) |
There was a problem hiding this comment.
Add a test case to verify that isOptionEqualToValue correctly returns false when comparing an option with a missing/empty name against an empty value.
it('handles option labels and equality for string values', () => {
expect(getOptionLabel('gpt-5.4-nano-suporte-juridico')).toBe('gpt-5.4-nano-suporte-juridico')
expect(isOptionEqualToValue(options[0], 'gpt-5')).toBe(true)
expect(isOptionEqualToValue({ label: 'Select' }, '')).toBe(false)
})
Description
Fixes #6590.
Allows free-solo dropdown fields to keep and submit typed values that are not present in the predefined option list. This lets Azure OpenAI deployment/model names such as custom
gpt-5.4-*deployments remain selectable instead of being reset to an empty value.Tests
pnpm --filter flowise-ui test -- dropdownUtils.test.js --runInBandNODE_OPTIONS=--max-old-space-size=4096 pnpm --filter flowise-ui buildpnpm exec eslint packages/ui/src/ui-component/dropdown/Dropdown.jsx packages/ui/src/ui-component/dropdown/AsyncDropdown.jsx packages/ui/src/ui-component/dropdown/dropdownUtils.js packages/ui/src/ui-component/dropdown/dropdownUtils.test.jsgit diff --check HEAD^..HEAD