fix(components): [input] when textarea resize is both, the wordLimit position inaccurate (#7445)

This commit is contained in:
bqy_fe
2022-05-05 09:52:37 +08:00
committed by GitHub
parent 334117c2cb
commit 675311b7db

View File

@ -136,7 +136,11 @@
@change="handleChange"
@keydown="handleKeydown"
/>
<span v-if="isWordLimitVisible" :class="nsInput.e('count')">
<span
v-if="isWordLimitVisible"
:style="countStyle"
:class="nsInput.e('count')"
>
{{ textLength }} / {{ attrs.maxlength }}
</span>
</template>
@ -157,7 +161,7 @@ import {
useSlots,
watch,
} from 'vue'
import { isClient } from '@vueuse/core'
import { isClient, useResizeObserver } from '@vueuse/core'
import { isNil } from 'lodash-unified'
import { ElIcon } from '@element-plus/components/icon'
import {
@ -215,6 +219,7 @@ const focused = ref(false)
const hovering = ref(false)
const isComposing = ref(false)
const passwordVisible = ref(false)
const countStyle = ref<StyleValue>()
const textareaCalcStyle = shallowRef(props.inputStyle)
const _ref = computed(() => input.value || textarea.value)
@ -280,6 +285,16 @@ const suffixVisible = computed(
const [recordCursor, setCursor] = useCursor(input)
useResizeObserver(textarea, (entries) => {
if (!isWordLimitVisible.value || props.resize !== 'both') return
const entry = entries[0]
const { width } = entry.contentRect
countStyle.value = {
/** right: 100% - width + padding(15) + right(6) */
right: `calc(100% - ${width + 15 + 6}px)`,
}
})
const resizeTextarea = () => {
const { type, autosize } = props