Skip to content

Commit

Permalink
fix: fix the truncate error about html
Browse files Browse the repository at this point in the history
  • Loading branch information
ruofee committed Sep 12, 2023
1 parent 279fcce commit abdebf7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/components/JsEllipsis.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ export default class JsEllipsis extends Vue {
private truncateHTML(container: HTMLElement, textContainer: HTMLElement, max: number) {
// only enter this function when container overflow.
const children = textContainer.childNodes;
if (children.length === 0) {
// remove parent node
return false;
}
if (children.length === 1) {
const node = children[0] as HTMLElement;
if (node.nodeType === Node.TEXT_NODE) {
Expand Down Expand Up @@ -240,7 +244,11 @@ export default class JsEllipsis extends Vue {
);
if (textContainer.childNodes[i]) {
// truncate the critical node
this.truncateHTML(container, textContainer.childNodes[i] as HTMLElement, max);
const truncateResult = this.truncateHTML(container, textContainer.childNodes[i] as HTMLElement, max);
// if truncateResult be false, it means that node should be removed
if (truncateResult === false) {
textContainer.removeChild(textContainer.childNodes[i]);
}
}
}
}
Expand Down

0 comments on commit abdebf7

Please sign in to comment.