React Material ui input field to custom

Viewed 44
2 Answers

The below code should work the way you want it.

function theFunction(e) {
  if (e.value <= 0) return e.value = 0
  if (e.value[0] == 0) return e.value = e.value.substring(1)
}
body{
      width: 100vw;
      height: 100vh;
}

.custom-input {
      border-top-right-radius: 4px;
      border-bottom-right-radius: 4px;
      background-color: rgb(42, 46, 66);
      color: rgb(249, 249, 251);
      padding: 18px;
      font-size: 48px;
      height: 84px;
      margin-bottom: 18px;
      border-color: rgb(171, 175, 177);
}
<body>
      <input type="number" class="custom-input" id="custom-input" oninput="theFunction(this)" value="800">
</body>

I think you can use the if condition in your handleChange function, for example :

...
var result = 0;
if(input <= 0 || input == ''){
   result = 0;
} else {
   result = event.target.value;
}

this.setState({
    inputValue: result
})
...

Hope this will help you :)

Related