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 missing min, max, step Typescript types #9313

Closed
1 task done
tcrognon opened this issue Nov 27, 2017 · 13 comments
Closed
1 task done

[TextField] type=number missing min, max, step Typescript types #9313

tcrognon opened this issue Nov 27, 2017 · 13 comments
Labels
bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! typescript

Comments

@tcrognon
Copy link

tcrognon commented Nov 27, 2017

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

<TextField type="number" min="0" max="10" step="1" /> should compile with Typescript

Current Behavior

Receive following Typescript error for min, similar for max and step: [ts] Property 'min' does not exist on type 'IntrinsicAttributes & TextFieldProps & { children?: ReactNode; }'.

Your Environment

Tech Version
Material-UI 1.0.0-beta.21
React 16.0.0
Typescript 2.6.1
@pelotom pelotom added typescript bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! labels Nov 27, 2017
@pelotom
Copy link
Member

pelotom commented Nov 27, 2017

Does this work?

<TextField type="number" inputProps={{ min: "0", max: "10", step: "1" }} />

@tcrognon
Copy link
Author

Yes that works. inputProps accepts an object with anything in it, though, so I'm effectively opting out of the type system by doing it this way.

pelotom added a commit to pelotom/material-ui that referenced this issue Nov 28, 2017
@pelotom
Copy link
Member

pelotom commented Nov 28, 2017

Yes that works. inputProps accepts an object with anything in it, though, so I'm effectively opting out of the type system by doing it this way.

Good point, I've opened #9321 to fix the typing of inputProps.

rosskevin pushed a commit that referenced this issue Nov 28, 2017
@rosskevin rosskevin reopened this Nov 29, 2017
@rosskevin
Copy link
Member

inputProps is intended to allow for anything goes on an InputComponent. This allows for open integration with external components, for which unfortunately we may not know or have types.

Example:

import * as MaskedInput from 'react-text-mask'

      <TextField
        InputProps={{
          inputComponent: MaskedInput,
        }}
        inputProps={{
          guide: false,
          mask,
          placeholderChar: '\u2000',
        }}
        type="tel"
        value={value}
      />

@rosskevin
Copy link
Member

rosskevin commented Nov 29, 2017

So the alternative to avoiding strongly typed inputProps in the same scenario (thanks @pelotom) is

import { InputProps as MuiInputProps } from 'material-ui/Input'

      <TextField
        InputProps={{
          inputComponent: (inputProps: MuiInputProps) => (
            <MaskedInput {...inputProps} guide={false} mask={mask} placeholderChar="\u2000" />
          ),
        }}
        type="tel"
        value={value}
      />

@pelotom is filing a new proposal/issue to revisit this API.

@GaddMaster
Copy link

@rosskevin
MaskedInput is not defined,
mask is not defined
:(

@djwashburn
Copy link

This seems like an overly complicated workaround

@CareerFairPlus
Copy link

It would be better to define these at the TextField level, so that validation can be performed without a bunch of repeated logic everywhere. I'd hate to have to extend TextField every time I want to use it for a number field with min/max/step requirements.

@Angelk90
Copy link
Contributor

@pelotom , @oliviertassinari , @rosskevin :

If the numbers are entered as input as shown in the image it is easy to bypass the control.

Is there a solution?

Link: codesandbox

Registrazione schermo 2020-11-20 alle 17 21 03

@oliviertassinari
Copy link
Member

oliviertassinari commented Nov 21, 2020

@Angelk90 Maybe you can control the value prop and apply the limit when the input is blurred (⚠️ only when blurred). At least, the limits fail the validation of the field when into a form.

Related to #19154

@Absleepy
Copy link

Absleepy commented May 2, 2021

this doesn't work when you type something.

@Himanshudabhi34
Copy link

How to write float value in TextField as input in material ui component for multiple input field ??

@Absleepy
Copy link

Absleepy commented Jun 23, 2022

@Himanshudabhi34 Can you Please provide more details? What do you mean by float value in textfield? As it already accept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! typescript
Projects
None yet
Development

No branches or pull requests

10 participants