mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-01-09 08:27:36 +08:00
25 lines
462 B
JavaScript
25 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;
|