focus on visible elements
This commit is contained in:
parent
03e7e333a3
commit
d1a81a877f
3 changed files with 30 additions and 23 deletions
|
@ -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 };
|
||||
|
|
Reference in a new issue