From d1a81a877f0e7364b7d69e214ec74151d76dd25c Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 15 Jan 2018 21:56:10 +0900 Subject: focus on visible elements --- src/shared/utils/dom.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/shared/utils/dom.js') 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 }; -- cgit v1.2.3 From 526009ba52f444df16975ea07e5e42598eeaa3d6 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 20 Jan 2018 21:00:39 +0900 Subject: fix for slack scroll --- src/shared/utils/dom.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/shared/utils/dom.js') diff --git a/src/shared/utils/dom.js b/src/shared/utils/dom.js index f138c33..974d534 100644 --- a/src/shared/utils/dom.js +++ b/src/shared/utils/dom.js @@ -83,7 +83,9 @@ const viewportRect = (e) => { const isVisible = (element) => { let rect = element.getBoundingClientRect(); - if (rect.width === 0 || rect.height === 0) { + let style = window.getComputedStyle(element); + + if (style.overflow !== 'visible' && (rect.width === 0 || rect.height === 0)) { return false; } if (rect.right < 0 && rect.bottom < 0) { -- cgit v1.2.3