From 98b348325a8f53a5d6911e4c9b76f6fce5bee5d9 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Thu, 11 Apr 2024 16:09:59 -0300 Subject: [PATCH] Fix autoresize not working well in Firefox on page load --- lib/TextArea/V5.js | 11 +++++++++++ src/Nri/Ui/TextArea/V5.elm | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/TextArea/V5.js b/lib/TextArea/V5.js index 4cc5461d..0a70b504 100644 --- a/lib/TextArea/V5.js +++ b/lib/TextArea/V5.js @@ -12,6 +12,17 @@ CustomElement.create({ onConnect: function () { this._textarea = this.querySelector("textarea"); this._updateListener(); + + // In Firefox, for some reason, the `scrollHeight` property isn't correct + // when the component is connected. It is correct when the window loads, though, + // so we also perform a resize when that happens. + // We end up doing this in all browsers, but it's fine: the second resize is a no-op. + var self = this; + window.addEventListener("load", function () { + if (self._autoresize) { + self._resize(); + } + }); }, observedAttributes: ["data-autoresize"], diff --git a/src/Nri/Ui/TextArea/V5.elm b/src/Nri/Ui/TextArea/V5.elm index eda8ae6b..e6bcb043 100644 --- a/src/Nri/Ui/TextArea/V5.elm +++ b/src/Nri/Ui/TextArea/V5.elm @@ -20,8 +20,9 @@ module Nri.Ui.TextArea.V5 exposing ### Patch changes - - no longer defaults the placeholder value to the label text + - No longer defaults the placeholder value to the label text - Adjust disabled styles + - Fix initial autoresize not working in Firefox ### Changes from V4