-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Snapshot: fix stuck focus in snapshots with hidden links #158
Conversation
Wouldn't this do the trick? diff --git a/src/dom/common/dom-view.tsx b/src/dom/common/dom-view.tsx
index 8bb2b1a..ae5bee4 100644
--- a/src/dom/common/dom-view.tsx
+++ b/src/dom/common/dom-view.tsx
@@ -466,7 +466,8 @@ abstract class DOMView<State extends DOMViewState, Data> {
...this._annotationShadowRoot.querySelectorAll('[tabindex="-1"]')
] as (HTMLElement | SVGElement)[];
focusableElements = focusableElements.filter(
- el => isPageRectVisible(getBoundingPageRect(el), this._iframeWindow, 0)
+ el => getComputedStyle(el).visibility === 'visible'
+ && isPageRectVisible(getBoundingPageRect(el), this._iframeWindow, 0)
);
focusableElements.sort((a, b) => {
let rangeA; |
The issue is that there are a few other instances when a focusable node would not actually be focusable, I think. Like if it's marked as Since a snapshot can theoretically have any stylesheet, I thought it might be more error-resistant and future-proof to just keep going until focus actually lands. That way, it doesn't matter why the focus did not take. Otherwise, we would have to potentially enumerate all those instances that could interfere with focus, and it might be easy to miss some of them. At the same time, maybe it is just easier to start with filtering based on a few most common properties ( |
Do the 0 width/height, In any case, we can keep the iterative approach, but let's:
|
If this isn't very clear, I can implement |
You are correct! I must have misremembered the root of one of earlier VPAT issues when focus wouldn't land on the elements. opacity, z-index and width/height indeed do not prevent focus from landing on a node. So then, the only instances when a link/button/etc. need to be skipped because they cannot be focused are: |
Yeah, let's just do that for now and see if anyone reports further issues. We also don't need to handle diff --git a/src/dom/common/dom-view.tsx b/src/dom/common/dom-view.tsx
index 8bb2b1a..173465d 100644
--- a/src/dom/common/dom-view.tsx
+++ b/src/dom/common/dom-view.tsx
@@ -465,9 +465,12 @@ abstract class DOMView<State extends DOMViewState, Data> {
...this._iframeDocument.querySelectorAll('a, area'),
...this._annotationShadowRoot.querySelectorAll('[tabindex="-1"]')
] as (HTMLElement | SVGElement)[];
- focusableElements = focusableElements.filter(
- el => isPageRectVisible(getBoundingPageRect(el), this._iframeWindow, 0)
- );
+ focusableElements = focusableElements.filter((el) => {
+ let style = getComputedStyle(el);
+ return style.visibility === 'visible'
+ && style.display !== 'none'
+ && isPageRectVisible(getBoundingPageRect(el), this._iframeWindow, 0);
+ });
focusableElements.sort((a, b) => {
let rangeA;
if (a.getRootNode() === this._annotationShadowRoot && a.hasAttribute('data-annotation-id')) { |
Oh, funny, they're using a checkbox to toggle the menu using CSS. I've seen that in a few other places. The interactivity works without JavaScript, so it's still active in the reader. I'm inclined not to support it, because I think supporting in-page interactions is confusing and goes against the spirit of having a consistent, unchanging snapshot of a page, but that's outside the scope of this PR. |
Exclude links that are hidden via visibility or display css properties and are not focusable while fetching focusable elements. Fixes: zotero/zotero#5069
8f43d75
to
21513c7
Compare
Gotcha! That makes sense. I re-pushed just filtering out of unfocusable nodes with a brief comment |
(Updated the commit message because this can affect EPUBs too.) |
If some links are not currently visible (e.g. hidden in a collapsed menu), the focus won't land on them on Tab keypress. Then, moving focus into the content, or past it into context pane, is not possible. Here, we'll keep trying to shift focus forward or backward until the focus lands.
Fixes: zotero/zotero#5069
For reference, this is the new focus behavior in snapshot that currently gets stuck:
Screen.Recording.2025-02-27.at.5.31.52.PM.mov