mirror of
https://github.com/element-plus/element-plus.git
synced 2025-08-18 14:12:56 +08:00
fix(components): [input] when textarea resize is both, the wordLimit position inaccurate (#7445)
This commit is contained in:
@ -136,7 +136,11 @@
|
|||||||
@change="handleChange"
|
@change="handleChange"
|
||||||
@keydown="handleKeydown"
|
@keydown="handleKeydown"
|
||||||
/>
|
/>
|
||||||
<span v-if="isWordLimitVisible" :class="nsInput.e('count')">
|
<span
|
||||||
|
v-if="isWordLimitVisible"
|
||||||
|
:style="countStyle"
|
||||||
|
:class="nsInput.e('count')"
|
||||||
|
>
|
||||||
{{ textLength }} / {{ attrs.maxlength }}
|
{{ textLength }} / {{ attrs.maxlength }}
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
@ -157,7 +161,7 @@ import {
|
|||||||
useSlots,
|
useSlots,
|
||||||
watch,
|
watch,
|
||||||
} from 'vue'
|
} from 'vue'
|
||||||
import { isClient } from '@vueuse/core'
|
import { isClient, useResizeObserver } from '@vueuse/core'
|
||||||
import { isNil } from 'lodash-unified'
|
import { isNil } from 'lodash-unified'
|
||||||
import { ElIcon } from '@element-plus/components/icon'
|
import { ElIcon } from '@element-plus/components/icon'
|
||||||
import {
|
import {
|
||||||
@ -215,6 +219,7 @@ const focused = ref(false)
|
|||||||
const hovering = ref(false)
|
const hovering = ref(false)
|
||||||
const isComposing = ref(false)
|
const isComposing = ref(false)
|
||||||
const passwordVisible = ref(false)
|
const passwordVisible = ref(false)
|
||||||
|
const countStyle = ref<StyleValue>()
|
||||||
const textareaCalcStyle = shallowRef(props.inputStyle)
|
const textareaCalcStyle = shallowRef(props.inputStyle)
|
||||||
|
|
||||||
const _ref = computed(() => input.value || textarea.value)
|
const _ref = computed(() => input.value || textarea.value)
|
||||||
@ -280,6 +285,16 @@ const suffixVisible = computed(
|
|||||||
|
|
||||||
const [recordCursor, setCursor] = useCursor(input)
|
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 resizeTextarea = () => {
|
||||||
const { type, autosize } = props
|
const { type, autosize } = props
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user