You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe your issue
I'm using the Popover component and the Popover.Panel is portalled to a different DOM node.
I expect that when the keyboard focus moves out of the Popover.Panel, it is placed back on the Popover.Panel. Instead, it is being placed on the sibling element of the Popover.Panel in the portalled location.
The linked codepen shows the same popover component in two different DOM structure. And shows a small reproduction recipe. Case (1) shows exactly my error case. Case (2) shows a different DOM structure, where the focus is handled to my expectation.
Potential cause
The focus-sentinels are only rendered when isPortalled is true (see popover.tsx#L753).
In my case, isPortalled is false. Therefore, the focus-sentinels are not rendered and there is no special focus handling.
The reason is, that the isPortalled check only returns true if button and panel are descendants of different 'root' elements.
for (let root of document.querySelectorAll('body > *')) {
if (Number(root?.contains(button)) ^ Number(root?.contains(panel))) {
return true
}
}
I believe this check is flawed. In my case, button and panel are part of the same 'root' element, but within that in very different locations.
I believe a better condition for isPortalled might be to check if Button and Panel are direct siblings. That way, the focus-sentinels would render whenever the native browser focus management would not suffice.
The text was updated successfully, but these errors were encountered:
What package within Headless UI are you using?
@headlessui/react
What version of that package are you using?
v1.6.6
What browser are you using?
Tested in Firefox and Chromium
Reproduction URL
https://codepen.io/simondl/pen/ZEoWQBq?editors=1010
Describe your issue
I'm using the
Popover
component and thePopover.Panel
is portalled to a different DOM node.I expect that when the keyboard focus moves out of the
Popover.Panel
, it is placed back on thePopover.Panel
. Instead, it is being placed on the sibling element of thePopover.Panel
in the portalled location.The linked codepen shows the same popover component in two different DOM structure. And shows a small reproduction recipe. Case (1) shows exactly my error case. Case (2) shows a different DOM structure, where the focus is handled to my expectation.
Potential cause
The focus-sentinels are only rendered when
isPortalled
is true (seepopover.tsx
#L753).In my case,
isPortalled
isfalse
. Therefore, the focus-sentinels are not rendered and there is no special focus handling.The reason is, that the
isPortalled
check only returns true ifbutton
andpanel
are descendants of different 'root' elements.taken from
popover.tsx
#L219I believe this check is flawed. In my case,
button
andpanel
are part of the same 'root' element, but within that in very different locations.I believe a better condition for
isPortalled
might be to check ifButton
andPanel
are direct siblings. That way, the focus-sentinels would render whenever the native browser focus management would not suffice.The text was updated successfully, but these errors were encountered: