Skip to content

Commit

Permalink
✨ Finalize autoresize feature
Browse files Browse the repository at this point in the history
  • Loading branch information
marcreichel committed Feb 13, 2022
1 parent 3415ba6 commit 41b3da9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
23 changes: 20 additions & 3 deletions dist/alpine-autosize.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/alpine-autosize.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
function Autosize(Alpine) {
Alpine.directive('autosize', (el) => {
el.style.height = '4px';
el.style.height = `${el.scrollHeight}px`;
Alpine.directive('autosize', (el, {}, { cleanup }) => {
const previousResizeValue = el.style.resize;
el.style.resize = 'none';

const handler = (event) => {
const element = event.target;
element.style.height = '4px';
element.style.height = `${element.scrollHeight}px`;
};

handler({ target: el });

el.addEventListener('input', handler);

cleanup(() => {
el.style.resize = previousResizeValue;
el.removeEventListener('input', handler);
});
});
}

Expand Down

0 comments on commit 41b3da9

Please sign in to comment.