Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added parentNode padding to targetWidth calculation #44

Closed
wants to merge 4 commits into from
Closed
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
10 changes: 9 additions & 1 deletion src/Truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down