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

Number TextField breaks when inputting letters #24312

Closed
2 tasks done
gubareve opened this issue Jan 8, 2021 · 2 comments
Closed
2 tasks done

Number TextField breaks when inputting letters #24312

gubareve opened this issue Jan 8, 2021 · 2 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

@gubareve
Copy link

gubareve commented Jan 8, 2021

  • 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 😯

Inputting a letter makes the text on the top drop down onto the current text:

GYzsTADdrJ.mp4

Expected Behavior 🤔

Either:

  1. The text wont drop down and the letters will be caught by form validation
  2. Letters can't be entered

Steps to Reproduce 🕹

https://codesandbox.io/s/material-ui-issue-forked-3o9f6

Steps:

  1. Create a textfield like this: <TextField id="outlined-number" type="number" variant="outlined" margin="normal" required fullWidth label="Testing" name="Testing" value={value} onChange={(e) => setValue(e.target.value)} autoFocus />

Context 🔦

I'm trying to make a form element that only accepts numbers. (html built-in form validation is fine)

Your Environment 🌎

C:\Users\Evan>npx @material-ui/envinfo
npx: installed 2 in 1.648s

  System:
    OS: Windows 10 10.0.19042
  Binaries:
    Node: 12.18.3 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.6 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: Not Found
    Edge: Spartan (44.19041.423.0), Chromium (87.0.664.66)

I use firefox!
@gubareve gubareve added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 8, 2021
@oliviertassinari oliviertassinari added duplicate This issue or pull request already exists component: text field This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 8, 2021
@oliviertassinari
Copy link
Member

@gubareve This is expected, Firefox fires a change event with an empty string when the content of the field is wrong. See https://next.material-ui.com/components/text-fields/#shrink for the documented solution.

@bartekbp
Copy link

@oliviertassinari This scenario seems quite common, so I would expect it to work better. Do you think it's possible to use HTMLInputElement.validity.badInput object to decide to shrink a field when it contains an invalid number? Maybe that would help.

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