-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
[tabs] Fix Arrow key navigation failing when component is rendered in shadow DOM #47178
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
Conversation
Netlify deploy previewhttps://deploy-preview-47178--material-ui.netlify.app/ Bundle size report
|
|
|
||
| const list = tabListRef.current; | ||
| const currentFocus = ownerDocument(list).activeElement; | ||
| const currentFocus = getActiveElement(ownerDocument(list)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by adding a getActiveElement utility that recursively traverses shadow roots to find the actual focused
element. The issue was that document.activeElement returns the shadow host instead of the focused element inside
shadow DOM, causing keyboard navigation to fail the role="tab" check.
|
@sai6855 I would mark this as an "enhancement" instead of a "bug". What do you think? We don't claim to support all components inside Shadow DOM. |
| * // Starting from a specific document | ||
| * const activeElement = getActiveElement(ownerDocument(element)); | ||
| */ | ||
| export default function getActiveElement(root: Document | ShadowRoot = document): Element | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could copy this slightly shorter one 😅
https://github.com/mui/base-ui/blob/master/packages/react/src/floating-ui-react/utils/element.ts#L5-L13
mj12albert
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sai6855 There are a few more instances of raw activeElement, might as well correct it in this PR as well: https://github.com/search?q=repo%3Amui%2Fmaterial-ui+activeElement+path%3A%2F%5Epackages%5C%2Fmui-material%5C%2Fsrc%5C%2F%2F&type=code
Got it 👍 , I'll do it in separate PR as there are lot more instances to update, It will be easier to revert change if something goes wrong whilst keeping this PR changes |
closes #47166
Before
https://codesandbox.io/p/sandbox/shadow-dom-test-tabs-component-78x4c8
After
https://stackblitz.com/edit/evlhh47d-8xzn9hbn