Skip to content

fix(CalendarMonth) fix first day of month not showing when weekstart …#7679

Merged
wise-king-sullyman merged 3 commits intopatternfly:mainfrom
dominik-petrik:datepicker-bugfix
Jul 21, 2022
Merged

fix(CalendarMonth) fix first day of month not showing when weekstart …#7679
wise-king-sullyman merged 3 commits intopatternfly:mainfrom
dominik-petrik:datepicker-bugfix

Conversation

@dominik-petrik
Copy link
Copy Markdown
Contributor

…set to monday

What: Closes #7654

@wise-king-sullyman wise-king-sullyman self-requested a review July 11, 2022 12:35
@patternfly-build
Copy link
Copy Markdown
Collaborator

patternfly-build commented Jul 11, 2022

Copy link
Copy Markdown
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

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

Nice work on this! I did notice one issue that I noted below, just let me know what you think! 🙂

Comment on lines 74 to 79
let startOnWeek = 0;
if (firstDayOfWeek.getMonth() === defaultDate.getMonth() && firstDayOfWeek.getDate() !== 1) {
firstDayOfWeek.setDate(firstDayOfWeek.getDate() - 7);
startOnWeek = 1;
}
for (let i = startOnWeek; i < 6; i++) {
const week = [];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm noticing an issue when weekStart={3} is passed in and going to January 2030, where the beginning of the month gets rendered correctly, but the end of the month gets cut off:

Calendar month with end of month dates cutoff

It looks like it's caused by the for (let i = startOnWeek portion, as reverting that to i = 0 fixes it while also fixing the original issue at hand, at least in this specific scenario. Going to some other random dates seems to work fine as well.

Copy link
Copy Markdown
Collaborator

@wise-king-sullyman wise-king-sullyman left a comment

Choose a reason for hiding this comment

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

It seems that the end of some months is now getting cut off:
image

I think in order to really support this another row will need to be added to the calendar whenever this occurs, which we seem to do under some circumstances already:
image

Or alternatively, we could just always have the calendar show 6 weeks. I think that's what Google does in Google Calendar.

Also, I would like to see a test to prevent this behavior from regressing in the future.

@nicolethoen
Copy link
Copy Markdown
Contributor

@thatblindgeye and @mmenestr might have some insight into when we may or may not want 6 weeks displayed. I think they recently made some decisions regarding this topic together.

@mmenestr
Copy link
Copy Markdown
Collaborator

Yes, we basically said that it should preferably vary based on whether the 6th week has any numbers from the current month. In other words, if the month needs 6 weeks to show up fully, then the calendar should show 6 weeks, but if the month only needs 5 weeks to show up fully (which would mean that the 6th week would have no dates from the month you're currently on, and instead only show calendar days for the following month) then only 5 weeks should show.

I just thought it was weird that in a lot of cases, if we were to always show 6 weeks, you'd have a full line for dates that were not part of the month you were on.

Hopefully that makes sense!

@dominik-petrik
Copy link
Copy Markdown
Contributor Author

I fixed the last row not showing in specific cases, now it works as requested, so number of rows displayed varies based on whether the 6th week contains days from same month as selected. @wise-king-sullyman also shared some useful resources on testing with me, so I should be able to create tests to prevent this from regressing.

Copy link
Copy Markdown
Contributor

@nicolethoen nicolethoen left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment thread packages/react-core/src/components/CalendarMonth/__tests__/CalendarMonth.test.tsx Outdated
Copy link
Copy Markdown
Collaborator

@wise-king-sullyman wise-king-sullyman left a comment

Choose a reason for hiding this comment

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

Two super small nits and then this will be good to merge!

import { CalendarMonth } from '../CalendarMonth';

test('Renders the first date in a month when a custom weekStart is passed', () => {
const formatAria = (date: Date) =>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you add a comment here just stating that this custom aria label is needed because of a bug with automatic aria label generation as it is now, and that it can be removed once that bug is fixed?

Copy link
Copy Markdown
Contributor Author

@dominik-petrik dominik-petrik Jul 20, 2022

Choose a reason for hiding this comment

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

I think that'd it be actually a good thing to keep custom aria label because format of default generated aria label might change in future and the test would fail for seemingly unrelated reason.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's a fair point, though the same could be said for this approach and its reliance on the cellAriaLabel prop functioning properly. This line of thinking could also extend to many other behaviors of the component, such as the weekStart or date props working properly, or the structure of the component.

I totally get not wanting this test to be able to fail for something that isn't the actual behavior under test, but I think that it's generally reasonable for a test to rely on other behavior of the component under test since totally avoiding that would be next to impossible.

Plus if the generated aria labels are properly tested developers should be able to see that test failing as well if the generated aria label is changed, which should make it apparent what the true cause of the failure here is.

All of that being said I don't think what you've got here is bad by any means and I don't think it neccesarily needs to go, but I would still like a comment saying why it's here and that it shouldn't be needed once the bug is fixed 🙂

expect(firstDate).toBeVisible();
});

test('Renders the first date in a month when a custom weekStart is passed', () => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
test('Renders the first date in a month when a custom weekStart is passed', () => {
test('Renders the last date in a month when a custom weekStart is passed', () => {

Copy link
Copy Markdown
Collaborator

@wise-king-sullyman wise-king-sullyman left a comment

Choose a reason for hiding this comment

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

🚀 This is really awesome work!

@wise-king-sullyman wise-king-sullyman merged commit 447095d into patternfly:main Jul 21, 2022
@patternfly-build
Copy link
Copy Markdown
Collaborator

Your changes have been released in:

  • eslint-plugin-patternfly-react@4.64.9
  • @patternfly/react-catalog-view-extension@4.76.9
  • @patternfly/react-charts@6.78.9
  • @patternfly/react-code-editor@4.66.9
  • @patternfly/react-console@4.76.9
  • @patternfly/react-core@4.225.9
  • @patternfly/react-docs@5.86.9
  • @patternfly/react-icons@4.76.9
  • @patternfly/react-inline-edit-extension@4.70.9
  • demo-app-ts@4.185.9
  • @patternfly/react-integration@4.187.9
  • @patternfly/react-log-viewer@4.70.9
  • @patternfly/react-styles@4.75.9
  • @patternfly/react-table@4.94.9
  • @patternfly/react-tokens@4.77.9
  • @patternfly/react-topology@4.72.9
  • @patternfly/react-virtualized-extension@4.72.9
  • transformer-cjs-imports@4.63.9

Thanks for your contribution! 🎉

jenny-s51 pushed a commit to jenny-s51/patternfly-react that referenced this pull request Jul 26, 2022
patternfly#7679)

* fix(CalendarMonth) some weeks not showing when weekstart changed

* fix(CalendarMonth) test added

* fix(CalendarMonth) update tests
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.

Bug - Datepicker - impossible select some days

6 participants