Skip to content

Commit c9a8221

Browse files
authored
fix: Fix displaying HTML elements in FieldDropdown. (#9258)
1 parent b44f7bf commit c9a8221

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

core/field_dropdown.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -699,25 +699,30 @@ export class FieldDropdown extends Field<string> {
699699
prefix?: string;
700700
suffix?: string;
701701
} {
702-
let hasImages = false;
702+
let hasNonTextContent = false;
703703
const trimmedOptions = options.map((option): MenuOption => {
704-
if (option === FieldDropdown.SEPARATOR) return option;
704+
if (option === FieldDropdown.SEPARATOR) {
705+
hasNonTextContent = true;
706+
return option;
707+
}
705708

706709
const [label, value] = option;
707710
if (typeof label === 'string') {
708711
return [parsing.replaceMessageReferences(label), value];
709712
}
710713

711-
hasImages = true;
714+
hasNonTextContent = true;
712715
// Copy the image properties so they're not influenced by the original.
713716
// NOTE: No need to deep copy since image properties are only 1 level deep.
714717
const imageLabel = isImageProperties(label)
715718
? {...label, alt: parsing.replaceMessageReferences(label.alt)}
716-
: {...label};
719+
: label;
717720
return [imageLabel, value];
718721
});
719722

720-
if (hasImages || options.length < 2) return {options: trimmedOptions};
723+
if (hasNonTextContent || options.length < 2) {
724+
return {options: trimmedOptions};
725+
}
721726

722727
const stringOptions = trimmedOptions as [string, string][];
723728
const stringLabels = stringOptions.map(([label]) => label);
@@ -793,7 +798,7 @@ export class FieldDropdown extends Field<string> {
793798
} else if (typeof option[1] !== 'string') {
794799
foundError = true;
795800
console.error(
796-
`Invalid option[${i}]: Each FieldDropdown option id must be a string.
801+
`Invalid option[${i}]: Each FieldDropdown option id must be a string.
797802
Found ${option[1]} in: ${option}`,
798803
);
799804
} else if (
@@ -806,7 +811,7 @@ export class FieldDropdown extends Field<string> {
806811
) {
807812
foundError = true;
808813
console.error(
809-
`Invalid option[${i}]: Each FieldDropdown option must have a string
814+
`Invalid option[${i}]: Each FieldDropdown option must have a string
810815
label, image description, or HTML element. Found ${option[0]} in: ${option}`,
811816
);
812817
}

0 commit comments

Comments
 (0)