-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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] Pass the shortcut information in the onChange
context
#9985
Conversation
a189a1d
to
47ce080
Compare
onChange
context
47ce080
to
21efe80
Compare
21efe80
to
0bd5c48
Compare
Netlify deploy previewNetlify deploy preview: https://deploy-preview-9985--material-ui-x.netlify.app/ Updated pagesThese are the results for the performance tests:
|
I would be in favor of passing an object. For example For example, new month would be {
id: 'next-month',
label: t('pickers.shortcuts.next-month'),
getValue: () => ...
} And I assume we could get other requests |
I agree that passing the full object would be more future-proof |
PR updated |
onChange
contextonChange
context
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.
Nice improvement! 👍
packages/x-date-pickers/src/internals/hooks/usePicker/usePickerValue.ts
Outdated
Show resolved
Hide resolved
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.
Looking great! 💙
Just though a possibly very useful and relevant addition for the demo.
What do you think about marking the shortcut chip that has been selected as active?
I imagine that such change might be needed by most people caring about, which shortcut has been clicked. 🤔
This could uncover the fact that it's pretty much mandatory to add an id
prop to shortcut item in order to reliably identify, which shortcut has actually been called.
Imagine a case of multi locale application having translated shortcuts, user selects a shortcut and it is supposedly saved in storage. Once the user visits the page again having changed locale or maybe the shortcut label (translation) has been updated—the saved shortcut can no longer be mapped. 🙈
Co-authored-by: Lukas <llukas.tyla@gmail.com> Signed-off-by: Flavien DELANGLE <flaviendelangle@gmail.com>
The only issue here is that the type of the shortcut is fixed, you can not pass it as a generic to your component. For the idea of the chip, that would be a nice improvement indeed 👌 |
Looks like the individual shortcut are not a slot, so it's hard to pass props to them. |
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.
Looks like the individual shortcut are not a slot, so it's hard to pass props to them.
Maybe we could improve the demo as a follow up if we want to create a new slot.
It's nice that our investigation uncovered a shortcoming in the implementation. 👍
@alexfauquette I let you confirm that I'm not missing a way to do this customization with the current API and I will create an issue if not 👍 |
I confirm it's not feasible, at least not in an easy way |
Closes #9897
@alexfauquette I would like your opinion on this one.
Would you pass the label?
Would you pass the entire shortcut object?
Would you go for the more hacky solution proposed in the issue of adding an
onChange
prop to the shortcut object? (I fear that people trigger there onChange based on this slot prop instead of using the picker props).Another approach?
Do nothing?