-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
In shadow DOM, keyboard not working for Select menu #34061
Comments
We haven't been testing the components in such context. It's not a popular use case after all. |
@michaldudak I wouldn't say it's not a popular use case. Being able to use a MUI with a React app that can be wrapped with a web component using shadowDom will give you more potential clients with big finances who want to move from JSF/JSP to ReactJS and who is willing to pay for the pro version. There are currently 2 ways to use a React app with JSF/JSP.
And it would be fit my needs perfectly if MUI provided a clear picture how and when it adds its styles. Hence I'd like to ask you pleas may you give an idea how to do this. PS. I bet this will allow some managers to be more courageous in their decision to migrate their old banking interface to a more modern one that uses React rather than JSP/JSF. Because in this way it would not be necessary to migrate everything at once. |
Any suggestions on a workaround? This is still an issue. @yk-jemmic Did you figure a solution? |
@tristanjasper I had a slightly different case, but yes, it's still relevant with an example in the topic as well as on their Demo (but it works partially) so keyboard navigation does not work correctly |
I've managed to get this to work with a custom <Select
ref={selectRef}
MenuProps={{
PaperProps: {
onKeyDown: ({ key }: React.KeyboardEvent<HTMLDivElement>) => {
const validKeys = ["ArrowUp", "ArrowDown"];
let newIndex = 0;
if (validKeys.includes(key) && selectRef.current) {
const selectedItem =
(selectRef.current.getElementsByClassName("Mui-focusVisible")[0] ||
selectRef.current.getElementsByClassName("Mui-selected")[0]) as HTMLElement;
const menuList = Array.from(
selectRef.current.querySelectorAll("ul[role='listbox'] li") || [],
);
if (selectedItem && selectedItem.parentNode) {
const selectedIndex = menuList.indexOf(selectedItem);
if (key === "ArrowDown") {
newIndex = selectedIndex + 1 < menuList.length ? selectedIndex + 1 : selectedIndex;
} else if (key === "ArrowUp") {
newIndex = selectedIndex - 1 >= 0 ? selectedIndex - 1 : selectedIndex;
}
}
if (menuList.length > newIndex) {
const newSelectedItem = menuList[newIndex] as HTMLElement;
newSelectedItem.focus();
}
}
},
},
}}
> |
Based on preliminary testing, the root cause of the problem is here:
On Applying similar changes seems to fix the problem. |
Duplicates
Latest version
Current behavior 😯
When Select menu (and its popover) is displayed within a shadow DOM, arrow keys have no effect.
Expected behavior 🤔
Arrow keys should select menu items.
(I'm not sure to what extent shadow DOM is supported, but it seems to be mostly working otherwise.)
Steps to reproduce 🕹
Steps:
Context 🔦
Rendering a MUI app entirely within a web component's shadow DOM.
Your environment 🌎
CodeSandbox
The text was updated successfully, but these errors were encountered: