18 lines
381 B
JavaScript
18 lines
381 B
JavaScript
import { tick } from "svelte";
|
|
|
|
export function autoGrow(node) {
|
|
function resize() {
|
|
node.style.height = "auto";
|
|
node.style.height = node.scrollHeight + "px";
|
|
}
|
|
|
|
// wait until DOM updates to apply initial value
|
|
tick().then(resize);
|
|
node.addEventListener("input", resize);
|
|
|
|
return {
|
|
destroy() {
|
|
node.removeEventListener("input", resize);
|
|
}
|
|
};
|
|
} |