Skip to content

Commit

Permalink
Merge pull request #485 from IvanPostu/issue-446
Browse files Browse the repository at this point in the history
fix: #446 Textarea not autoresize bug
  • Loading branch information
wuda-io authored Jul 7, 2024
2 parents 62192a3 + 647913e commit ca88d67
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class Forms {
});

document.querySelectorAll('.materialize-textarea').forEach((textArea: HTMLTextAreaElement) => {
Forms.textareaAutoResize(textArea);
Forms.InitTextarea(textArea);
});

// File Input Path
Expand Down
22 changes: 22 additions & 0 deletions tests/spec/forms/formsSpec.js
Original file line number Diff line number Diff line change
@@ -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']);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ca88d67

Please sign in to comment.