question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a way to add portaled (outer) nodes inside FocusScope

See original GitHub issue

🙋 Feature Request

Provide a way to pass into FocusScope nodes, which should consider as a part of it — even they are mounted outside of FocusScope node tree (e.g. portaled).

🤔 Expected Behavior

Let say we have portaled tooltips with some links, and these tooltips are inside FormDialog. And we need to have them in its FocusScope in order to be available for tabbing. Something like that: <FocusScope shards={tooltipRefs}><FormDialog /></FocusScope>

😯 Current Behavior

Any ideas?

💁 Possible Solution

See https://github.com/theKashey/react-focus-lock/blob/master/src/Lock.js#L199

🔦 Context

FocusScope inner component has portaled nodes with buttons, links, inputs.

💻 Examples

<FocusScope shards={tooltipRefs}>
  <Input1 /> // inside focus scope
  <Input2 /> // inside focus scope
  <Portal>
    <Input3 />  // outside, but we must have it inside focus scope
  </Portal>
</FocusScope>

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
LFDanLucommented, Sep 6, 2022

@tounsoo A parent FocusScope currently considers a child scope as part of its contain which is why you can click into the input inside the tooltip here and not have the parent scope (aka the Modal) try to restore focus back to one of its immediate children. However, as you mentioned the only problem currently is that we don’t handle tabbing from a parent scope into a portaled child due to our usage of a TreeWalker to determine the next/previous focusable element when hitting Tab. Now that we’ve refactored FocusScope so it tracks scopes via a tree, we could potentially walk down the tree into a child scope when we detect that we are tabbing from that child’s root scope element? I can bring this up with the team to see what they think.

1reaction
LFDanLucommented, Sep 6, 2022

@yakunins This use case should already be supported by our React Spectrum components, albeit the child Popovers also have their own FocusScope: https://codesandbox.io/s/react-spectrum-template-forked-vnmzwm?file=/src/App.js. FocusScope should allow focus to move inside a child scope from a parent scope and should work even when that child scope is portaled.

Here is a slightly modified version of your sandbox, note you can tab to the button that triggers the tooltip, open it with Enter, that focus lands on the tooltip when it opens, and that you can then tab out of the tooltip and land back on the trigger. Note that ideally the tooltip would automatically close when focus leaves it and that tabbing forward from a parent scope into a portaled child FocusScope is not supported.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kanzi Engine: kanzi::FocusManager Class Reference
Focus scopes, or scopes, are nodes which assist in focus chain navigation handling. They act like a focus proxy, forwarding the active focus...
Read more >
FocusScope – React Aria - React Spectrum Libraries
A FocusScope manages focus for its descendants. It supports containing focus inside the scope, restoring focus to the previously focused element on unmount,...
Read more >
FocusScope and "focus" property of child elements inside a ...
The focus property tells which item is going to take the focus when the FocusScope will gain the activeFocus , to you shouldn't...
Read more >
useOverlayTrigger – React Aria - NET
There is no built in way to create popovers or other types of overlays in HTML. ... which builds on useOverlayTrigger and provides...
Read more >
Synthesizing Qualitative Evidence
Evidence gained from qualitative research is invaluable in understanding how individuals and communities per- ceive health, manage their own health and make ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found