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
[Pickers] Fix showTodayButton
not returning the current time
#24650
Conversation
There must be some React magic i don't completly understand, but wrapping the "now" in a React.useRef have the effect of now updating the value in the components
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.
It's not clear to me whether we want these semantics everywhere.
As a first step, please add a test so that we can check if it makes sense to create two different implementations.
useNow
might be used as default value of sorts and that shouldn't change over time. That might be implied by how it's used though.
showTodayButton
not returning the current time
issue solved and test case added
|
||
expect(onCloseMock.callCount).to.equal(1); | ||
expect(handleChange.callCount).to.equal(1); | ||
expect(adapterToUse.getDiff(handleChange.args[0][0], start)).to.equal(10); |
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.
😍
@anthonyraymond Thanks for raising the issue to our attention, it's half of the job done. Sebastian was definitely right about the useNow semantic for default values, we needed to keep a ref. |
Problem
When clicking on the "Today" button in MobileDate[Time]Picker, the returned value is always the same => the moment at which the component was first mounted.
How to reproduce
Example: https://codesandbox.io/s/62sdn
Expected behaviour
The "Now" value should represent the current time when the user click the button, and not the time when the component was first mounted.
Describe the changes
Somehow, removing the useReft fix the issue, i suspect some hook cache magic being used somewhere in React, but i don't know enough about the Hook implementation so...
Here is a sandbox using the fix proposed in the PR: https://codesandbox.io/s/funny-liskov-8pdp7