Skip to content

Commit 36c529b

Browse files
committed
feat: MessageInput コンポーネントにテキストエリアのサイズ変更イベントを追加し、ボタン表示の条件を更新
1 parent 0424a10 commit 36c529b

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
<message-input-text-area
3939
ref="textareaComponentRef"
4040
v-model="state.text"
41+
v-model:show-is-input-text-area-expanded-button="
42+
showIsInputTextAreaExpandedButton
43+
"
4144
:channel-id="channelId"
4245
:is-posting="isPosting"
4346
:shrink-to-one-line="
@@ -114,7 +117,7 @@ const { channelsMap } = useChannelsStore()
114117
const isLeftControlsExpanded = ref(false)
115118
const isPreviewShown = ref(false)
116119
const isInputTextAreaExpanded = ref(true)
117-
const showIsInputTextAreaExpandedButton = ref(true)
120+
const showIsInputTextAreaExpandedButton = ref(false)
118121
119122
const isArchived = computed(
120123
() => channelsMap.value.get(props.channelId)?.archived ?? false

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
@focus="onFocus"
2222
@blur="onBlur"
2323
@paste="onPaste"
24+
@resized="onResize"
2425
/>
2526
<div :class="$style.over" />
2627
<dropdown-suggester
@@ -146,6 +147,24 @@ const scollbarWidth = getScrollbarWidth()
146147
const style = {
147148
'--input-scrollbar-width': `${scollbarWidth}px`
148149
}
150+
151+
const showIsInputTextAreaExpandedButton = defineModel<boolean>(
152+
'showIsInputTextAreaExpandedButton',
153+
{
154+
default: false
155+
}
156+
)
157+
158+
const onResize = () => {
159+
if (textareaRef.value) {
160+
const height = textareaRef.value.scrollHeight
161+
if (isMobile.value) {
162+
showIsInputTextAreaExpandedButton.value = height >= 70
163+
} else {
164+
showIsInputTextAreaExpandedButton.value = height >= 160
165+
}
166+
}
167+
}
149168
</script>
150169

151170
<style lang="scss" module>

src/components/UI/TextareaAutosize.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</template>
1919

2020
<script lang="ts" setup>
21-
import { onBeforeUnmount, onMounted, ref, toRef, watch, nextTick } from 'vue'
2221
import autosize from 'autosize'
22+
import { nextTick, onBeforeUnmount, onMounted, ref, toRef, watch } from 'vue'
2323
import useTextModelSyncer from '/@/composables/useTextModelSyncer'
2424
2525
const props = defineProps<{
@@ -39,6 +39,7 @@ const emit = defineEmits<{
3939
(e: 'focus'): void
4040
(e: 'blur'): void
4141
(e: 'paste', _val: ClipboardEvent): void
42+
(e: 'resized'): 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('resized')
58+
})
5559
}
5660
})
5761
watch(toRef(props, 'modelValue'), async () => {
@@ -62,6 +66,9 @@ watch(toRef(props, 'modelValue'), async () => {
6266
})
6367
onBeforeUnmount(() => {
6468
if (textareaEle.value) {
69+
textareaEle.value.removeEventListener('autosize:resized', () => {
70+
emit('resized')
71+
})
6572
autosize.destroy(textareaEle.value)
6673
}
6774
})

0 commit comments

Comments
 (0)