Skip to content

Commit

Permalink
Fix primefaces#6561: Return scalar values directly as a label for Dro…
Browse files Browse the repository at this point in the history
…pdown
  • Loading branch information
VytautasLozickas committed Jul 11, 2024
1 parent 6b296b5 commit 9d17c8d
Show file tree
Hide file tree
Showing 3 changed files with 15 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
9 changes: 9 additions & 0 deletions components/lib/utils/ObjectUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,15 @@ 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 9d17c8d

Please sign in to comment.