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

Input with Label (or TextField) inside Menu: typing the first character of the label blurs the input #36133

Closed
2 tasks done
barbalex opened this issue Feb 10, 2023 · 3 comments
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

@barbalex
Copy link

barbalex commented Feb 10, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example: https://codesandbox.io/s/modest-heyrovsky-6tyisc?file=/src/App.tsx
Second example demonstrating same behaviour with TextField: https://codesandbox.io/s/dreamy-tess-wx86oc?file=/src/App.tsx

Steps:

  1. klick into the input
  2. type the first character of it's label, in this case an "f"
  3. watch the input blur (in our app this even closes the menu)
  4. type a different character instead
  5. watch it being written into the input

Expected behavior 🤔

the input should not blur when typing any character

Your environment 🌎

npx @mui/envinfo
  System:
    OS: Windows 10 10.0.22621
  Binaries:
    Node: 19.4.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 3.2.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 9.2.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 109.0.5414.121
    Edge: Spartan (44.22621.1105.0), Chromium (110.0.1587.41)
  npmPackages:
    @emotion/react: 11.10.5 => 11.10.5 
    @emotion/styled: 11.10.5 => 11.10.5 
    @mui/base:  5.0.0-alpha.117 
    @mui/core-downloads-tracker:  5.11.8 
    @mui/material: 5.11.8 => 5.11.8 
    @mui/private-theming:  5.11.7 
    @mui/styled-engine:  5.11.8 
    @mui/system:  5.11.8 
    @mui/types:  7.2.3 
    @mui/utils:  5.11.7 
    @types/react: 18.0.27 => 18.0.27 
    react: 18.2.0 => 18.2.0 
    react-dom: 18.2.0 => 18.2.0 
    typescript: 4.9.5 => 4.9.5 
@barbalex barbalex added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 10, 2023
@barbalex barbalex changed the title Input with Label inside Menu: typing the first character of the label blurs the input Input with Label (or TextField) inside Menu: typing the first character of the label blurs the input Feb 10, 2023
@siriwatknp siriwatknp added bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material labels Feb 13, 2023
@siriwatknp siriwatknp removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 13, 2023
@siriwatknp
Copy link
Member

siriwatknp commented Feb 13, 2023

It looks like a bug to me but needs more investigation.

@ZeeshanTamboli
Copy link
Member

ZeeshanTamboli commented Feb 16, 2023

I suppose the label, which is a menu item child, is being focused which causes the input to blur. This is the feature of the Menu component. If there is a menu item that starts with that alphabet it will be focused (in this case the label). See demo for an example. You can prevent the keyboard events from bubbling up to the Menu using event.stopPropagation().

Check the following CodeSandboxes:

Similar kind of issues: #19116, #19096.

I believe we can close this issue. I hope it helps.

@ZeeshanTamboli ZeeshanTamboli removed the bug 🐛 Something doesn't work label Feb 16, 2023
@barbalex
Copy link
Author

Yeah, that explains it and also: As it is a feature, this is no bug. Just something to be aware of.
Thanks for great help and this tool.

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