From c9a8221a2d2cd01cb42aa162b7ce2b8418ec1a9c Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 28 Jul 2025 13:33:52 -0700 Subject: [PATCH] fix: Fix displaying HTML elements in `FieldDropdown`. (#9258) --- core/field_dropdown.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/core/field_dropdown.ts b/core/field_dropdown.ts index 9c0d7f292..8b01ccdda 100644 --- a/core/field_dropdown.ts +++ b/core/field_dropdown.ts @@ -699,25 +699,30 @@ export class FieldDropdown extends Field { prefix?: string; suffix?: string; } { - let hasImages = false; + let hasNonTextContent = false; const trimmedOptions = options.map((option): MenuOption => { - if (option === FieldDropdown.SEPARATOR) return option; + if (option === FieldDropdown.SEPARATOR) { + hasNonTextContent = true; + return option; + } const [label, value] = option; if (typeof label === 'string') { return [parsing.replaceMessageReferences(label), value]; } - hasImages = true; + hasNonTextContent = true; // Copy the image properties so they're not influenced by the original. // NOTE: No need to deep copy since image properties are only 1 level deep. const imageLabel = isImageProperties(label) ? {...label, alt: parsing.replaceMessageReferences(label.alt)} - : {...label}; + : label; return [imageLabel, value]; }); - if (hasImages || options.length < 2) return {options: trimmedOptions}; + if (hasNonTextContent || options.length < 2) { + return {options: trimmedOptions}; + } const stringOptions = trimmedOptions as [string, string][]; const stringLabels = stringOptions.map(([label]) => label); @@ -793,7 +798,7 @@ export class FieldDropdown extends Field { } else if (typeof option[1] !== 'string') { foundError = true; console.error( - `Invalid option[${i}]: Each FieldDropdown option id must be a string. + `Invalid option[${i}]: Each FieldDropdown option id must be a string. Found ${option[1]} in: ${option}`, ); } else if ( @@ -806,7 +811,7 @@ export class FieldDropdown extends Field { ) { foundError = true; console.error( - `Invalid option[${i}]: Each FieldDropdown option must have a string + `Invalid option[${i}]: Each FieldDropdown option must have a string label, image description, or HTML element. Found ${option[0]} in: ${option}`, ); }