Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(content): prevent editor extending on typing #933

Merged
merged 1 commit into from Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/content/templates/editor.vue
Expand Up @@ -2,7 +2,6 @@
<textarea
ref="textarea"
v-model="file"
@keyup.stop="onType"
@keydown.tab.exact.prevent="onTabRight"
@keydown.tab.shift.prevent="onTabLeft"
@compositionstart.prevent="isInComposition = true"
Expand Down Expand Up @@ -32,13 +31,18 @@ export default {
this.$refs.textarea.focus()
},
file () {
this.onType()
this.$emit('input', this.file)
}
},
methods: {
onType () {
const el = this.$refs.textarea
el.style.height = el.scrollHeight + 'px'

el.style.height = 'auto'
this.$nextTick(() => {
el.style.height = el.scrollHeight + 'px'
})
},
onTabRight(event) {
if (this.isInComposition) {
Expand Down
4 changes: 4 additions & 0 deletions packages/content/templates/nuxt-content.dev.vue
Expand Up @@ -98,7 +98,11 @@ export default {
}

.nuxt-content-editor {
box-sizing: border-box;
display: block;
width: 100%;
padding: 8px;
overflow: hidden;
resize: none;
Comment on lines +101 to +106
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

width: 100% + horizontal padding means the element overflows parents width.
So I added box-sizing: border-box.

Default style of textarea is display: inline-block but I explicitly set it as block (maybe this is just preference).

overflow: hidden is to make situation simple and prevent redundant scroll bar from appearing.

resize: none is also to make situation simple. That is, with overflow: hidden, if developer shrinks textarea vertically, overflown lines are hidden.

}
</style>