kopia lustrzana https://github.com/shoelace-style/shoelace
fix: improve tabbable performance
rodzic
d5ab0fef22
commit
371e021c9d
|
@ -1,5 +1,8 @@
|
|||
import { offsetParent } from 'composed-offset-position';
|
||||
|
||||
// It doesn't technically check visibility, it checks if the element has been rendered and can maybe possibly be tabbed to.
|
||||
// This is a workaround for shadowroots not having an `offsetParent`
|
||||
function isTakingUpSpace (elem: HTMLElement): boolean {
|
||||
return Boolean( elem.offsetParent || elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length );
|
||||
}
|
||||
/** Determines if the specified element is tabbable using heuristics inspired by https://github.com/focus-trap/tabbable */
|
||||
function isTabbable(el: HTMLElement) {
|
||||
const tag = el.tagName.toLowerCase();
|
||||
|
@ -20,8 +23,8 @@ function isTabbable(el: HTMLElement) {
|
|||
}
|
||||
|
||||
// Elements that are hidden have no offsetParent and are not tabbable
|
||||
// offsetParent() is added because otherwise it misses elements in Safari
|
||||
if (el.offsetParent === null && offsetParent(el) === null) {
|
||||
// !isRendered is added because otherwise it misses elements in Safari
|
||||
if (!isTakingUpSpace(el)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue