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

Re-fix primefaces#6561: Return scalar values directly as a label for Dropdown #6872

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
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
Loading