-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/numeric input #17
Conversation
}; | ||
|
||
calcValue(val) { | ||
const { max, min } = this.props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this operation is often called clamp
:
const clamp = (min, max, v) => Math.min(Math.max(v, min), max)
[`${baseClass}__increment--disabled`]: | ||
this.props.max && this.props.value === this.props.max | ||
})} | ||
onClick={this.changeValue(1)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cursor: not-allowed;
doesnt block click events so u can still click on this and have onChange
being fired (it shouldnt be if we are already having the max/min value entered)
<input | ||
type="text" | ||
{...restProps} | ||
value={value !== null ? value : ''} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this component should always be controlled internally or externally - handleChange
should either call onChange
if its controlled externally or setState if its controlled internally (so uncontrolled externally), otherwise for uncontrolled components it will leave garbage types into the field (u purify the event.target.value, but u dont set it)
} | ||
|
||
onFocus = () => { | ||
this.addKeyboardEventListeners(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why those arent handled by the input
component?
return ( | ||
<span className={mergedClassNames} style={this.getComponentStyles()}> | ||
<input | ||
type="text" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use type 'number'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value={value !== null ? value : ''} | ||
disabled={disabled} | ||
onChange={this.handleChange} | ||
onFocus={this.onFocus} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use one convention for naming event handler functions.
}; | ||
|
||
onKeyDown = e => { | ||
if (e.keyCode === KeyCodes.arrowDown) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use field type number, all of this is handled by deafult
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also min/max values are handled by browser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imho browser validation is insufficient in this case
}; | ||
|
||
handleChange = e => { | ||
e.preventDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to prevent default action from firing?
```js | ||
initialState = { value: 1, error: null }; | ||
|
||
onInputChange = (value) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use handleInputChange
line-height: 36px; | ||
height: 100%; | ||
border-radius: 4px; | ||
border: 1px solid #bcc6d0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use var value for colors
No description provided.