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

Add n_blur/n_submit to Input. #326

Merged
merged 3 commits into from
Oct 22, 2018
Merged

Add n_blur/n_submit to Input. #326

merged 3 commits into from
Oct 22, 2018

Conversation

T4rk1n
Copy link
Contributor

@T4rk1n T4rk1n commented Oct 12, 2018

Add four props to dcc.Input:

  • n_submit, The number of times enter was pressed when the component had focus.
  • n_submit_timestamp The last timestamp enter was pressed.
  • n_blur, The number of times the component lost focus.
  • n_blur_timestamp, The last time the component lost focus.

resolves #230

Copy link
Contributor

@valentijnnieman valentijnnieman left a comment

Choose a reason for hiding this comment

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

Nice 💃 have just one suggestion, up to you if you want to include that in this PR.

@@ -41,6 +41,20 @@ export default class Input extends Component {
if (fireEvent) {
fireEvent({event: 'blur'});
}
if (setProps) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A small improvement here could be that if setProps is set, the component doesn't need to keep state itself, i.e. if setProps is set you don't need to fire setState. If you were to implement that, you'd also need to add that logic to componentWillReceiveProps. We had a small discussion about that in #331 - it won't cause any bugs like that here but it's still a small gain to not keep unnecessary state in this component. Up to you if you want to add that now, we could always add it later if you want to just merge this first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But it's not using the state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I was looking at line 29. That's something for another time then, feel free to merge!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a note about that in our react dev guide ? In the SuggestionsInput, I was using componentWillReceiveProps to setState on the value, but also setState before calling setProps on the value and the value in the props and state was always different so it lead to a bug where no suggestions beyond the first was registered so it a very valid concern to think about when developing dash component.

Copy link
Contributor

Choose a reason for hiding this comment

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

Exactly, like I mentioned above I found a bug with that recently too in #331. In the Input component I don't think it'll lead to any bugs though. But it's not in the React for Python devs guide, no. Would be good to add that!

@T4rk1n T4rk1n merged commit ee56b11 into master Oct 22, 2018
@T4rk1n T4rk1n deleted the input-enter-blur branch October 22, 2018 20:09
@@ -37,7 +37,7 @@ def __init__(self, id=Component.REQUIRED, storage_type=Component.UNDEFINED, data
_locals.update(kwargs) # For wildcard attrs
args = {k: _locals[k] for k in _explicit_args if k != 'children'}

for k in ['id']:
for k in [u'id']:
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You commenting on auto generated code, I didn't do that.

Copy link
Contributor

@Akronix Akronix Oct 31, 2018

Choose a reason for hiding this comment

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

Ah ok. Sorry if it was rude.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trying to add 'returnPressed' event for Input
3 participants