Created
March 22, 2023 10:59
-
-
Save Henxed/5f77303519a0b68ed23c9daf7936beda to your computer and use it in GitHub Desktop.
Auto Resize Textarea (inertia.js, vue3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('./bootstrap'); | |
import { createApp, h } from 'vue'; | |
import { createInertiaApp } from '@inertiajs/vue3'; | |
import AutoResizeTextarea from '@/AutoResizeTextarea' | |
/*....*/ | |
createInertiaApp({ | |
title: (title) => `${title} - ${appName}`, | |
progress: { | |
color: '#1e293b', | |
}, | |
resolve: (name) => require(`./Pages/${name}.vue`), | |
setup({ el, App, props, plugin }) { | |
let ap = createApp({ render: () => h(App, props) }) | |
.use(......) | |
/* more */ | |
.use(AutoResizeTextarea) | |
/* more */ | |
.mixin({ methods: { route } }); | |
ap.config.globalProperties.$moment=moment; | |
return ap.mount(el); | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
install: (app) => { | |
app.directive("autoresize", { | |
mounted(el) { | |
el.style.height = el.scrollHeight < 64 ? '64px' : el.scrollHeight + 'px'; | |
el.style.overflow = 'hidden'; | |
el.addEventListener('input', () => { | |
el.style.height = 'auto'; | |
el.style.height = el.scrollHeight < 64 ? '64px' : el.scrollHeight + 'px'; | |
}); | |
} | |
}); | |
}, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- use directive v-autoresize --> | |
<textarea v-model="form.text" class="form-textarea" v-autoresize></textarea> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment