diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-01-18 10:41:08 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-18 10:41:08 +0000 |
commit | 1f57547c0ab1dab1aa615e2b543067855719ab6f (patch) | |
tree | f87441ed3a9889a75a698225151e7b10a07ae1b6 /src/shared/utils/dom.js | |
parent | cc634d0e7fc33d60e67df5a0cbbcfbf365120c5a (diff) | |
parent | d1a81a877f0e7364b7d69e214ec74151d76dd25c (diff) |
Merge pull request #308 from ueokande/focus-input
Focus input
Diffstat (limited to 'src/shared/utils/dom.js')
-rw-r--r-- | src/shared/utils/dom.js | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/shared/utils/dom.js b/src/shared/utils/dom.js index d4fd68a..f138c33 100644 --- a/src/shared/utils/dom.js +++ b/src/shared/utils/dom.js @@ -81,4 +81,26 @@ const viewportRect = (e) => { }; }; -export { isContentEditable, viewportRect }; +const isVisible = (element) => { + let rect = element.getBoundingClientRect(); + if (rect.width === 0 || rect.height === 0) { + return false; + } + if (rect.right < 0 && rect.bottom < 0) { + return false; + } + if (window.innerWidth < rect.left && window.innerHeight < rect.top) { + return false; + } + if (element.nodeName === 'INPUT' && element.type.toLowerCase() === 'hidden') { + return false; + } + + let { display, visibility } = window.getComputedStyle(element); + if (display === 'none' || visibility === 'hidden') { + return false; + } + return true; +}; + +export { isContentEditable, viewportRect, isVisible }; |