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

[Pickers] Fix onDismiss handler in MobileDatePicker #30768

Merged
merged 11 commits into from
Feb 3, 2022

Conversation

Ashish2097
Copy link
Contributor

@Ashish2097 Ashish2097 commented Jan 25, 2022

Closes #30731

@mui-bot
Copy link

mui-bot commented Jan 25, 2022

Details of bundle changes

Generated by 🚫 dangerJS against 381d1c1

@danilo-leal danilo-leal added the component: pickers This is the name of the generic UI component, not the React module! label Jan 25, 2022
@danilo-leal danilo-leal changed the title Fix/30731 mobile picker cancel [Pickers] Fix mobile picker cancel button Jan 25, 2022
Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

Let's add test for it

@mnajdova mnajdova added the PR: needs test The pull request can't be merged label Jan 26, 2022
@Ashish2097
Copy link
Contributor Author

Hi @mnajdova, added the test cases.

@hbjORbj hbjORbj added bug 🐛 Something doesn't work and removed PR: needs test The pull request can't be merged labels Jan 28, 2022
@hbjORbj hbjORbj changed the title [Pickers] Fix mobile picker cancel button [Pickers] Fix cancel behaviour in MobileDatePicker Jan 28, 2022
@hbjORbj hbjORbj changed the title [Pickers] Fix cancel behaviour in MobileDatePicker [Pickers] Fix onDismiss handler in MobileDatePicker Feb 2, 2022
@hbjORbj hbjORbj force-pushed the fix/30731-mobile-picker-cancel branch from 989f4d4 to 381d1c1 Compare February 2, 2022 11:44
@hbjORbj
Copy link
Member

hbjORbj commented Feb 2, 2022

I can confirm in this codesandbox that the issue is fixed.

Codesandbox before the fix: https://codesandbox.io/s/eloquent-feather-iznb0?file=/src/Demo.tsx

Comment on lines +73 to +74
const [initialDate, setInitialDate] = React.useState<TDateValue>(draftState.committed);

Copy link
Member

Choose a reason for hiding this comment

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

This means initialDate will always be the first value of draftState.committed. Is this the expected behavior? (I don't know the whole implementation but creating another state kinda concern me a bit because it can create another bug where the state is not updated)

Copy link
Member

Choose a reason for hiding this comment

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

It is set to the value of draftState.committed when the component first loads, and afterwards, it is newly set every time user clicks "OK". (We call setInitialDate inside acceptDate function, only if needClosePicker is true. You can check my last commit).

Copy link
Member

Choose a reason for hiding this comment

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

I see, thanks for the explanation 👍

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we need one more additional state :)

Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

👍 This is awesome for the first contribution!

@hbjORbj hbjORbj merged commit 6eb0003 into mui:master Feb 3, 2022
@mnajdova
Copy link
Member

mnajdova commented Feb 3, 2022

@flaviendelangle FYI

@flaviendelangle
Copy link
Member

Thanks, I'm reproducing it on MUI-X 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: pickers This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MobileDatePicker's Cancel button does not work.
8 participants