Skip to content

Setting DatePicker format to DD MMM YYYY but deleting the MMM will make the textfield shows MMMM (Long Month format) #8526

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

Closed
2 tasks done
kianjunhen opened this issue Apr 6, 2023 · 10 comments
Labels
component: pickers This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation support: question Community support but can be turned into an improvement

Comments

@kianjunhen
Copy link

kianjunhen commented Apr 6, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example:

Steps:

  1. Use the basic date picker
  2. Make the format to 'DD MMM YYYY'
  3. Select any date from Date Picker or enter from keyboard
  4. Manual delete the MMM
  5. The preview will show 'DD MMMM YYYY'

Current behavior 😯

image
image

Expected behavior 🤔

No response

Context 🔦

No response

Your environment 🌎

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Order ID or Support key 💳 (optional)

No response

@kianjunhen kianjunhen added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Apr 6, 2023
@zannager zannager added the component: pickers This is the name of the generic UI component, not the React module! label Apr 6, 2023
@alexfauquette
Copy link
Member

That's the expected behavior. When a section is empty, it shows a placeholder which is not necessarily the format token. Here for month, the default is 4 letters for words and 2 letters for numbers

// From src/locales/enUS.ts
fieldMonthPlaceholder: (params) => (params.contentType === 'letter' ? 'MMMM' : 'MM'),

You can modify this behavior by providing custom localeText:

// Field section placeholders
fieldYearPlaceholder: (params) => 'Y'.repeat(params.digitAmount),
fieldMonthPlaceholder: (params) => (params.contentType === 'letter' ? 'MMMM' : 'MM'),
fieldDayPlaceholder: () => 'DD',
fieldWeekDayPlaceholder: (params) => (params.contentType === 'letter' ? 'EEEE' : 'EE'),
fieldHoursPlaceholder: () => 'hh',
fieldMinutesPlaceholder: () => 'mm',
fieldSecondsPlaceholder: () => 'ss',
fieldMeridiemPlaceholder: () => 'aa',

This information could be added in the base concept pages

@kianjunhen
Copy link
Author

Thanks Alex for the input, it works now.

@alexfauquette
Copy link
Member

@flaviendelangle What do you think about?

This information could be added in the base concept pages

@alexfauquette alexfauquette added docs Improvements or additions to the documentation support: question Community support but can be turned into an improvement and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Apr 7, 2023
@flaviendelangle
Copy link
Member

They are documented here

I think it's too specific to be in the Base concept

@alexfauquette
Copy link
Member

Ok, it appears in algolia, so might be enough, will see it this issue arrive back

image

@AkshayHere
Copy link

That's the expected behavior. When a section is empty, it shows a placeholder which is not necessarily the format token. Here for month, the default is 4 letters for words and 2 letters for numbers

// From src/locales/enUS.ts
fieldMonthPlaceholder: (params) => (params.contentType === 'letter' ? 'MMMM' : 'MM'),

You can modify this behavior by providing custom localeText:

// Field section placeholders
fieldYearPlaceholder: (params) => 'Y'.repeat(params.digitAmount),
fieldMonthPlaceholder: (params) => (params.contentType === 'letter' ? 'MMMM' : 'MM'),
fieldDayPlaceholder: () => 'DD',
fieldWeekDayPlaceholder: (params) => (params.contentType === 'letter' ? 'EEEE' : 'EE'),
fieldHoursPlaceholder: () => 'hh',
fieldMinutesPlaceholder: () => 'mm',
fieldSecondsPlaceholder: () => 'ss',
fieldMeridiemPlaceholder: () => 'aa',

This information could be added in the base concept pages

Any ideas on how to use the fieldMonthPlaceholder ?
There are no examples there where I can see how this is used.

@flaviendelangle
Copy link
Member

flaviendelangle commented Oct 24, 2023

You have the answer just above 👍

#8526 (comment)

And for a more in-depth explanation on how to pass locales to the grid: https://mui.com/x/react-date-pickers/localization/

@Shekiel
Copy link

Shekiel commented Jul 10, 2024

@flaviendelangle I agree with @AkshayHere, could you please provide an example of how this can be used?

@LukasTy
Copy link
Member

LukasTy commented Jul 10, 2024

@Shekiel have you checked the 2nd code example in here?

@Shekiel
Copy link

Shekiel commented Jul 10, 2024

@LukasTy Thanks, just checked checked this, and this worked for me: Changing the fieldMonthPlaceholder as shown in the example to get the correct format:
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale="en-gb" localeText={{ fieldMonthPlaceholder: (params) => params.contentType === 'digit' ? 'MM' : params.format,}}>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pickers This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

7 participants