Skip to content

Commit 86352e5

Browse files
committed
Take letter-spacing into account when sizing container.
1 parent e95e1fc commit 86352e5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Truncate.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ export default class Truncate extends Component {
156156
}
157157

158158
measureWidth(text) {
159-
return this.canvas.measureText(text).width;
159+
const targetStyles = window.getComputedStyle(this.refs.target);
160+
const letterSpacing = parseFloat(targetStyles['letter-spacing']) || 0;
161+
return this.canvas.measureText(text).width + (letterSpacing * text.length);
160162
}
161163

162164
ellipsisWidth(node) {

0 commit comments

Comments
 (0)