From 12c6eb017c436583d94e10dfcf15690ccfb90adb Mon Sep 17 00:00:00 2001 From: "Antoine (ande)" Date: Fri, 18 Aug 2023 20:33:02 +0200 Subject: [PATCH] [FIX] web: textarea do not resize properly Current behaviour: When clicking on a note containing multi-line text, the textarea shrinks Expected behaviour: Note should show whole text Steps to reproduce: 1. Install sale_management 2. Head to Sales > Quotations 3. Click on any quotation line 4. Click on "Add a note" 5. Input multi-line text 6. Click on the "Save manually" button 7. Click again on the note 8. Note is omly one character tall opw-3457234 closes odoo/odoo#134231 X-original-commit: 061430f1430723d719230796774cf4efab8aa348 Signed-off-by: Nicolas Lempereur (nle) Signed-off-by: Antoine Demany (ande) --- .../src/views/fields/text/text_field.js | 4 +- .../tests/views/fields/text_field_tests.js | 44 ++++++++++++++++++- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/views/fields/text/text_field.js b/addons/web/static/src/views/fields/text/text_field.js index f0b11df0f85..4df94c08b5c 100644 --- a/addons/web/static/src/views/fields/text/text_field.js +++ b/addons/web/static/src/views/fields/text/text_field.js @@ -48,9 +48,7 @@ export class TextField extends Component { }); useSpellCheck({ refName: "textarea" }); - if (!this.props.readonly) { - useAutoresize(this.textareaRef, { minimumHeight: this.minimumHeight }); - } + useAutoresize(this.textareaRef, { minimumHeight: this.minimumHeight }); } get isTranslatable() { diff --git a/addons/web/static/tests/views/fields/text_field_tests.js b/addons/web/static/tests/views/fields/text_field_tests.js index 64cba8d08a1..5d4c69ca9c8 100644 --- a/addons/web/static/tests/views/fields/text_field_tests.js +++ b/addons/web/static/tests/views/fields/text_field_tests.js @@ -22,7 +22,6 @@ let target; QUnit.module("Fields", (hooks) => { hooks.beforeEach(() => { target = getFixture(); - serverData = { models: { partner: { @@ -58,6 +57,17 @@ QUnit.module("Fields", (hooks) => { }, ], }, + partner_list: { + fields: { + partner_ids: { + string: "Partners", + type: "one2many", + relation: "partner", + relation_field: "id", + }, + }, + records: [{ id: 1, partner_ids: [1] }], + }, }, }; @@ -633,4 +643,36 @@ QUnit.module("Fields", (hooks) => { await nextTick(); assert.containsOnce(document.body, ".o_popover .o_model_field_selector_popover"); }); + + QUnit.test("text field should vertical autoresize when saving", async function (assert) { + serverData.models.partner.fields.foo.type = "text"; + serverData.models.partner.records[0].foo = "1"; + await makeView({ + type: "form", + resModel: "partner_list", + resId: 1, + serverData, + arch: ` +
+ + + + + +
`, + }); + + await click(target, "[name=foo] div"); + let textarea = target.querySelector(".o_field_widget[name='foo'] textarea"); + const initialHeight = textarea.offsetHeight; + + await editInput(textarea, null, "1\n2\n3\n4\n5\n6\n7\n8"); + await clickSave(target); + + await click(target, "[name=foo] div"); + textarea = target.querySelector(".o_field_widget[name='foo'] textarea"); + const afterHeight = textarea.offsetHeight; + + assert.ok(afterHeight > initialHeight, "Should be taller than one character"); + }); });