Skip to content
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

[WNMGDS-2757] Upgrade react-day-picker library #3064

Merged
merged 19 commits into from
May 2, 2024

Conversation

pwolfert
Copy link
Collaborator

Summary

WNMGDS-2757

See background in the ticket and in #2920. We're upgrading the react-day-picker library primarily because the old version did not support ES Modules, which causes problems with modern build tools.

Before we could do this upgrade, we had to contribute a fix upstream for Preact support, and that resulted in this release, which is what we're upgrading to.

Note that this upgrade will drop our uncompressed React bundle size from 407KB to 387KB.

Changes:

  • Upgraded react-day-picker dependency from 8.0.5 to 8.10.1
  • Upgraded date-fns dependency from 2.28.0 to 3.0.6
  • Changed the disabled-button styles in the calendar picker to fix low color contrast. While color contrast standards are ignored for disabled elements, we wanted to improve the experience for all users by improving the contrast. Instead of lightening the disabled buttons, we strike the numbers through and use the muted color in our design system palette (see updated VRT reference images).

How to test

  1. e3a61b7 can be used to test it out in other example projects. After that commit, the date field was removed from the basic examples.
  2. Test in Storybook too

Checklist

  • Prefixed the PR title with the Jira ticket number as [WNMGDS-####] Title or [NO-TICKET] if this is unticketed work.
  • Selected appropriate Type (only one) label for this PR, if it is a breaking change, label should only be Type: Breaking
  • Selected appropriate Impacts, multiple can be selected.
  • Selected appropriate release milestone

If this is a change to code:

  • Created or updated unit tests to cover any new or modified code
  • If necessary, updated unit-test snapshots (yarn test:unit:update) and browser-test snapshots (yarn test:browser:update)

To reproduce the error, go to the day picker story and click the calendar button. It will throw an error about `.current` and coming from a jsx function

I wonder if the change [between react-day-picker v8.8.2 and v8.9.0](gpbl/react-day-picker@v8.8.2...v8.9.0) causing problems is the removal of the React imports from the modules. I know we've had issues with that in the past. Right now if I upgrade past v8.8.2, Storybook will work with React but not with Preact. I think in order for us to be able to use libraries that use the new JSX transform, we have to use the new JSX transform, but we can't use the new JSX transform until we can safely drop support for React 16.

I've tried changing the TS config setting to
```json
"jsx": "react-jsx",
```
but it doesn't seem to fix the problem.
…t projects

It only works if Preact is in React-compatability mode. It works in examples/preact-react-app but not examples/preact-app.
…les support

While this doesn't work in this commit, the whole goal of this effort is to make it work. The problem is figuring out how to get their built-in JSX transform functions to play nice with the way _we_ handle JSX, React, and Preact.
These changes were made after discussion with both Accessibility and Design and have been approved by UX leads
@pwolfert pwolfert added Type: Fixed Indicates an unexpected problem or unintended behavior Impacts: Core Impacts the core DS primarily, changes may occur in other themes as well. labels Apr 30, 2024
@pwolfert pwolfert added this to the 11.0.0-beta.1 milestone Apr 30, 2024
@pwolfert pwolfert requested a review from zarahzachz April 30, 2024 19:15
Copy link
Collaborator

@zarahzachz zarahzachz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The library may have an a11y bug. Or it's how we've implemented it. Or it doesn't matter! 😵

So I've found the calendar picker does accurately prevent user interaction (users can't use keyboards or pointers to select out of range dates, and that's good!) but if a user types a date that's out of range, the picker applies aria-selected="true" to a disabled date! Is this a bug? I don't know! Maybe disabled has higher specificity and aria-selected doesn't matter?

Screen.Recording.2024-05-01.at.10.33.48.AM.mov

}

.rdp-button:not([aria-disabled='true']) {
.rdp-button:not(:disabled) {
cursor: pointer;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an odd rule - our buttons have this set in our reset file so this must be undoing another style this library has set?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be redundant; I'll check

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, they have a button reset rule of their own. That could be something to revisit later—whether we want to try to optimize their CSS. At the beginning, our strategy was to try to keep their original CSS mostly intact and add overrides to it so it would be easy to upgrade the library as time went on. With that strategy, though, we do include a lot more rules than we need.

@@ -67,12 +67,7 @@
border: 2px solid transparent;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, see my comment below on the cursor pointer, but this rdp-button_reset class is doing a lot of redundant things too. I think we only need the background: none bit but this could use a deeper dive to ensure that doesn't introduce regressions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above. I think this is out of scope for this work right now, but we should follow up on it.


@media (forced-colors: active) {
background-color: GrayText;
cursor: not-allowed;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this has point-events:none I don't think cursor: not-allowed will work

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's interesting! Good catch. When I go back and look at their PR that switched back from aria-disabled to disabled, it looks like they removed the pointer-events: none because it's not needed when the browser already knows the button is disabled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a107aa5

…e pointer events

And this keeps us from being able to apply the `not-allowed` cursor style
@pwolfert
Copy link
Collaborator Author

pwolfert commented May 1, 2024

@zarahzachz, about the odd behavior you found with out-of-range dates:

if a user types a date that's out of range, the picker applies aria-selected="true" to a disabled date! Is this a bug? I don't know! Maybe disabled has higher specificity and aria-selected doesn't matter?

I don't think we should wade into the territory of implementing validation on this component, and I think that would fall in that category. The app team is responsible for supplying those date ranges, so they should be validating and showing an error message. Right now it does appear that the disabled style has higher specificity, so at least we aren't showing that they've selected an invalid date in the calendar. I just tested with VoiceOver, and the fact that we don't move focus to the selected button when the calendar is opened makes me believe a screen reader user will never hear that selected state in normal usage.

@pwolfert pwolfert merged commit 002b95e into main May 2, 2024
1 check passed
@pwolfert pwolfert deleted the pwolfert/upgrade-day-picker branch May 2, 2024 02:55
@pwolfert pwolfert removed this from the 11.0.0-beta.1 milestone May 3, 2024
@pwolfert pwolfert added this to the 10.1.0 milestone May 3, 2024
pwolfert added a commit that referenced this pull request May 10, 2024
* This is the minimum version that causes the issue in Preact Storybook

To reproduce the error, go to the day picker story and click the calendar button. It will throw an error about `.current` and coming from a jsx function

I wonder if the change [between react-day-picker v8.8.2 and v8.9.0](gpbl/react-day-picker@v8.8.2...v8.9.0) causing problems is the removal of the React imports from the modules. I know we've had issues with that in the past. Right now if I upgrade past v8.8.2, Storybook will work with React but not with Preact. I think in order for us to be able to use libraries that use the new JSX transform, we have to use the new JSX transform, but we can't use the new JSX transform until we can safely drop support for React 16.

I've tried changing the TS config setting to
```json
"jsx": "react-jsx",
```
but it doesn't seem to fix the problem.

* Discovered that our SingleInputDateField doesn't work in native Preact projects

It only works if Preact is in React-compatability mode. It works in examples/preact-react-app but not examples/preact-app.

* Upgrade to the version of RDP that gives us date-fns 3.0 with ES Modules support

While this doesn't work in this commit, the whole goal of this effort is to make it work. The problem is figuring out how to get their built-in JSX transform functions to play nice with the way _we_ handle JSX, React, and Preact.

* Upgrade date-fns too. It all works in the Astro example

* Upgrade to fixed version

* Fix `preact-app` example

* Update CSS because of `aria-disabled` to `disabled` change upstream

* Fix selectors

* Address color-contrast issues with design changes

These changes were made after discussion with both Accessibility and Design and have been approved by UX leads

* Fix strike-through in forced-colors mode

* Update VRT refs

* Add it to the astro example too

* Remove from examples where it isn't needed now that we've tested it

* Update VRT refs of astro example where we added the date field

* Now that these buttons are actually disabled, we don't need to disable pointer events

And this keeps us from being able to apply the `not-allowed` cursor style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Impacts: Core Impacts the core DS primarily, changes may occur in other themes as well. Type: Fixed Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants