-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from metalabdesign/container-detection
Improve parent container detection
- Loading branch information
Showing
5 changed files
with
118 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// @flow | ||
|
||
import findAncestor from './findAncestor'; | ||
|
||
const getClippingBlock = (node: ?Node): HTMLElement | null => { | ||
const result = findAncestor((node) => { | ||
if (node === document.documentElement) return true; | ||
|
||
const style = getComputedStyle(node); | ||
|
||
return style.overflow && style.overflow !== 'visible'; | ||
}, node); | ||
|
||
return result; | ||
}; | ||
|
||
export default getClippingBlock; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// @flow | ||
|
||
import {Rect} from 'flowtip-core'; | ||
|
||
const getContentRect = (node: HTMLElement): Rect => { | ||
const rect = node.getBoundingClientRect(); | ||
const style = getComputedStyle(node); | ||
|
||
const topBorder = parseInt(style.borderTopWidth, 10); | ||
const rightBorder = parseInt(style.borderRightWidth, 10); | ||
const bottomBorder = parseInt(style.borderBottomWidth, 10); | ||
const leftBorder = parseInt(style.borderLeftWidth, 10); | ||
|
||
return new Rect( | ||
rect.left + leftBorder || 0, | ||
rect.top + topBorder || 0, | ||
Math.min(rect.width - leftBorder - rightBorder, node.clientWidth) || 0, | ||
Math.min(rect.height - topBorder - bottomBorder, node.clientHeight) || 0, | ||
); | ||
}; | ||
|
||
export default getContentRect; |