-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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] Change mobile dialog close behavior #7721
base: master
Are you sure you want to change the base?
Conversation
These are the results for the performance tests:
|
const handleDismiss = useEventCallback(() => { | ||
// Set all dates in state to equal the last committed date. | ||
// e.g. Reset the state to the last committed value. | ||
setDate({ value: dateState.committed, action: 'acceptAndClose' }); | ||
setDate({ | ||
value: resetValueOnClose ? dateState.resetFallback : dateState.committed, | ||
action: 'acceptAndClose', | ||
}); | ||
}); |
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 don't get why the modification is here. I agree "dismiss" is mostly used when closing UI. But I doubt it's a good idea to have onDismiss
behavior depending on resetValueOnClose
especially if at some point we open access to hook.
For me, it would make more sense that depending on resetValueOnClose
we either call onDismiss
or onCancel
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.
Very good point. 👌
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.
- call `handleCancel` when `resetValueOnClose`
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.
With the new naming it makes sens, @flaviendelangle do you see coming features with which it could interfere?
* If `true`, on dismiss will reset the value to the value when the picker was opened. | ||
* | ||
* Might make most sense when in need of resetting the value on modal dismiss. | ||
* @default `true` for mobile, `false` for desktop. |
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.
The default value of a boolean prop should be false
, such that you end up with either
<Components />
or <Component resetValueOnDismiss />
but not <Component resetValueOnDismiss={false} />
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.
Thank you for clearing this thing up. 👍
I've updated it, do you think it is now in a correct form? 🤔
The behavior of the pickers on close is a topic that keeps getting discussed, I would be very cautious before introducing any new prop, to make sure that we are solving peoples pain and not just fine tuning the use case of some specific user. I'll try to list the issues around this topic to check 👍 |
I do understand and agree. |
Yes, I think people should be able to save or not when closing. We have 2 topics here The default behaviorDesktopSaving when closing on desktop is what Spectrum is doing for example. Most of the discussions around this topic are linked in #4408 This specific use case is probably the one with the smallest majority on any behavior. MobileIt is the 1st feedback we get of someone wanting to reset the value (as far as I remember). How to let people choose another behaviorWhen we started to get feedback about the life-cycle, it became clear that is a very subjective topic and that if we want to make everyone happy, we need a way to customize those behaviors. One API I had in mind was to let people override part of For example: <DatePicker
lifecycleManager={({ setDate, dateState }) => ({
onDimiss: (source: 'escape' | 'click-outside') => {
setDate({ value: dateState.resetFallback, action: 'acceptAndClose' });
}
}})
/> But that's a low level API that can easily be done in a poor way and end up being worse that all those booleans props. In summary, it is very unclear to me what the default behaviors should be and how people should be able to override them. |
Indeed, your suggested API does look very powerful and fully customizable, but at the same time, as you mentioned, it could be a bit too powerful and a bit too cumbersome to use for most. Unless we provide a more user friendly option. I was also thinking about at least having a hybrid prop accepting both a boolean as well as a callback Did we ever consider having hybrid props serving both a more basic case as well as a more customized one? |
It's not something I saw on our components, but it's something I saw on other set of components. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Fixes #7700
resetValueOnClose
property, which will reset the value toresetFallback
(same as when clicking cancel) when closing modal.true
on mobile pickers so that clicking away orEsc
would reset the value (seems to make sense, given that pickers do haveCancel
andAccept
actions in this case)The only relevant change in in
usePickerValue
file.