Skip to content

Conversation

@entioentio
Copy link
Contributor

From UX point of view years should be sorted descending for some cases. When the custom yearRange is specified with descending array, the function breaks.

From UX point of view years should be sorted descending for some cases. When the custom yearRange is specified with descending array, the function breaks.
Copy link
Owner

@JosephusPaye JosephusPaye left a comment

Choose a reason for hiding this comment

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

Just a small change...

Copy link
Contributor Author

@entioentio entioentio left a comment

Choose a reason for hiding this comment

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

Perfect! I was a bit concerned about this but didint think of computed as a solution

@JosephusPaye
Copy link
Owner

Just had a thought for another solution. We can assume that the year range will always be sorted, in ascending or descending order. This will save the cost of sorting a potentially big array that will probably already be sorted in the first place.

So all we need is to pick the earliest and latest years using the first and last elements of the array.

Then this line in previousMonthDisabled() can be replaced with:

const firstYear = Math.min(this.yearRange[0], this.yearRange[this.yearRange.length - 1]);
const outsideYearRange = lastDayOfPreviousMonth.getFullYear() < firstYear;

Similarly this line in nextMonthDisabled() can be replaced with:

const lastYear = Math.max(this.yearRange[0], this.yearRange[this.yearRange.length - 1]);
const outsideYearRange = firstDayOfNextMonth.getFullYear() > lastYear;

@entioentio
Copy link
Contributor Author

Great. I've added your min/max solution. It's elegant, cool.

@entioentio
Copy link
Contributor Author

Let me know if you need anything more to be changed

@JosephusPaye
Copy link
Owner

I'll merge this for the next release. Thanks!

@JosephusPaye JosephusPaye changed the title Fixing issue with descending years UiCalendar: Fix prev/next month buttons when yearRange is desc Dec 31, 2021
@JosephusPaye JosephusPaye merged commit 1110903 into JosephusPaye:next Dec 31, 2021
@JosephusPaye
Copy link
Owner

Thanks!

@JosephusPaye
Copy link
Owner

Released in v1.3.2

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.

2 participants