Skip to content

Commit

Permalink
🐛 fix: textarea の height が max-height を超えた時にのみ拡張ボタンが表示されるように条件を改善
Browse files Browse the repository at this point in the history
  • Loading branch information
reiroop committed Feb 3, 2025
1 parent bc316cb commit 0b29ec1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
39 changes: 19 additions & 20 deletions src/components/Main/MainView/MessageInput/MessageInputTextArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@focus="onFocus"
@blur="onBlur"
@paste="onPaste"
@autosize-updated="updateShowIsInputTextareaExpandButtonVisibility"

Check warning on line 25 in src/components/Main/MainView/MessageInput/MessageInputTextArea.vue

View check run for this annotation

Codecov / codecov/patch

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

Added line #L25 was not covered by tests
/>
<div :class="$style.over" />
<dropdown-suggester
Expand Down Expand Up @@ -78,6 +79,7 @@ const emit = defineEmits<{
(e: 'postMessage'): void
(e: 'modifierKeyDown'): void
(e: 'modifierKeyUp'): void
(e: 'autosize-updated'): void
}>()
const firefoxFlag = isFirefox()
Expand Down Expand Up @@ -143,16 +145,19 @@ const onBlur = () => {
emit('blur')
}
const textAreaAutoSizeMaxHeightShrunk = computed(() =>
isMobile.value ? 70 : 160
)

Check warning on line 150 in src/components/Main/MainView/MessageInput/MessageInputTextArea.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/MessageInput/MessageInputTextArea.vue#L148-L150

Added lines #L148 - L150 were not covered by tests
const textAreaAutoSizeMaxHeight = computed(() => {
if (props.isMaxHeightNone) {
return 'none'
}
if (isMobile.value) {
return props.isInputTextAreaExpanded ? '140px' : '70px'
} else {
return props.isInputTextAreaExpanded ? '320px' : '160px'
}
return (
(props.isInputTextAreaExpanded
? textAreaAutoSizeMaxHeightShrunk.value * 2
: textAreaAutoSizeMaxHeightShrunk.value) + 'px'

Check warning on line 159 in src/components/Main/MainView/MessageInput/MessageInputTextArea.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/MessageInput/MessageInputTextArea.vue#L152-L159

Added lines #L152 - L159 were not covered by tests
)
})

Check warning on line 161 in src/components/Main/MainView/MessageInput/MessageInputTextArea.vue

View check run for this annotation

Codecov / codecov/patch

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

Added line #L161 was not covered by tests
const scollbarWidth = getScrollbarWidth()
Expand All @@ -168,24 +173,18 @@ const showIsInputTextAreaExpandedButton = defineModel<boolean>(
}
)

Check warning on line 174 in src/components/Main/MainView/MessageInput/MessageInputTextArea.vue

View check run for this annotation

Codecov / codecov/patch

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

Added line #L174 was not covered by tests
const updateTextareaExpandButtonVisibility = () => {
if (textareaRef.value) {
const height = textareaRef.value.scrollHeight
if (isMobile.value) {
showIsInputTextAreaExpandedButton.value = height >= 70
} else {
showIsInputTextAreaExpandedButton.value = height >= 160
const updateShowIsInputTextareaExpandButtonVisibility = () => {
nextTick(() => {
if (textareaRef.value) {
showIsInputTextAreaExpandedButton.value =
textareaRef.value.scrollHeight > textAreaAutoSizeMaxHeightShrunk.value
}
}
})

Check warning on line 182 in src/components/Main/MainView/MessageInput/MessageInputTextArea.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/MessageInput/MessageInputTextArea.vue#L176-L182

Added lines #L176 - L182 were not covered by tests
}
watch(
value,
() => {
nextTick(() => {
updateTextareaExpandButtonVisibility()
})
},
[value],
updateShowIsInputTextareaExpandButtonVisibility,
{ immediate: true }
)

Check warning on line 189 in src/components/Main/MainView/MessageInput/MessageInputTextArea.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/MessageInput/MessageInputTextArea.vue#L185-L189

Added lines #L185 - L189 were not covered by tests
</script>
Expand Down
4 changes: 4 additions & 0 deletions src/components/UI/TextareaAutosize.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const emit = defineEmits<{
(e: 'focus'): void
(e: 'blur'): void
(e: 'paste', _val: ClipboardEvent): void
(e: 'autosize-updated'): void
}>()
const { value, onInput } = useTextModelSyncer(props, emit)
Expand All @@ -52,6 +53,9 @@ const focus = () => {
onMounted(() => {
if (textareaEle.value) {
autosize(textareaEle.value)
textareaEle.value.addEventListener('autosize:resized', () => {
emit('autosize-updated')
})

Check warning on line 58 in src/components/UI/TextareaAutosize.vue

View check run for this annotation

Codecov / codecov/patch

src/components/UI/TextareaAutosize.vue#L56-L58

Added lines #L56 - L58 were not covered by tests
}
})
watch([toRef(props, 'modelValue'), toRef(props, 'maxHeight')], async () => {

Check warning on line 61 in src/components/UI/TextareaAutosize.vue

View check run for this annotation

Codecov / codecov/patch

src/components/UI/TextareaAutosize.vue#L61

Added line #L61 was not covered by tests
Expand Down

0 comments on commit 0b29ec1

Please sign in to comment.