Skip to content
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

Merged
merged 13 commits into from
Nov 23, 2018
Merged

Feature/numeric input #17

merged 13 commits into from
Nov 23, 2018

Conversation

kamilmateusiak
Copy link
Contributor

No description provided.

};

calcValue(val) {
const { max, min } = this.props;
Copy link
Member

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)}
Copy link
Member

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 : ''}
Copy link
Member

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();
Copy link
Member

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"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use type 'number'

Copy link
Contributor Author

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}
Copy link

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) {
Copy link

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

Copy link

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

Copy link
Contributor Author

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();
Copy link

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) => {
Copy link

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;
Copy link

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

@kamilmateusiak kamilmateusiak merged commit bb60487 into master Nov 23, 2018
@quarties quarties deleted the feature/numeric-input branch May 28, 2019 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants