Skip to content
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

Fix #7134:Refactor Dropdown component to support using option as value #7141

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions components/lib/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,10 @@ export const Dropdown = React.memo(
};

const getOptionValue = (option) => {
if (props.useOptionAsValue) {
return option;
}

const optionValue = props.optionValue ? ObjectUtils.resolveFieldData(option, props.optionValue) : option ? option['value'] : ObjectUtils.resolveFieldData(option, 'value');

return props.optionValue || ObjectUtils.isNotEmpty(optionValue) ? optionValue : option;
Expand Down
4 changes: 4 additions & 0 deletions components/lib/dropdown/dropdown.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ export interface DropdownProps extends Omit<React.DetailedHTMLProps<React.InputH
* Property name or getter function to use as the disabled flag of an option, defaults to false when not defined.
*/
optionDisabled?: string | ((option: any) => boolean) | undefined;
/**
* Whether the option should be used as the value for the select element.
*/
useOptionAsValue?: boolean;
/**
* Property name or getter function that refers to the children options of option group.
* @defaultValue items
Expand Down
Loading