-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(esl-popup): add bottom, left, right position and update position…
… when parents scroll
- Loading branch information
Showing
9 changed files
with
312 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {getWindow} from './getWindow'; | ||
|
||
export function getComputedStyle(element: Element): CSSStyleDeclaration { | ||
return getWindow(element).getComputedStyle(element); | ||
} |
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,5 @@ | ||
export function getDocumentElement(element: Element | Window): Element { | ||
return ((element instanceof Window | ||
? element.document | ||
: element.ownerDocument) || window.document).documentElement; | ||
} |
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,3 @@ | ||
export function getNodeName(element?: Node | Window): string { | ||
return element && !(element instanceof Window)? (element.nodeName).toLowerCase() : ''; | ||
} |
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,12 @@ | ||
import {getNodeName} from './getNodeName'; | ||
import {getDocumentElement} from './getDocumentElement'; | ||
|
||
export function getParentNode(element: Element | ShadowRoot): Node { | ||
if (getNodeName(element) === 'html') { | ||
return element; | ||
} | ||
|
||
return (element instanceof ShadowRoot | ||
? element.host | ||
: element.assignedSlot || element.parentNode) || getDocumentElement(element as Element); | ||
} |
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,15 @@ | ||
import {getNodeName} from './getNodeName'; | ||
import {isScrollParent} from './isScrollParent'; | ||
import {getParentNode} from './getParentNode'; | ||
|
||
export function getScrollParent(node: Node): Element { | ||
if (['html', 'body', '#document'].indexOf(getNodeName(node)) >= 0) { | ||
return node.ownerDocument?.body as Element; | ||
} | ||
|
||
if (node instanceof HTMLElement && isScrollParent(node as Element)) { | ||
return node as Element; | ||
} | ||
|
||
return getScrollParent(getParentNode(node as Element)); | ||
} |
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,12 @@ | ||
export function getWindow(node: Node | Window): Window { | ||
if (node == null) { | ||
return window; | ||
} | ||
|
||
if (node instanceof Window) { | ||
return node; | ||
} | ||
|
||
const ownerDocument = node.ownerDocument; | ||
return ownerDocument ? ownerDocument.defaultView || window : window; | ||
} |
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,7 @@ | ||
import {getComputedStyle} from './getComputedStyle'; | ||
|
||
export function isScrollParent(element: Element): boolean { | ||
// Firefox wants us to check `-x` and `-y` variations as well | ||
const {overflow, overflowX, overflowY} = getComputedStyle(element); | ||
return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX); | ||
} |
Oops, something went wrong.