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

Textfield type="number" allowing non-numeric values in firefox #18923

Closed
BjoernRave opened this issue Dec 19, 2019 · 4 comments
Closed

Textfield type="number" allowing non-numeric values in firefox #18923

BjoernRave opened this issue Dec 19, 2019 · 4 comments
Labels
component: text field This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists

Comments

@BjoernRave
Copy link

Current Behavior 😯

When creating a number field like the following: <Textfield type="number" /> on firefox it allows non-numeric values. It works fine in chrome.

Expected Behavior 🤔

When creating a number field like the following: <Textfield type="number" /> it should only allow numeric values.

Steps to Reproduce 🕹

Steps:

  1. Create a Textfield with type="number"
  2. Open the app in firefox
  3. Try to type a

Your Environment 🌎

Tech Version
Material-UI v4.8.0
React v 16.12
Browser Firefox v71
TypeScript 3.7.2
etc.
@mmarkelov
Copy link

@BjoernRave This is not Material bug. There seems to be some disagreement about this among browsers
Link 1
Link 2
Link 3

@mmarkelov
Copy link

@BjoernRave as a workaround you can do this:

React.useEffect(() => {
    document
      .querySelector("input[type='number']")
      .addEventListener("keypress", evt => {
        if (evt.which === 8) {
          return;
        }
        if (evt.which < 48 || evt.which > 57) {
          evt.preventDefault();
        }
      });
  }, []);

@BjoernRave
Copy link
Author

BjoernRave commented Dec 19, 2019

@mmarkelov okay, didn't know that and also thanks for the workaround, I was almost going crazy :D

@oliviertassinari oliviertassinari added component: text field This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists labels May 11, 2020
@oliviertassinari
Copy link
Member

Duplicate of #10582

@oliviertassinari oliviertassinari marked this as a duplicate of #10582 May 11, 2020
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! duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants