Skip to content
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

autoFocus not working when Textfield is mounted by clicking on the MenuItem within Menu #35996

Open
2 tasks done
vimutti77 opened this issue Jan 30, 2023 · 2 comments
Open
2 tasks done
Assignees
Labels
component: text field This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material

Comments

@vimutti77
Copy link
Contributor

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example:

Steps:

  1. Go to https://codesandbox.io/s/magical-fog-y0e1m1?file=/demo.tsx
  2. Click on the Toggle Button
  3. The autoFocus is working as expected.
  4. Click on the Toggle Button again to hide the Textfield
  5. Click on Open Menu Button
  6. Click on the Toggle within the Menu
  7. The autoFocus is not working

Current behavior 😯

It is not autoFocus the Textfield.

Expected behavior 🤔

It is autoFocus the Textfield.

Context 🔦

I have a form that will open after clicking on the option in the Menu. I want it to autoFocus the Textfield when the form is open.

Your environment 🌎

npx @mui/envinfo
 I am using Edge.
  System:
    OS: Windows 10 10.0.22621
  Binaries:
    Node: 18.12.1 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: Not Found
    Edge: Spartan (44.22621.1194.0), Chromium (109.0.1518.70)
  npmPackages:
    @emotion/react: ^11.10.5 => 11.10.5
    @emotion/styled: ^11.10.5 => 11.10.5
    @mui/base: 5.0.0-alpha.113 => 5.0.0-alpha.113
    @mui/core-downloads-tracker:  5.11.4
    @mui/icons-material: ^5.11.0 => 5.11.0
    @mui/material: ^5.11.4 => 5.11.4
    @mui/private-theming:  5.11.2
    @mui/styled-engine:  5.11.0
    @mui/system: ^5.11.4 => 5.11.4
    @mui/types:  7.2.3
    @mui/utils:  5.11.2
    @mui/x-data-grid:  5.17.19
    @mui/x-data-grid-premium: ^5.17.19 => 5.17.19
    @mui/x-data-grid-pro:  5.17.19
    @mui/x-date-pickers:  5.0.14
    @mui/x-date-pickers-pro: 5.0.14 => 5.0.14
    @mui/x-license-pro:  5.17.12
    @types/react: ^18.0.26 => 18.0.26
    react: ^18.2.0 => 18.2.0
    react-dom: ^18.2.0 => 18.2.0
    typescript: ^4.9.4 => 4.9.4
@vimutti77 vimutti77 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 30, 2023
@mj12albert mj12albert added the component: text field This is the name of the generic UI component, not the React module! label Jan 30, 2023
@mj12albert
Copy link
Member

Thanks for reporting this!

In the mean time, you can kind of workaround it using a ref like this (codesandbox) – the TextField will focus when the menu is closed

@mj12albert mj12albert added package: material-ui Specific to @mui/material and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 30, 2023
@esinarta
Copy link

If anyone else is still having issues, the solution referenced here worked for me: #4387 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material
Projects
None yet
Development

No branches or pull requests

4 participants