mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(TextEllipsis): fix the logic of calculating the position of ellipsis (#12137)
This commit is contained in:
parent
02b6779c42
commit
c95d59e303
@ -40,7 +40,7 @@ export default defineComponent({
|
|||||||
const root = ref<HTMLElement>();
|
const root = ref<HTMLElement>();
|
||||||
|
|
||||||
const actionText = computed(() =>
|
const actionText = computed(() =>
|
||||||
expanded.value ? props.expandText : props.collapseText,
|
expanded.value ? props.collapseText : props.expandText,
|
||||||
);
|
);
|
||||||
|
|
||||||
const pxToNum = (value: string | null) => {
|
const pxToNum = (value: string | null) => {
|
||||||
@ -89,7 +89,7 @@ export default defineComponent({
|
|||||||
return dots + content.slice(right, end);
|
return dots + content.slice(right, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
const middle = Math.round((left + right) >> 1);
|
const middle = Math.round((left + right) / 2);
|
||||||
|
|
||||||
// Set the interception location
|
// Set the interception location
|
||||||
if (position === 'end') {
|
if (position === 'end') {
|
||||||
@ -127,21 +127,20 @@ export default defineComponent({
|
|||||||
rightPart[1] - rightPart[0] <= 1
|
rightPart[1] - rightPart[0] <= 1
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
content.slice(0, leftPart[1]) +
|
content.slice(0, leftPart[0]) +
|
||||||
dots +
|
dots +
|
||||||
content.slice(rightPart[1], end)
|
content.slice(rightPart[1], end)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const leftMiddle = Math.floor((leftPart[0] + leftPart[1]) >> 1);
|
const leftMiddle = Math.floor((leftPart[0] + leftPart[1]) / 2);
|
||||||
const rightMiddle = Math.ceil((rightPart[0] + rightPart[1]) >> 1);
|
const rightMiddle = Math.ceil((rightPart[0] + rightPart[1]) / 2);
|
||||||
|
|
||||||
container.innerText =
|
container.innerText =
|
||||||
props.content.slice(0, leftMiddle) +
|
props.content.slice(0, leftMiddle) +
|
||||||
props.dots +
|
props.dots +
|
||||||
actionText.value +
|
props.content.slice(rightMiddle, end) +
|
||||||
props.dots +
|
props.expandText;
|
||||||
props.content.slice(rightMiddle, end);
|
|
||||||
|
|
||||||
if (container.offsetHeight >= maxHeight) {
|
if (container.offsetHeight >= maxHeight) {
|
||||||
return middleTail(
|
return middleTail(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user