There is no event fired when clicking on the arrows so here is what I can propose you, see this custom component on Stackblitz.
Here is the full code :
.css :
.custom-input {
display: flex;
}
.custom-input > .arrows {
margin-left: -21px;
}
/*+++++++++ ARROWS +++++++++++++*/
.arrows-component {
display: inline-block;
}
.arrows {
display: flex;
flex-direction: column;
align-items: center;
}
.arrows button {
background-color: transparent;
border: 1px solid transparent;
}
.arrows button:hover {
border: 1px solid rgba(0, 0, 0, .24);
}
.arrows button:focus {
border: 1px solid rgba(0, 0, 0, .24);
}
.arrow-top {
width: 0;
height: 0;
border-style: solid;
border-width: 0 3.5px 7px 3.5px;
border-color: transparent transparent #007bff transparent;
}
.arrow-bottom {
width: 0;
height: 0;
border-style: solid;
border-width: 7px 3.5px 0 3.5px;
border-color: #007bff transparent transparent transparent;
}
.js :
import React, { Component } from "react";
import { render } from "react-dom";
import "./style.css";
const App = () => {
return (
<div>
<CustomInput />
</div>
);
};
const CustomInput = () => {
const [currentValue, setCurrentValue] = React.useState(0);
const handleChanges = e => {
setCurrentValue(event.target.value.replace(/\D/, ""));
};
const topArrowClicked = (e) => {
setCurrentValue(prevState => prevState + 1);
}
const bottomArrowClicked = (e) => {
setCurrentValue(prevState => prevState - 1);
}
return (
<div className="custom-input">
<input
type="text"
value={currentValue}
pattern="[0-9]*"
onChange={e => handleChanges(e)}
/>
<span className="arrows">
<InputArrows topArrowClick={topArrowClicked} bottomArrowClick={bottomArrowClicked} />
</span>
</div>
);
};
const InputArrows = ({topArrowClick, bottomArrowClick}) => {
return (
<div className="arrows-component">
<div className="arrows">
<button onClick={topArrowClick}>
<div className="arrow-top" />
</button>
<button onClick={bottomArrowClick}>
<div className="arrow-bottom" />
</button>
</div>
</div>
);
};
render(<App />, document.getElementById("root"));
Here you have a full access to the method triggered when clicking on the top and bottom arrow, and you can implement whatever functionality you want (as a step or different behavior).