Skip to content

Commit 3fd935e

Browse files
committed
Take parent padding into account when sizing container.
1 parent fd1b389 commit 3fd935e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Truncate.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ export default class Truncate extends Component {
127127
return;
128128
}
129129

130-
const targetWidth = target.parentNode.getBoundingClientRect().width;
130+
const targetParentStyles = window.getComputedStyle(target.parentNode);
131+
const targetParentPadding = parseFloat(targetParentStyles.paddingLeft) +
132+
parseFloat(targetParentStyles.paddingRight);
133+
const targetWidth = target.parentNode.getBoundingClientRect().width -
134+
targetParentPadding;
131135

132136
// Delay calculation until parent node is inserted to the document
133137
// Mounting order in React is ChildComponent, ParentComponent

0 commit comments

Comments
 (0)