Skip to content

Commit 98f2838

Browse files
committed
add renderLastLine method to overriding if it need
1 parent 373aa7a commit 98f2838

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Truncate.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default class Truncate extends Component {
3131
this.measureWidth = this.measureWidth.bind(this);
3232
this.getLines = this.getLines.bind(this);
3333
this.renderLine = this.renderLine.bind(this);
34+
this.renderLastLine = this.renderLastLine.bind(this);
3435
}
3536

3637
componentDidMount() {
@@ -171,14 +172,14 @@ export default class Truncate extends Component {
171172
const {
172173
elements,
173174
props: {
174-
lines: numLines,
175-
ellipsis
175+
lines: numLines
176176
},
177177
state: {
178178
targetWidth
179179
},
180180
innerText,
181181
measureWidth,
182+
renderLastLine,
182183
onTruncate
183184
} = this;
184185

@@ -230,7 +231,7 @@ export default class Truncate extends Component {
230231
}
231232
}
232233

233-
resultLine = <span>{textRest.slice(0, lower)}{ellipsis}</span>;
234+
resultLine = renderLastLine(textRest.slice(0, lower), textWords);
234235
} else {
235236
// Binary search determining when the line breaks
236237
let lower = 0;
@@ -284,6 +285,11 @@ export default class Truncate extends Component {
284285
}
285286
}
286287

288+
renderLastLine(splicedText, originalArray) {
289+
const { ellipsis } = this.props;
290+
return (<span>{splicedText}{ellipsis}</span>);
291+
}
292+
287293
render() {
288294
const {
289295
elements: {

0 commit comments

Comments
 (0)