33

I have this TextField in Material UI:

<TextField
      id="contact phone number"
      label="Contact phone number"
      type="number"
      value={this.state.contactPhoneNumber}
      onChange={this.handleChange('contactPhoneNumber')}
      placeholder="Contact phone number"
      margin="normal"
/>

It looks like this: enter image description here

How would I remove the up and down arrow dials from the TextField?

a_hardin
  • 4,991
  • 4
  • 32
  • 40
etayluz
  • 15,920
  • 23
  • 106
  • 151

11 Answers11

41

You can try css approach for that.

input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
  -webkit-appearance: none; 
  margin: 0; 
}
Shubhanu Sharma
  • 1,957
  • 12
  • 30
  • Works For me. If you don't want to affect all input then you can add class to TextField and use like this: .mui-number-field { input::-webkit-inner-spin-button, input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; } } – rahulxyz Nov 27 '21 at 18:48
28

From the TextField docs, the type prop accepts valid HTML input types. I believe the reason the up and down arrows are present is because you specified number as the type.

Try type="tel" instead, as it seems to be the standard input type for phone numbers.

Here is a reference to the tel type and why it's a good idea to use it. Note that if the current browser doesn't support it, it will fall back to being a regular text field.

Allen G
  • 438
  • 4
  • 6
  • If you can share a way to format the number like a telephone number I'll blow you more points – etayluz Jun 12 '18 at 20:00
  • 3
    This solution worked for me, one thing I am wondering is how I can get back the number data type validation I had with type="number"? – Trevor Njeru Aug 23 '20 at 01:05
  • 2
    I've downvoted because whilst this is a quick fix, it removes all validation that the contents be a valid float or integer, meaning you have more work to do in your form validation. The removal of the arrows via css (other answers) would retain the numeric constraint whilst still fixing the problem. – thclark Jan 05 '22 at 09:40
21

In React v 17.0.2 and Material-UI v 4.11.4, this works for me:

import { makeStyles } from '@material-ui/core/styles';
import TextField from '@material-ui/core/TextField';

const useStyles = makeStyles({
  input: {
    '& input[type=number]': {
        '-moz-appearance': 'textfield'
    },
    '& input[type=number]::-webkit-outer-spin-button': {
        '-webkit-appearance': 'none',
        margin: 0
    },
    '& input[type=number]::-webkit-inner-spin-button': {
        '-webkit-appearance': 'none',
        margin: 0
    }
  },
});

export default function MyComponent() {
  const classes = useStyles();
  return <TextField className={classes.input} />;
}
Ali Askari
  • 341
  • 3
  • 7
18

For Material UI version 5

const Input = styled(MuiInput)(({ theme }) => ({
  "& input::-webkit-outer-spin-button, & input::-webkit-inner-spin-button": {
    display: "none",
  },
  "& input[type=number]": {
    MozAppearance: "textfield",
  },
}));

And then use it as

<Input 
      id="contact phone number"
      label="Contact phone number"
      type="number"
      value={this.state.contactPhoneNumber}
      onChange={this.handleChange('contactPhoneNumber')}
      placeholder="Contact phone number"
      margin="normal"
/>
Rohan Sharma
  • 1,416
  • 2
  • 14
  • 19
15

This works for me (css help: https://www.w3schools.com/howto/howto_css_hide_arrow_number.asp)

input: {
    background: theme.palette.secondary.main,
    border: `1px solid white`,
    flex: 1,
    padding: '8px',
    '&[type=number]': {
      '-moz-appearance': 'textfield',
    },
    '&::-webkit-outer-spin-button': {
      '-webkit-appearance': 'none',
      margin: 0,
    },
    '&::-webkit-inner-spin-button': {
      '-webkit-appearance': 'none',
      margin: 0,
    },
  },
Jain
  • 1,209
  • 10
  • 16
5

Material-Ui v5 beta

    MuiInput: {
      styleOverrides: {
        root: {
          '& input::-webkit-outer-spin-button, & input::-webkit-inner-spin-button':
            {
              display: 'none',
            },
          '& input[type=number]': {
            MozAppearance: 'textfield',
          },
        },
      },
    },
4

The question is old but maybe this answer may help those who are still seeking a valid answer.

If you use an outlined textfield you can create a class like,

textfieldClass: {
'& .MuiOutlinedInput-input': {
  '&::-webkit-outer-spin-button, &::-webkit-inner-spin-button': {
    '-webkit-appearance': 'none',
},
}

},

If you use underlined textfield;

textfieldClass: {
 '& .MuiInput-input': {
  '&::-webkit-outer-spin-button, &::-webkit-inner-spin-button': {
    '-webkit-appearance': 'none',
  },
 }
}, 

then you can use it in TextField like:

<TextField
  className={classes.textfieldClass}
  id="contact phone number"
  label="Contact phone number"
  type="number"
  value={this.state.contactPhoneNumber}
  onChange={this.handleChange('contactPhoneNumber')}
  placeholder="Contact phone number"
  margin="normal"

/>

EmrahYT
  • 71
  • 5
1

In my case, if I set it as type=tel then, I will be able to type letters also inside the field which I do not want it. Instead, I did the below one and it worked for me

 const StyledInput= styled(OutlinedInput)`
  input[type='number']::-webkit-inner-spin-button,
  input[type='number']::-webkit-outer-spin-button {
    display: none;
  }`;

 <StyledInput
                type="number"
                inputProps={{ min: 0 }}
                onChange={event => {
                   ...
                }}
 />

chety
  • 136
  • 4
0

Just change the type="number" to type="tel"

Sahil Rajpal
  • 510
  • 4
  • 8
0

To add to the existing answers, here is a way of removing the up/down arrow icons using the sx prop (MUI 5):

<TextField
 sx={{
 "& input::-webkit-outer-spin-button, & input::-webkit-inner-spin-button": {
                          display: "none",
                        },
"& input[type=number]": {
                          MozAppearance: "textfield",
                        },
}}
type="number"
/>

Narcis
  • 33
  • 3
-1

Change TextField attribute type from number to tel

For Example:

<TextField label="Phone No" type="number" required />

To

<TextField label="Phone No" type="tel" required />
Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
Aman
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Nikolai Kiselev Jun 12 '22 at 09:05