mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-01-10 00:47:45 +08:00
26 lines
462 B
JavaScript
26 lines
462 B
JavaScript
|
const BORDER_HEIGHT = 1;
|
||
|
|
||
|
/**
|
||
|
* A hook that automatically matches textarea height to its content.
|
||
|
*/
|
||
|
const TextareaAutosize = {
|
||
|
mounted() {
|
||
|
this.autosize();
|
||
|
|
||
|
this.el.addEventListener("input", (event) => {
|
||
|
this.autosize();
|
||
|
});
|
||
|
},
|
||
|
|
||
|
updated() {
|
||
|
this.autosize();
|
||
|
},
|
||
|
|
||
|
autosize() {
|
||
|
this.el.style.height = "0px";
|
||
|
this.el.style.height = `${this.el.scrollHeight + 2 * BORDER_HEIGHT}px`;
|
||
|
},
|
||
|
};
|
||
|
|
||
|
export default TextareaAutosize;
|