From 4c4c8be1429ac2f01298574a7d617cd3eb76b0a3 Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Mon, 14 Aug 2017 16:09:27 -0700 Subject: [PATCH] Fix wrong width of field_dropdown with an image on Edge / IE (#1278) --- core/field_dropdown.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 7ece4e8dc..c5bac1b8c 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -413,6 +413,26 @@ Blockly.FieldDropdown.prototype.render_ = function() { this.size_.width + Blockly.BlockSvg.SEP_SPACE_X); }; +/** + * Updates the width of the field. Overrides field.prototype.updateWidth to + * deal with image selections on IE and Edge. If the selected item is not an + * image, or if the browser is not IE / Edge, this simply calls the parent + * implementation. + */ +Blockly.FieldDropdown.prototype.updateWidth = function() { + if (this.imageJson_ && (goog.userAgent.IE || goog.userAgent.EDGE)) { + // Recalculate the full width. + var arrowWidth = Blockly.Field.getCachedWidth(this.arrow_); + var width = Number(this.imageJson_.width) + arrowWidth + Blockly.BlockSvg.SEP_SPACE_X; + if (this.borderRect_) { + this.borderRect_.setAttribute('width', width); + } + this.size_.width = width; + } else { + Blockly.Field.prototype.updateWidth.call(this); + } +}; + /** * Close the dropdown menu if this input is being deleted. */