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

feat: add CSS variable for caption font size #1703

Merged
merged 1 commit into from Feb 25, 2023
Merged

feat: add CSS variable for caption font size #1703

merged 1 commit into from Feb 25, 2023

Conversation

7PH
Copy link
Contributor

@7PH 7PH commented Feb 21, 2023

Context

With default CSS and parameters and when using dropdown and buttons caption layout, the calendar width changes when cycling through the different months with default locale
image image

This may be seen as an issue for two reasons:

  • This shifts layout when interacting with the calendar. E.g. when clicking multiples times on "go to next month", it can happen that the "go to previous month" button shifts to the right and the next click is on "go to previous month" instead (reproducible in documentation page)
  • This makes the calendar less elegant when using the calendar in a dropdown or with a different background than the page

Reproduce

This can be reproduced on the currently deployed documentation website, in the example using caption layout "dropdown-buttons": https://react-day-picker.js.org/basics/navigation#choosing-a-caption-layout

import React from 'react';
import { DayPicker } from 'react-day-picker';

export default function App() {
  return (
    <DayPicker captionLayout="dropdown-buttons" fromYear={2015} toYear={2025} />
  );
}

Analysis

With the recent addition of month/year navigation using both dropdowns and buttons and default locales and CSS variables, it happens for specifics months (February, September, November, December) that the width of .rdp-caption becomes larger than .rdp-table because these months have longer names.

Solution

I reduced the font-size so that the worst-case scenario (September) fits with dropdown-buttons caption layout. This also works for the other EU locales I've tested (fr, it, es, de). I also changed the font size from % to pixels, because the table width is always --rdp-cell-size times 7 and --rdp-cell-size is in pixels. I though it made sense to add this into a variable, because if someone wants to change the cell size to something smaller, he will have to change the caption font size as well. Waiting for your thoughts on this.

After:
image

@gpbl gpbl changed the title Fix calendar width changing when cycling through months with longer names Add CSS variable for caption font-size Feb 25, 2023
@gpbl gpbl changed the title Add CSS variable for caption font-size Add CSS variable for caption font size Feb 25, 2023
@gpbl gpbl changed the title Add CSS variable for caption font size feat: add CSS variable for caption font size Feb 25, 2023
@gpbl gpbl merged commit 07659d5 into gpbl:master Feb 25, 2023
@gpbl
Copy link
Owner

gpbl commented Feb 25, 2023

Hey thanks, good one!

@7PH 7PH deleted the dev/7ph/fix-width-jump-on-month-change branch March 1, 2023 08:17
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.

None yet

2 participants