Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

fixes plotly/dash-core_components#169 #277

Closed
wants to merge 13 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions src/components/Input.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,29 @@ export default class Input extends Component {
setProps,
type
} = this.props;
const {value} = this.state;
//const {value} = this.state;
Copy link
Contributor

Choose a reason for hiding this comment

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

If you comment this out, it will mean that a Dash user cannot provide the value prop to the dcc.Input component (or rather, it will not do anything). You can see in the constructor of the class that this.state.value is set to props.value, and below in <input />, it gets set to the value attribute: <input value={value} />.

return (
<input
onChange={e => {
this.setState({value: e.target.value});
if (setProps) {
if (type === 'number') {
setProps({value: Number(e.target.value)});
}
else {
setProps({value: e.target.value});
onBlur={
event => {
this.setState({value: event.target.value});
if (setProps) {
if (type === 'number') {
setProps({value: Number(event.target.value)});
}
else {
setProps({value: event.target.value});
}
}
if (fireEvent) fireEvent({event: 'blur'});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain a bit about what this code is supposed to do? Is it really necessary?

Copy link
Author

Choose a reason for hiding this comment

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

This rejects the onKeyPress event and the onChange event is therefore not triggered. This is used to make sure the user can only press on 0-9, dot and comma and that the user cannot input Something like 0.122.,233,44.4, it prevents the use of another dot or comma when either one of them is already present

}
onChange={
() => {
if (fireEvent) fireEvent({event: 'change'});
}
if (fireEvent) fireEvent({event: 'change'});
}}
onBlur={() => {
if (fireEvent) fireEvent({event: 'blur'});
}}
value={value}
}
//value={value}
Copy link
Contributor

Choose a reason for hiding this comment

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

The reason that this doesn't work without removing the value={value}, is probably because onBlur only fires the update, well, on blur, as opposed to onChange which fires every change. Setting value here will overwrite anything you put in the input (try having just <input value={value} /> in there, and you'll see what I mean - it is as if it's 'locked' to whatever is put in as the value prop) so onBlurwill fire it's update on blur, but because the input is 'locked', it fires the update with the same value. Does that make sense?

Copy link
Author

Choose a reason for hiding this comment

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

Yes it make sense, maybe it could work with another variable, i.e. typed for example. I will try

Copy link
Author

Choose a reason for hiding this comment

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

I Added a prop typed to the state (Is it the proper way to say this?), this gets updated by onChange , the valueprop takes the value of thetypeprop whenonBlur``gets fired, so now it works (at least on windows 10)

{...omit(['fireEvent', 'setProps', 'value'], this.props)}
/>
);
Expand Down Expand Up @@ -244,6 +248,11 @@ Input.propTypes = {
*/
step: PropTypes.string,

/**
* Sets the number of important digits. It can be the string any or a positive floating point number. If this attribute is not set to any, the default is zero.
*/
precision: PropTypes.string,

/**
* Dash-assigned callback that gets fired when the input changes.
*/
Expand Down