diff --git a/src/Truncate.js b/src/Truncate.js index 7fbdc516..7b154090 100644 --- a/src/Truncate.js +++ b/src/Truncate.js @@ -128,7 +128,7 @@ export default class Truncate extends Component { return; } - const targetWidth = target.parentNode.getBoundingClientRect().width; + let targetWidth = target.parentNode.getBoundingClientRect().width; // Delay calculation until parent node is inserted to the document // Mounting order in React is ChildComponent, ParentComponent @@ -147,6 +147,14 @@ export default class Truncate extends Component { canvas.font = font; + const parentStyle = window.getComputedStyle(target.parentNode); + + const parentPadding = ( + ((parseInt(parentStyle['padding-left'])!=NaN)?parseInt(parentStyle['padding-left']):0) + + ((parseInt(parentStyle['padding-right'])!=NaN)?parseInt(parentStyle['padding-right']):0)); + + targetWidth-=parentPadding; + this.setState({ targetWidth }, callback);