Fix RTL text field positioning bug by ensuring a reflow (#2779)

This commit is contained in:
Sam El-Husseini
2019-08-07 10:54:36 -07:00
committed by GitHub
parent 5ada490eca
commit 36135ac62b

View File

@@ -161,7 +161,17 @@ Blockly.FieldTextInput.prototype.render_ = function() {
// This logic is done in render_ rather than doValueInvalid_ or
// doValueUpdate_ so that the code is more centralized.
if (this.isBeingEdited_) {
this.resizeEditor_();
if (this.sourceBlock_.RTL) {
// in RTL, we need to let the browser reflow before resizing
// in order to get the correct bounding box of the borderRect
// avoiding issue #2777.
var field = this;
setTimeout(function() {
field.resizeEditor_();
}, 0);
} else {
this.resizeEditor_();
}
if (!this.isTextValid_) {
Blockly.utils.dom.addClass(this.htmlInput_, 'blocklyInvalidInput');
} else {
@@ -247,7 +257,11 @@ Blockly.FieldTextInput.prototype.widgetCreate_ = function() {
htmlInput.value = htmlInput.defaultValue = this.value_;
htmlInput.untypedDefaultValue_ = this.value_;
htmlInput.oldValue_ = null;
this.resizeEditor_();
// Ensure the browser reflows before resizing to avoid issue #2777.
var field = this;
setTimeout(function() {
field.resizeEditor_();
}, 0);
this.bindInputEvents_(htmlInput);