diff --git a/src/forms.ts b/src/forms.ts index c5bf49972a..863af198bf 100644 --- a/src/forms.ts +++ b/src/forms.ts @@ -94,7 +94,7 @@ export class Forms { }); document.querySelectorAll('.materialize-textarea').forEach((textArea: HTMLTextAreaElement) => { - Forms.textareaAutoResize(textArea); + Forms.InitTextarea(textArea); }); // File Input Path diff --git a/tests/spec/forms/formsSpec.js b/tests/spec/forms/formsSpec.js index b8e7009f5b..76b1856734 100644 --- a/tests/spec/forms/formsSpec.js +++ b/tests/spec/forms/formsSpec.js @@ -1,3 +1,5 @@ +const MULTILINE_TEXT = 'This is line 1.\nThis is line 2.\nThis is line 3.\nThis is line 4.\nThis is line 5.\nAnd this is line 6.'; + describe('Forms:', function () { beforeEach(async function () { await XloadFixtures(['forms/formsFixture.html']); @@ -46,6 +48,26 @@ describe('Forms:', function () { M.Forms.textareaAutoResize(el); expect(el.clientHeight).toBeGreaterThan(pHeight); }); + + it('Programmatically initialized textarea resize', () => { + const element = document.querySelector('#textarea'); + M.Forms.InitTextarea(element); + const textareaHeight = element.clientHeight; + element.value = MULTILINE_TEXT; + keydown(element, 13); + expect(element.clientHeight).toBeGreaterThan(textareaHeight); + }); + + it('Automatically initialized textarea resize', () => { + const event = new Event('DOMContentLoaded'); + document.dispatchEvent(event); + + const element = document.querySelector('#textarea'); + const textareaHeight = element.clientHeight; + element.value = MULTILINE_TEXT; + keydown(element, 13); + expect(element.clientHeight).toBeGreaterThan(textareaHeight); + }); }); // No active class added, because it is now a css feature only