@@ -102,56 +102,62 @@ export default class InputNumeric extends Component {
102102}
103103}
104104
105+ /**
106+ * Decrement the input field's value by one step (this.props.step)
107+ */
105108decrement ( ) {
106- const newValue = this . validate ( this . props . value - this . props . step ) ;
107- if ( this . props . onChange ) {
108- this . props . onChange ( newValue ) ;
109- }
109+ const newValue = this . validate ( this . state . newValue - this . props . step ) ;
110+ this . setState ( {
111+ newValue
112+ } ) ;
113+ }
114+
115+ /**
116+ * Increment the input field's value by one step (this.props.step)
117+ */
118+ increment ( ) {
119+ const newValue = this . validate ( this . state . newValue + this . props . step ) ;
120+ this . setState ( {
121+ newValue
122+ } ) ;
110123}
111124
125+ /**
126+ * Start an interval in which the input field's value is repeatedly decremented
127+ */
112128startDecrement ( ) {
113129this . decrement ( ) ;
114- this . decrementTimeout = setTimeout ( ( ) => {
115- this . decrementInterval = setInterval ( ( ) => {
130+ this . timeout = setTimeout ( ( ) => {
131+ this . interval = setInterval ( ( ) => {
116132this . decrement ( ) ;
117133} , this . mouseDownInterval ) ;
118134} , this . mouseDownDelay ) ;
119135}
120136
121- stopDecrement ( ) {
122- if ( this . decrementTimeout ) {
123- clearTimeout ( this . decrementTimeout ) ;
124- }
125- if ( this . decrementInterval ) {
126- clearInterval ( this . decrementInterval ) ;
127- }
128- if ( this . props . onBlur ) {
129- this . props . onBlur ( this . state . newValue ) ;
130- }
131- }
132-
133- increment ( ) {
134- const newValue = this . validate ( this . props . value + this . props . step ) ;
135- if ( this . props . onChange ) {
136- this . props . onChange ( newValue ) ;
137- }
138- }
139-
137+ /**
138+ * Start an interval in which the input field's value is repeatedly incremented
139+ */
140140startIncrement ( ) {
141141this . increment ( ) ;
142- this . incrementTimeout = setTimeout ( ( ) => {
143- this . incrementInterval = setInterval ( ( ) => {
142+ this . timeout = setTimeout ( ( ) => {
143+ this . interval = setInterval ( ( ) => {
144144this . increment ( ) ;
145145} , this . mouseDownInterval ) ;
146146} , this . mouseDownDelay ) ;
147147}
148148
149- stopIncrement ( ) {
150- if ( this . incrementTimeout ) {
151- clearTimeout ( this . incrementTimeout ) ;
149+ /**
150+ * Stop the decrement/increment interval and execute the onChange() and onBlur() functions
151+ */
152+ stop ( ) {
153+ if ( this . timeout ) {
154+ clearTimeout ( this . timeout ) ;
152155}
153- if ( this . incrementInterval ) {
154- clearInterval ( this . incrementInterval ) ;
156+ if ( this . interval ) {
157+ clearInterval ( this . interval ) ;
158+ }
159+ if ( this . props . onChange ) {
160+ this . props . onChange ( this . state . newValue ) ;
155161}
156162if ( this . props . onBlur ) {
157163this . props . onBlur ( this . state . newValue ) ;
@@ -164,8 +170,8 @@ export default class InputNumeric extends Component {
164170< button
165171type = "button"
166172onMouseDown = { ( ) => this . startDecrement ( ) }
167- onMouseUp = { ( ) => this . stopDecrement ( ) }
168- onMouseLeave = { ( ) => this . stopDecrement ( ) }
173+ onMouseUp = { ( ) => this . stop ( ) }
174+ onMouseLeave = { ( ) => this . stop ( ) }
169175>
170176–
171177</ button >
@@ -179,8 +185,8 @@ export default class InputNumeric extends Component {
179185< button
180186type = "button"
181187onMouseDown = { ( ) => this . startIncrement ( ) }
182- onMouseUp = { ( ) => this . stopIncrement ( ) }
183- onMouseLeave = { ( ) => this . stopIncrement ( ) }
188+ onMouseUp = { ( ) => this . stop ( ) }
189+ onMouseLeave = { ( ) => this . stop ( ) }
184190>
185191+
186192</ button >
0 commit comments