Closed alexfauquette closed 2 years ago
first solution: control the selection such that the user can only modify one digit https://codesandbox.io/s/basictextfields-demo-material-ui-forked-iizr1c?file=/demo.tsx
second solution: control the selection such that the user can only modify one piece (day/month/year) at the time TODO
Move to #5504
The Month and Year picker
Current behavior
For now, the masked input is managed by 4 props:
inputFormat
which indicates how the date should be formattedmask
The expected shape'__/____'
where each'_'
is a slot for an accepted characteracceptRegex
a Regexp allowing to define which characters are accepted to fill_
slots. Most of the time/\dap/gi
or/\d/gi
to allow'a', 'p'
when writing AM/PM timesdisableMaskedInput
simply disable the mask, user can do whatever they wantThis feature is important for keyboard interaction because, without a mask, it's easy to miss a space or use a
/
instead of a-
which will lead to an invalid date, so we discourage usingdisableMaskedInput={true}
Those parameters are strongly linked together. Modifying
inputFormat
withoutmask
does not make sens, anddisableMaskedInput
should be used only if it's impossible to provide amask
for the wantedinputFormat
This leads to the following weird behavior for developers: The default props for the date picker depend on the views provided:
The main problem here is the "Year and Month" case, because it set by default
disableMaskedInput
totrue
monthAndYear
returns strings such as"Jan, 1"
which are not supported by the mask enginemask
/inputFormat
it still does not work, that have to adddisableMaskedInput={false}
Proposed Solution
(A) Modify the format
Set a format MM/YYYY such as proposed in #4664
(B) Drop month and year
This feature set magically the
inputFormat
when developers only care about the month and the year. But it seems to do more damage than it helps, so we could remove the special case of month and yearsdisableMaskedInput
will always befalse
MM/YYYY
with the appropriate mask if they want to remove the days in the format(C) Group related variables
We could regroup all the variables in one object:
The defaultized value would be as follow. The idea is to keep default
acceptRegex
because it's rare to have to change it, and addap
for AM/PM is easy to forget.disableMask
toundefined
disableMaskedInput=true
(D) Have a special behavior when mask/format is provided
Same as option (C) but without grouping everything in a JS object. The default value would be computed as follow:
disableMask
tofalse
disableMaskedInput=true
I put other pain points below because they can have an influence on how we resolve the one above
The locale management #4756
Current behavior
The mask is set by default, lives in Europe or America with
__/__/____
date mask. Spoiler: it's not the case, some locales set the year first leading to a mask____/__/__
Proposed modification
remove the
mask
and use theinputFormat
to compute it.Managing more masks
Current behavior
The masked input support format with fix length and only digits. This excludes formats such as
1/2/2025
(because the number of digits can be 1 or 2 for months and days) orJun 2012
because it uses letters (even if number of letters is fix).Objective
Support mask for those, with mask such as [1or2digitsDay]/[1or2digitsMonth]/[year] Not sure if it is possible