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
{{ message }}
Repository navigation
[context menu] FocusGuard creates <span> elements in table body if used on table rows #3166
component: context menuChanges related to the context menu component.has workaroundThere’s a bug, but users have a complete workaround, so no urgent fix or release is needed.
When a ContextMenu is triggered it created <span> elements in the container where it was defined. This creates an issue when used inside Tables since they are not allowed to be inside the table structure.
Expected behavior
Being able to use the ContextMenu inside tables and table rows
The benefit of this approach is you're not violating the table row role or breaking assistive technologies by making the <tr> itself interactive.
Edit: I'm noticing that it does still render spans inside the <tbody> while the menu is open, which appears not to break the table layout, but does temporarily make the table markup invalid. I wonder though if that is acceptable because the focus will be locked into the popup, and by the time the focus there is removed, the table will be returned to its valid state? I'm curious too why those spans are rendered as children of the root and not in the portal
Well I guess if you're using next, and next relies on valid html, then you care about valid html 😄
You could possibly rework my workaround to wrap the whole <table> with the context menu, and use the click target or its ancestor to get up to the row you need with some data-rowid attribute, and populate the menu with what you need that way.
Although I'm still wondering why the focus guard spans render as children of the provider and not into the portal. I suspect it's a requirement for how returning focus works or something. (I haven't investigated yet.)
Here is a new example that places the context menu outside of the table, so we don't render any invalid html elements inside the table. We read the rowid data- attribute off the event target.
Hopefully this use-case can be looked at. Linear style UIs where you want to render a context menu wrapping a <tr> element are pretty common these days.
We can change Context Menu specifically to fully trap focus inside modally, without letting you tab out of the context menu (which is the reason the visually-hidden invisible elements get rendered, to preserve the tabbing order).
changed the title [-][ContextMenu] FocusGuard creates <span> elements in table body if used on table rows[/-][+][context menu] FocusGuard creates <span> elements in table body if used on table rows[/+]on May 10, 2026
component: context menuChanges related to the context menu component.has workaroundThere’s a bug, but users have a complete workaround, so no urgent fix or release is needed.
Activity
eckmLJE commentedon Nov 7, 2025
Here is my (rushed) implementation of the hacky approach to this.
<td>, wraps the cell content with a zero padding trigger container -- altogether this results in a continuous click area in the whole rowhttps://codesandbox.io/p/sandbox/morning-lake-m6s24z
The benefit of this approach is you're not violating the table row role or breaking assistive technologies by making the
<tr>itself interactive.Edit: I'm noticing that it does still render spans inside the
<tbody>while the menu is open, which appears not to break the table layout, but does temporarily make the table markup invalid. I wonder though if that is acceptable because the focus will be locked into the popup, and by the time the focus there is removed, the table will be returned to its valid state? I'm curious too why those spans are rendered as children of the root and not in the portalFrom the discord thread, here is some reading on the issue:
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/row_role
https://adrianroselli.com/2023/11/dont-turn-a-table-into-an-aria-grid-just-for-a-clickable-row.html
mj12albert commentedon Nov 7, 2025
Thanks for the sandbox ~ for the focus guard spans, they are also transient in OPs sandbox, I wonder if it has any impact on actual usage
Though even if you don't care about invalid HTML, Next.js will throw:
eckmLJE commentedon Nov 7, 2025
Well I guess if you're using next, and next relies on valid html, then you care about valid html 😄
You could possibly rework my workaround to wrap the whole
<table>with the context menu, and use the click target or its ancestor to get up to the row you need with somedata-rowidattribute, and populate the menu with what you need that way.Although I'm still wondering why the focus guard spans render as children of the provider and not into the portal. I suspect it's a requirement for how returning focus works or something. (I haven't investigated yet.)
eckmLJE commentedon Nov 11, 2025
Here is a new example that places the context menu outside of the table, so we don't render any invalid html elements inside the table. We read the rowid data- attribute off the event target.
https://codesandbox.io/p/sandbox/morning-lake-m6s24z
andresmarpz commentedon Dec 26, 2025
Hopefully this use-case can be looked at. Linear style UIs where you want to render a context menu wrapping a
<tr>element are pretty common these days.atomiks commentedon Dec 27, 2025
We can change Context Menu specifically to fully trap focus inside modally, without letting you tab out of the context menu (which is the reason the visually-hidden invisible elements get rendered, to preserve the tabbing order).
github-actions commentedon Dec 30, 2025
This fix will be available in the next npm release of Base UI.
In the meantime, you can try it out on our Canary release channel:
[-][ContextMenu] FocusGuard creates <span> elements in table body if used on table rows[/-][+][context menu] FocusGuard creates <span> elements in table body if used on table rows[/+]