Skip to content

Commit

Permalink
Fix #7134:Refactor Dropdown component to support using option as value (
Browse files Browse the repository at this point in the history
  • Loading branch information
Rekl0w authored Sep 9, 2024
1 parent e433da4 commit 9b9cffd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
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

0 comments on commit 9b9cffd

Please sign in to comment.