From db66bbe5a1d823cce939e797013c6803ceb5da55 Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Mon, 16 Oct 2023 12:46:59 -0400 Subject: [PATCH] update comments --- src/internal/tabbable.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/internal/tabbable.ts b/src/internal/tabbable.ts index 9c692b75..d0516412 100644 --- a/src/internal/tabbable.ts +++ b/src/internal/tabbable.ts @@ -1,11 +1,16 @@ -// 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` -// https://stackoverflow.com/questions/19669786/check-if-element-is-visible-in-dom -// Previously, we used https://www.npmjs.com/package/composed-offset-position, but recursing up an entire -// node tree took up a lot of CPU cycles and made focus traps unusable in Chrome / Edge. +// +// This 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 shadow roots not having an `offsetParent`. +// +// See https://stackoverflow.com/questions/19669786/check-if-element-is-visible-in-dom +// +// Previously, we used https://www.npmjs.com/package/composed-offset-position, but recursing up an entire node tree took +// up a lot of CPU cycles and made focus traps unusable in Chrome / Edge. +// 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(); @@ -26,7 +31,6 @@ function isTabbable(el: HTMLElement) { } // Elements that are hidden have no offsetParent and are not tabbable - // !isRendered is added because otherwise it misses elements in Safari if (!isTakingUpSpace(el)) { return false; }