From 8de783ec49236d7afa0a9bed86f8f0da3972c094 Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Mon, 6 Jul 2020 10:55:00 -0700 Subject: [PATCH] Fix field dropdown with images (#4016) * Fix field dropdown with images --- core/menuitem.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/menuitem.js b/core/menuitem.js index c9ba07981..8ff6cfc85 100644 --- a/core/menuitem.js +++ b/core/menuitem.js @@ -20,15 +20,15 @@ goog.require('Blockly.utils.IdGenerator'); /** * Class representing an item in a menu. * - * @param {string} content Text caption to display as the content of - * the item. + * @param {string|!HTMLElement} content Text caption to display as the content + * of the item, or a HTML element to display. * @param {string=} opt_value Data/model associated with the menu item. * @constructor */ Blockly.MenuItem = function(content, opt_value) { /** - * Human-readable text of this menu item. - * @type {string} + * Human-readable text of this menu item, or the HTML element to display. + * @type {string|!HTMLElement} * @private */ this.content_ = content; @@ -125,7 +125,11 @@ Blockly.MenuItem.prototype.createDom = function() { content.appendChild(checkbox); } - content.appendChild(document.createTextNode(this.content_)); + var contentDom = /** @type {!HTMLElement} */ (this.content_); + if (typeof this.content_ == 'string') { + contentDom = document.createTextNode(this.content_); + } + content.appendChild(contentDom); element.appendChild(content); // Initialize ARIA role and state.