-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
option to keep button in error state #91
base: master
Are you sure you want to change the base?
Conversation
README.md
Outdated
@@ -157,7 +157,7 @@ Put the button in the normal state. | |||
|
|||
Put the button in the success state. Call the callback or the onSuccess prop when going back to the normal state. | |||
|
|||
##### error([callback]) | |||
##### error([callback, dontGoBackToNormal]) |
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.
I think I'd rather have a prop to control that. Something like props.stayInErrorState
which would default to false
.
Otherwise you need to handle it as an optional argument (eg. right now it would break when calling l.141)
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.
Yes true I actually made a change afterwards to avoid the error when calling handlePromise
but forgot to push them (this.error(null, false, err)
) but a default value for dontGoBackToNormal optional argument is a much better option).
I think I'd rather have a prop to control that. Something like
props.stayInErrorState
which would default to false.
I chose to use to use dontGoBackToNormal
optional argument when calling error()
for consistency because this is what is done for success()
, but I agree this should also be available as a prop for the situation when button is not controlled via methods.
Will add commits to this PR for those 2 things.
Add documentation for undocumented `controlled` prop
2a91bd5
to
e195abc
Compare
e195abc
to
82451b2
Compare
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.
sorry for the delay, for some reason I didn't get a notification
this.setState({currentState: STATE.SUCCESS}) | ||
this._timeout = setTimeout(() => { | ||
if (!dontRemove) { this.setState({currentState: STATE.NOTHING}) } | ||
if (!stayInSuccessState || !this.props.stayInSuccessState) { this.setState({currentState: STATE.NOTHING}) } |
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.
I think you don't need the default argument and then the check becomes:
if (typeof stayInSuccessState !== 'undefined' ? !stayInSuccessState : !this.props.stayInSuccessState) {
...
}
otherwise the argument won't ever be used if the prop is true
this.setState({currentState: STATE.ERROR}) | ||
this._timeout = setTimeout(() => { | ||
this.setState({currentState: STATE.NOTHING}) | ||
if (!stayInErrorState || !this.props.stayInErrorState) { this.setState({currentState: STATE.NOTHING}) } |
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.
same here
This allows to force the button in error state (does no go back to NOTHING state after timeout
durationError
).Can be useful in case the error is not recoverable (no need to re-click the button).