Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default class Truncate extends Component {
this.measureWidth = this.measureWidth.bind(this);
this.getLines = this.getLines.bind(this);
this.renderLine = this.renderLine.bind(this);
this.renderLastLine = this.renderLastLine.bind(this);
}

componentDidMount() {
Expand Down Expand Up @@ -171,14 +172,14 @@ export default class Truncate extends Component {
const {
elements,
props: {
lines: numLines,
ellipsis
lines: numLines
},
state: {
targetWidth
},
innerText,
measureWidth,
renderLastLine,
onTruncate
} = this;

Expand Down Expand Up @@ -230,7 +231,7 @@ export default class Truncate extends Component {
}
}

resultLine = <span>{textRest.slice(0, lower)}{ellipsis}</span>;
resultLine = renderLastLine(textRest.slice(0, lower), textWords);
} else {
// Binary search determining when the line breaks
let lower = 0;
Expand Down Expand Up @@ -284,6 +285,11 @@ export default class Truncate extends Component {
}
}

renderLastLine(splicedText, originalArray) {
const { ellipsis } = this.props;
return (<span>{splicedText}{ellipsis}</span>);
}

render() {
const {
elements: {
Expand Down