From 9d17c8dd8ea97c213f3c02d7a7627a1e7f97a786 Mon Sep 17 00:00:00 2001 From: Vytautas Lozickas Date: Thu, 11 Jul 2024 15:32:39 +0300 Subject: [PATCH 1/2] Fix primefaces#6561: Return scalar values directly as a label for Dropdown --- components/lib/dropdown/Dropdown.js | 6 +++++- components/lib/utils/ObjectUtils.js | 9 +++++++++ components/lib/utils/utils.d.ts | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/components/lib/dropdown/Dropdown.js b/components/lib/dropdown/Dropdown.js index 7b1782fa7d..1980f30988 100644 --- a/components/lib/dropdown/Dropdown.js +++ b/components/lib/dropdown/Dropdown.js @@ -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}`; }; diff --git a/components/lib/utils/ObjectUtils.js b/components/lib/utils/ObjectUtils.js index 49b346ad08..da80b04870 100644 --- a/components/lib/utils/ObjectUtils.js +++ b/components/lib/utils/ObjectUtils.js @@ -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 diff --git a/components/lib/utils/utils.d.ts b/components/lib/utils/utils.d.ts index 3c40163b32..db8c8d7954 100644 --- a/components/lib/utils/utils.d.ts +++ b/components/lib/utils/utils.d.ts @@ -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; From 007e1295ac50fd2b3390d573f106d1af57e8d035 Mon Sep 17 00:00:00 2001 From: Vytautas Lozickas Date: Thu, 11 Jul 2024 15:39:49 +0300 Subject: [PATCH 2/2] Reformat code --- components/lib/utils/ObjectUtils.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/components/lib/utils/ObjectUtils.js b/components/lib/utils/ObjectUtils.js index da80b04870..659e3f5c43 100644 --- a/components/lib/utils/ObjectUtils.js +++ b/components/lib/utils/ObjectUtils.js @@ -387,12 +387,7 @@ export default class ObjectUtils { } static isScalar(value) { - return value != null && ( - typeof value === 'string' || - typeof value === 'number' || - typeof value === 'bigint' || - typeof value === 'boolean' - ); + return value != null && (typeof value === 'string' || typeof value === 'number' || typeof value === 'bigint' || typeof value === 'boolean'); } /**