Skip to content

Commit 0b29ec1

Browse files
committed
🐛 fix: textarea の height が max-height を超えた時にのみ拡張ボタンが表示されるように条件を改善
1 parent bc316cb commit 0b29ec1

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

src/components/Main/MainView/MessageInput/MessageInputTextArea.vue

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@focus="onFocus"
2323
@blur="onBlur"
2424
@paste="onPaste"
25+
@autosize-updated="updateShowIsInputTextareaExpandButtonVisibility"
2526
/>
2627
<div :class="$style.over" />
2728
<dropdown-suggester
@@ -78,6 +79,7 @@ const emit = defineEmits<{
7879
(e: 'postMessage'): void
7980
(e: 'modifierKeyDown'): void
8081
(e: 'modifierKeyUp'): void
82+
(e: 'autosize-updated'): void
8183
}>()
8284
8385
const firefoxFlag = isFirefox()
@@ -143,16 +145,19 @@ const onBlur = () => {
143145
emit('blur')
144146
}
145147
148+
const textAreaAutoSizeMaxHeightShrunk = computed(() =>
149+
isMobile.value ? 70 : 160
150+
)
151+
146152
const textAreaAutoSizeMaxHeight = computed(() => {
147153
if (props.isMaxHeightNone) {
148154
return 'none'
149155
}
150-
151-
if (isMobile.value) {
152-
return props.isInputTextAreaExpanded ? '140px' : '70px'
153-
} else {
154-
return props.isInputTextAreaExpanded ? '320px' : '160px'
155-
}
156+
return (
157+
(props.isInputTextAreaExpanded
158+
? textAreaAutoSizeMaxHeightShrunk.value * 2
159+
: textAreaAutoSizeMaxHeightShrunk.value) + 'px'
160+
)
156161
})
157162
158163
const scollbarWidth = getScrollbarWidth()
@@ -168,24 +173,18 @@ const showIsInputTextAreaExpandedButton = defineModel<boolean>(
168173
}
169174
)
170175
171-
const updateTextareaExpandButtonVisibility = () => {
172-
if (textareaRef.value) {
173-
const height = textareaRef.value.scrollHeight
174-
if (isMobile.value) {
175-
showIsInputTextAreaExpandedButton.value = height >= 70
176-
} else {
177-
showIsInputTextAreaExpandedButton.value = height >= 160
176+
const updateShowIsInputTextareaExpandButtonVisibility = () => {
177+
nextTick(() => {
178+
if (textareaRef.value) {
179+
showIsInputTextAreaExpandedButton.value =
180+
textareaRef.value.scrollHeight > textAreaAutoSizeMaxHeightShrunk.value
178181
}
179-
}
182+
})
180183
}
181184
182185
watch(
183-
value,
184-
() => {
185-
nextTick(() => {
186-
updateTextareaExpandButtonVisibility()
187-
})
188-
},
186+
[value],
187+
updateShowIsInputTextareaExpandButtonVisibility,
189188
{ immediate: true }
190189
)
191190
</script>

src/components/UI/TextareaAutosize.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const emit = defineEmits<{
3939
(e: 'focus'): void
4040
(e: 'blur'): void
4141
(e: 'paste', _val: ClipboardEvent): void
42+
(e: 'autosize-updated'): void
4243
}>()
4344
4445
const { value, onInput } = useTextModelSyncer(props, emit)
@@ -52,6 +53,9 @@ const focus = () => {
5253
onMounted(() => {
5354
if (textareaEle.value) {
5455
autosize(textareaEle.value)
56+
textareaEle.value.addEventListener('autosize:resized', () => {
57+
emit('autosize-updated')
58+
})
5559
}
5660
})
5761
watch([toRef(props, 'modelValue'), toRef(props, 'maxHeight')], async () => {

0 commit comments

Comments
 (0)