-
Notifications
You must be signed in to change notification settings - Fork 101
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
feat(ui-date-input): improve DateInput2 api, extend docs #1640
Conversation
|
a7b3b8c
to
42c83a2
Compare
@@ -2,28 +2,37 @@ | |||
describes: DateInput2 | |||
--- | |||
|
|||
This component is an updated version of [`DateInput`](/#DateInput) that's easier to configure for developers, has a better UX, better accessibility features and a year picker. We recommend using this instead of `DateInput` which will be deprecated in the future. | |||
`DateInput2` is an experimental upgrade to the existing [`DateInput`](/#DateInput) component, offering easier configuration, better UX, improved accessibility, and a year picker. While it addresses key limitations of `DateInput`, it's still in the experimental phase, with some missing unit tests and potential (though unlikely) API changes. `DateInput` will be deprecated in the future, but for now, developers can start using `DateInput2` and provide feedback. |
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 would not expose this information to the public: whether we have unit tests or not.
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 think we can disclose this for experimental components
@@ -45,9 +45,9 @@ type DateInput2OwnProps = { | |||
nextMonthButton: string | |||
} | |||
/** | |||
* Specifies the input value. | |||
* Specifies the input value *before* formatting. The `formatDate` will be applied to it before displaying. Should be a valid, parsable date. |
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 would mention here what a parseable date is, e.g. link this https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format
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.
that would be a good addition
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.
There is some weirdness going on with date parsing. I got these settings:
locale="hu-hu"
timezone="Australia/Sydney"
When I select say 10th August in the Calendar dropdown the first example will display:
UTC Date String: 2024-08-09T14:00:00.000Z
Input Value: 2024. augusztus 10.
Which is OK I guess, selecting 10th August (midnight) in Australia is 9th August in London.
But if I enter into this DateInput: 2024-08-10
and focus out, it treats the entered date as UTC:
UTC Date String: 2024-08-10T00:00:00.000Z
Input Value: 2024. augusztus 10.
Also watch out Date's parser is so broken that its scary. From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format : "When the time zone offset is absent, date-only forms are interpreted as a UTC time and date-time forms are interpreted as local time." Either use Moment's or make 100% sure that we always add timezone offset |
I think adding the timezone offset everywhere is the right solution here and that would solve the bug you mention above too |
886c0bb
to
92c6449
Compare
1490704
to
0f310ef
Compare
Some funky locale bugs: Set locale to In the "with year picker" example I can move forward with the arrows to feb. 2025. Here the year picker will be empty. Same if I enter a date after 2024 manually. I dont have a good solution for this besides implementing some min/max prop. |
0f310ef
to
5304c56
Compare
|
b966e59
to
7b3867a
Compare
|
||
Any of the following separators can be used when typing a date: `,`, `-`, `.`, `/` or a whitespace however on blur the date will be formatted according to the locale and separators will be changed and leading zeros also adjusted. | ||
|
||
If you want different parsing and formatting then the current locale you can use the `dateFormat` prop which accepts either a string with a name of a different locale (so you can use US date format even if the user is France) or a parser and formatter functions. |
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.
Its not clear for me from this how the Dateformat prop as string differs from the locale
prop. I would make a new paragraph for these where I would also write about how it gets calculated. You can reuse it from DateTimeInput
:
"Localization
The component is localized via its locale and timezone parameters. Both are read from props, context and from the browser's locale in this priority order. locale determines the language and format dates and time are displayed in (e.g. month names, AM/PM or 24-hour format) and the beginning of the week (e.g. Monday in Germany, Sunday in the U.S.) in the dropdown calendar."
// split input on '.', whitespace, '/', ',' or '-' using regex: /[.\s/.-]+/ | ||
// the '+' allows splitting on consecutive delimiters | ||
const [year, month, day] = input.split(/[,.\s/.-]+/) | ||
const newDate = new Date(year, month-1, day) |
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.
This is interpreted in local time. I think it could lead to bugs if the component uses a different timezone -- it might return a date a day before/after?
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.
might be true, I will check that
509e102
to
fe75f11
Compare
fe75f11
to
ed2b141
Compare
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 work!
/INSTUI-4219
this PR simplifies and improves the
DateInput2
apithe docs are also extended to address the experimental nature of the component and elaborate on usage
test plan:
try the following things in a couple different locales (e.g.
it-it
,ar-eg
,pt-br
)