Skip to content

Commit

Permalink
Re-fix primefaces#6561: Return scalar values directly as a label for …
Browse files Browse the repository at this point in the history
…Dropdown (primefaces#6872)

* Fix primefaces#6561: Return scalar values directly as a label for Dropdown

* Reformat code
  • Loading branch information
VytautasLozickas authored Jul 11, 2024
1 parent 6b296b5 commit 947b7d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion components/lib/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,11 @@ export const Dropdown = React.memo(
};

const getOptionLabel = (option) => {
const optionLabel = props.optionLabel ? ObjectUtils.resolveFieldData(option, props.optionLabel) : option ? option['label'] : ObjectUtils.resolveFieldData(option, 'label');
if (ObjectUtils.isScalar(option)) {
return `${option}`;
}

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

return `${optionLabel}`;
};
Expand Down
4 changes: 4 additions & 0 deletions components/lib/utils/ObjectUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ export default class ObjectUtils {
return /^[a-zA-Z\u00C0-\u017F]$/.test(char);
}

static isScalar(value) {
return value != null && (typeof value === 'string' || typeof value === 'number' || typeof value === 'bigint' || typeof value === 'boolean');
}

/**
* Firefox-v103 does not currently support the "findLast" method. It is stated that this method will be supported with Firefox-v104.
* https://caniuse.com/mdn-javascript_builtins_array_findlast
Expand Down
1 change: 1 addition & 0 deletions components/lib/utils/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export declare class ObjectUtils {
static isString(value: any): boolean;
static isPrintableCharacter(char: string): boolean;
static isLetter(char: string): boolean;
static isScalar(value: any): boolean;
static findLast(value: any[], callback: () => any): any;
static findLastIndex(value: any[], callback: () => any): number;
static sort(value1: any, value2: any, order: number, locale: string | string[]): number;
Expand Down

0 comments on commit 947b7d6

Please sign in to comment.