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

Can not type "S" in Menu Textfield #19116

Closed
manojspace opened this issue Jan 7, 2020 · 19 comments
Closed

Can not type "S" in Menu Textfield #19116

manojspace opened this issue Jan 7, 2020 · 19 comments
Labels
component: menu This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists

Comments

@manojspace
Copy link

I was trying to add textfield in menu, and it works fine.
But when I type S as the first keyword, it doesn't take that key as input, instead it just highlights the menu area.

If S is a shortcut key, then how to disable it for that menu instance?

Can someone help here for this problem.

The code snippet is here:
https://codesandbox.io/s/zealous-feather-ehvec

Just try typing start with S key.

@jimmy-james
Copy link

jimmy-james commented Jan 8, 2020

I was trying to add textfield in menu, and it works fine.
But when I type S as the first keyword, it doesn't take that key as input, instead it just highlights the menu area.

If S is a shortcut key, then how to disable it for that menu instance?

Can someone help here for this problem.

The code snippet is here:
https://codesandbox.io/s/zealous-feather-ehvec

Just try typing start with S key.

Typing S does not work specifically when it is the first letter typed on focus. It works after typing another letter first however.

@manojspace
Copy link
Author

Is there any way to overcome this problem?

@manojspace manojspace reopened this Jan 8, 2020
@jimmy-james
Copy link

jimmy-james commented Jan 8, 2020

Is there any way to overcome this problem?

Looks like putting a Textfield component inside of a Menu component causes the problem because, if you notice, the "S" you are typing is found in the Textfield Label attribute. If you change/remove the Label, you'll find that it doesn't catch on "S" anymore.

This seems to be happening because MUI Menu moves the focus based on what it finds in the MenuList. For some reason, it's also targeting the Label, which it shouldn't, IMO.

Do you have to have a Textfield within the Menu?

@jimmy-james
Copy link

jimmy-james commented Jan 8, 2020

Ah, I see. MUI Menu traverses the MenuList items and focuses on every child item. When it focuses on your Textfield child, it sees the text inside of it in the Label ("Standard") and processes it just as if it was an expected MenuList item.

@jimmy-james
Copy link

Seeing if a fix can be merged.
If not, then you'll have to try a different approach. Not sure what your specific use case is.

@mbrookes
Copy link
Member

mbrookes commented Jan 8, 2020

You can prevent keyboard events from bubbling up from the input to the menu.

@mbrookes mbrookes added component: menu This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists labels Jan 8, 2020
@mbrookes
Copy link
Member

mbrookes commented Jan 8, 2020

Duplicate of #19096

@mbrookes mbrookes marked this as a duplicate of #19096 Jan 8, 2020
@mbrookes mbrookes closed this as completed Jan 8, 2020
@manojspace
Copy link
Author

manojspace commented Jan 9, 2020

Is there any way to overcome this problem?

Looks like putting a Textfield component inside of a Menu component causes the problem because, if you notice, the "S" you are typing is found in the Textfield Label attribute. If you change/remove the Label, you'll find that it doesn't catch on "S" anymore.

This seems to be happening because MUI Menu moves the focus based on what it finds in the MenuList. For some reason, it's also targeting the Label, which it shouldn't, IMO.

Do you have to have a Textfield within the Menu?

Sol.1: Removing the label it worked.
Sol.2: Prevent keyboard events as suggested by @mbrookes

onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
     e.stopPropagation();
  }

<TextField onKeyDown={this.onKeyDown} />

Thank you soo much! You saved my day!

@TondeMoon
Copy link

Sol.1: Removing the label it worked. Sol.2: Prevent keyboard events as suggested by @mbrookes

`onKeyDown = (e: KeyboardEvent) => { e.stopPropagation(); }

`

Thank you soo much! You saved my day!

Thank you from 2022 for my saved days!

@nikitahlukhov
Copy link

One more thank you from 2022!

@ShaliniChauhan123
Copy link

thankyou from 2023

@vsvai
Copy link

vsvai commented May 30, 2023

onKeyDown = {(e: KeyboardEvent) => {
e.stopPropagation();
}}
Inside The textField component fixed will fix
this issue after the onChange

@abinicorn
Copy link

abinicorn commented Sep 26, 2023

Thank you from 2023! Saved my day!

@akselipalmer
Copy link

Thank you from 2023! Our team was so confused. Saved us.

@palmerelias
Copy link

I'm not sure why it wasn't obvious to me at first, but 'onKeyDown' is a prop for inputBase.

<InputBase
onKeyDown={(e) => {
e.stopPropagation();
}}
onChange={handleChange}
/>

Thanks for the help from 2023!!

@afaqahmedkhan
Copy link

onKeyDown = {(e: KeyboardEvent) => { e.stopPropagation(); }} Inside The textField component fixed will fix this issue after the onChange

Thanks from 2024

@jtimus
Copy link

jtimus commented Mar 14, 2024

Thanks from March 2024!

@AlessandroGenerale17
Copy link

Thanks from April 2024! 👍🏻

@rutvik-cybercom
Copy link

Thanks from April 2024!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: menu This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests