-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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] How can I get access to the Pickers Adapter Utils for use with usePickersTranslations
?
#13768
Comments
Hello @kealjones-wk. |
usePickersTranslations
?usePickersTranslations
?
The issue has been inactive for 7 days and has been automatically closed. |
Hello @LukasTy sorry for the delay in response I went on holiday after creating this and just got back. Our use case is Wrapping DateRangePicker (and probably others in the future) to change its functionality to act and look more similar to the DatePicker component, meaning having the Open Picker Button/Icon Adornment instead of opening on click, adding ability to use the keyboard with the calendar, etc. Because we added the Open Picker Button we need |
I struggle to understand what is missing for you. If you could create a working reproduction case, it would help us a lot 🙏 |
Note Edited emphasises and word choices to not be such a doo doo head.
@flaviendelangle Yes, I have access to the methods, but thats not the problem. The problem is that they are unusable because they require a utils/adapter argument and without I cannot create a working reproduction... but here is an example of not being able to use the method, see line 25 of For some further context: Now check:
and follow that through to the mui-x/packages/x-date-pickers/src/internals/hooks/useDesktopPicker/useDesktopPicker.tsx Line 110 in 39b38ae
that mui-x/packages/x-date-pickers/src/internals/hooks/useDesktopPicker/useDesktopPicker.tsx Line 69 in 39b38ae
is there some other way to get the adapter/utils that is public? cause if not Let me know if you need anything else. :) |
OK, I totally missed this "detail". @LukasTy, we should be able to host the |
If I get it right the utils are actually just the current adapter. |
I like the idea that the user never has to directly interact with the adapter. Right now the adapter is public API, so I respect semver, but people never have to use it so I have no bad feeling breaking things in majors. So I'm not a big fan of exporting Plus, if const utils = useUtils();
const translations = usePickersTranslations();
const label = translations.openTimePickerDialogue(value, utils); Is a worse DX than this IMHO: const translations = usePickersTranslations();
const label = translations.openTimePickerDialogue(value); Since we ask people to import something from our package just to pass it back. |
Good points @flaviendelangle ... I'll look into moving the utils a level up so that they don't have to be passed into these methods |
@flaviendelangle That is a great suggestion. 👍 In this case, I fear that the proposed change is hardly doable without a BC, at least a slight one, because translations are public and if we decide to change their API then it could mean a migration to someone with custom local translations. As for the technical part of the change, we are talking about something like this? -openDatePickerDialogue: (value, utils) =>
+openDatePickerDialogue: (value, formattedDate) =>
- value !== null && utils.isValid(value)
+ value !== null && formattedDate
- ? `Choose date, selected date is ${utils.format(value, 'fullDate')}`
+ ? `Choose date, selected date is ${formattedDate}`
: 'Choose date', And on the usage side: -'aria-label': getOpenDialogAriaText(pickerFieldProps.value, utils),
+'aria-label': getOpenDialogAriaText(pickerFieldProps.value, utils.isValid(pickerFieldProps.value) ? utils.format(pickerFieldProps.value, 'fullDate') : null), |
What if we keep the utils for now but make it nullable, and stop using it in the actual translations. As for the technical part, I did not dive into it honestly. |
I am 100% behind @flaviendelangle idea of making the 2nd arg nullable/undefinable and mui using the PERSONALLY, I don't think there are many consumers of this API besides me as no one tends to be complaining about this besides me, AND the fact that the ONLY way to even provide that 2nd arg that i can think of is to construct your own unique instance of an adapter that might not match the one that was provided by the consumers which would cause its own issues. so like that |
PS. @flaviendelangle sorry for any rudeness in my comment above. I was in a bad headspace that week. I should have explained much of those details in the original issue. Thank you for putting up with me anyway and sorry about that. <3 |
No offense taken 🙏 |
Just wanted to check in on this and see if it was gonna be picked up? |
@kealjones-wk I took over the topic |
<3 awesome! Thanks so much @flaviendelangle |
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Note We value your feedback @kealjones-wk! How was your experience with our support team? |
The problem in depth
#13657 Added
usePickersTranslations
which is awesome, but it didn't provide a public version ofuseUtils
like was requested in #12691Access to the Adapter Utils is necessary to use at least 3 of the properties on LocaleText, see:
openDatePickerDialogue
,openTimePickerDialogue
, andclockLabelText
. There is currently no public way to get the utils for this argument that i know of. Is there some way that i don't know of?Actual in depth issue explained in a comment below: #13768 (comment)
Your environment
No response
Search keywords: useUtils, date pickers, localization, localeText, adapter, utils
Order ID: 82849
The text was updated successfully, but these errors were encountered: