Hi,
Is there more control on teh input data type for numbers when using spectrum?
E.g. only integers, or limit the number of digits?
Probably the solution is to use regex and react to achieve this. Look at the following code:
import { useState } from "react";
export default function App() {
const [inputValue, setInputValue] = useState("");
const keepInRange = (currentValue, min, max) => {
const value = parseInt(currentValue.replace(/\D/g, ""));
if (isNaN(value)) {
return "";
} else if (value < min) {
return min.toString();
} else if (value > max) {
return max.toString();
} else {
return value.toString();
}
};
const handleChange = (event) => {
setInputValue(keepInRange(event.currentTarget.value, 1, 100));
};
return (
<div className="App">
<input type="text" value={inputValue} onChange={handleChange} />
</div>
);
}
Just keep in mind that the type of that variable is a string so if you want to use as a number you would have to convert it by using parseInt() javascript function.