[TrapFocus] Can't focus input attached under shadow-DOM
See original GitHub issueWhenever I click on a TextField to start editing it, thus the focus will be lost immediately.
- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
Expected Behavior 🤔
On clicking, the Textfield can get focus normally.
Steps to Reproduce 🕹
Example: https://codesandbox.io/s/material-demo-forked-bi51w?file=/index.tsx
Steps:
- Click the TextField at the bottom
Context 🔦
class RTWebComponent extends HTMLElement {
connectedCallback() {
const shadowRoot = this.attachShadow({ mode: "open" });
const mountPoint = document.createElement("div");
mountPoint.id = "ResourceTimeline";
const reactRoot = shadowRoot.appendChild(mountPoint);
const jss = create({
...jssPreset(),
insertionPoint: reactRoot
});
ReactDOM.render(
<div>
<StylesProvider jss={jss}>
<TemporaryDrawerLoseFocus />
</StylesProvider>
{/* <TemporaryDrawerWithoutStlyle /> */}
</div>,
mountPoint
);
}
}
customElements.define("resource-timeline", RTWebComponent);
export default class TemporaryDrawer extends React.Component {
render() {
return (
<div>
{/* <ThemeProvider theme={this.getTheme()}> */}
<Drawer anchor={"top"} open={true}>
<TextField
id="111111"
label="Flight Number"
variant="outlined"
margin="dense"
fullWidth
defaultValue={"1231"}
/>
</Drawer>
{/* </ThemeProvider> */}
</div>
);
}
}
Your Environment 🌎
`npx @material-ui/envinfo`
System:
OS: Windows 10 10.0.19041
Binaries:
Node: 12.18.3 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.5 - C:\opt\Yarn\bin\yarn.CMD
npm: 6.14.6 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 87.0.4280.88
Edge: Spartan (44.19041.423.0), Chromium (87.0.664.60)
npmPackages:
@material-ui/core: 4.11.2 => 4.11.2
@material-ui/icons: 4.11.2 => 4.11.2
@material-ui/styles: 4.11.2
@material-ui/system: 4.11.2
@material-ui/types: 5.1.0
@material-ui/utils: 4.11.2
@types/react: 17.0.0 => 17.0.0
react: 17.0.1 => 17.0.1
react-dom: 17.0.1 => 17.0.1
typescript: 4.1.3 => 4.1.3
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
[TrapFocus] Can't focus input attached under shadow-DOM
Whenever I click on a TextField to start editing it, thus the focus will be lost immediately. The issue is present in the...
Read more >shadowElement.focus() — impossible? - Stack Overflow
I've found that it seems impossible to focus on any element in the shadow dom. we have shadow options like delegatesFocus , and...
Read more >Managing focus in the shadow DOM | Read the Tea Leaves
So the first challenge is to emulate whatever the browser normally does when you press Tab or Shift + Tab . In this...
Read more >focus-trap demo - GitHub Pages
Here is a focus trap in an open Shadow DOM with some focusable parts. deactivate trap. View demo source >>. with shadow dom....
Read more >Accessibility - Angular Material
The cdkTrapFocus directive traps Tab key focus within an element. This is intended to be used to create accessible experience for components like...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@natezhengbne When passing the
Drawer
the modal propModalProps={{disableEnforceFocus: true}}
it seems to work.You can do that globally via the
theme
as wellWe have fixed this issue along the way in v5. I believe we fixed it when we changed the logic of the TrapFocus to only restore the focus when escaping and landing on the body. Proof: https://codesandbox.io/s/material-demo-forked-6ln7y?file=/TemporaryDrawerLoseFocus.tsx.