Skip to content

Make Calendar able to scale down responsively #7583

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

Merged
merged 8 commits into from
Apr 15, 2025

Conversation

MikeKingdom
Copy link
Collaborator

Replaces #7581

What does this PR do?

This PR makes Calendar able to scale down if the specified size is smaller than the viewport.
This is to meet WCAG 1.4.10 Reflow. See #7557 .

Calendar accepts a size property that defaults to medium (384px). WCAG 1.4.10 requires that certain chunks of information be able to reflow and only require scrolling in 1 direction to see them down to 320px wide. 320px is basically equivalent to a 400% zoom of a 1280 display.

The change adds a @media query at the size of the Calendar. If the viewport width is smaller than this size this adjusts the styles of the Calendar to narrow. This can be disabled by setting responsive={false} or by using fill.

Only the width squishes and not the height so the result can be cells that are non-square. Currently I feel like this is acceptable since it would be a lot more work to scale the height also (although ideas are more than welcome.)

UPDATE: Now the Calendar maintains aspect ratio as it shrinks,

Here's an example using the Input/DateInput/Simple story:
Normal size:
image

At 320px screen width:
image

At 320px screen width with a highlighted/button date:
image

Where should the reviewer start?

StyledCalendar.js

What testing has been done on this PR?

Jest and Storybook

How should this be manually tested?

Any of the Calendar or DateInput storys in storybook

Do Jest tests follow these best practices?

  • screen is used for querying.
  • The correct query is used. (Refer to this list of queries)
  • asFragment() is used for snapshot testing.

Any background context you want to provide?

What are the relevant issues?

Fixes #7557

Screenshots (if appropriate)

Do the grommet docs need to be updated?

Yes

Should this PR be mentioned in the release notes?

Yes

Is this change backwards compatible or is it a breaking change?

Backwards compatible

const responsiveDaySizeStyle = (props) => {
const breakpoint = props.theme.global.size[props.sizeProp];
const data = props.theme.calendar[props.sizeProp];
// try width: 100%; max-width: data.daySize
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// try width: 100%; max-width: data.daySize

This is implemented, can we remove?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done


const responsiveSizeStyle = (props) => {
const breakpoint = props.theme.global.size[props.sizeProp];
// try width: 100%; max-width: width
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// try width: 100%; max-width: width

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

{ value: breakpoint },
`
height: auto;
aspect-ratio: 7/6;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remind me why 7/6? Could we add a comment for future reference?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Answered via slack but replying here also for others benefit. 7 days per week, 6 weeks shown. Pre-existing code does 14.6% width (100%/7) and 6*daySize height.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good to know, agree adding a comment in the code would be helpful for future

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

@taysea taysea left a comment

Choose a reason for hiding this comment

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

Behavior and styling looks great. Just added a few small comments. Nice find with aspect-ratio.

Copy link
Collaborator

@jcfilben jcfilben left a comment

Choose a reason for hiding this comment

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

Code looks good

@MikeKingdom MikeKingdom requested review from taysea and jcfilben April 14, 2025 19:46
Copy link
Collaborator

@jcfilben jcfilben left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Collaborator

@taysea taysea left a comment

Choose a reason for hiding this comment

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

Thanks, Mike!

@jcfilben jcfilben merged commit 20da157 into master Apr 15, 2025
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Date Input - 1.4.10 Reflow
3 participants