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

Calendar: Multiple Month/Year selection mode not highlighting selected month #4892

Closed
AbdelhakGuettaf opened this issue Sep 7, 2023 · 8 comments · Fixed by #4908
Closed
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@AbdelhakGuettaf
Copy link
Contributor

Describe the bug

After taking a brief look, it seems like the isMonthSelected function in the calendar component is not functioning as it should:

   const isMonthSelected = (month) => {
        if (isComparable()) {
            let value = isRangeSelection() ? props.value[0] : props.value;
            return !isMultipleSelection() ? value.getMonth() === month && value.getFullYear() === currentYear : false;
        }
        return false;
    };

value is an array of dates when the selectionMode is multiple not a single date. Same could be for Years but I haven't checked

Reproducer

No response

PrimeReact version

9.6.2

React version

18.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

Selected months or years should be highlighted.

@AbdelhakGuettaf AbdelhakGuettaf added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Sep 7, 2023
@melloware
Copy link
Member

From that code it looks like if multiple selection it will always return false.

Looks like PrimeVue has the same code: https://github.com/primefaces/primevue/blob/fd51e4226e524b59d89ea7c9f08ee5482d84e488/components/lib/calendar/Calendar.vue#L673-L681

PrimeNG is slightly different but still returns false https://github.com/primefaces/primeng/blob/d7177ab835dc8bb61df7771deb26756742e7a439/src/app/components/calendar/calendar.ts#L1643

So I guess this is intentional?

@melloware melloware added Status: Discussion Issue or pull request needs to be discussed by Core Team and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Sep 8, 2023
@AbdelhakGuettaf
Copy link
Contributor Author

It should return true if multipleSelection is true, but it doesn't because its comparing wrong values. If multiple selection is true then the props.value is an array.

@melloware

This comment was marked as outdated.

@melloware
Copy link
Member

Oh no i see what you mean. They are just sending back false but really it needs to loop over all the dates to see if it is selected.

@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Discussion Issue or pull request needs to be discussed by Core Team labels Sep 9, 2023
@AbdelhakGuettaf
Copy link
Contributor Author

My bad I didn't explain it well xD

@melloware
Copy link
Member

Can you paste your exact config here like..

<Calendar value={dates} onChange={(e) => setDates(e.value)} selectionMode="multiple" readOnlyInput />

So I can make mine the same?

@AbdelhakGuettaf
Copy link
Contributor Author

Sure, also here's an example
<Calendar value={date} selectionMode="multiple" onChange={(e) => setDate(e.value)} view="month" dateFormat="mm/yy" readOnlyInput />

melloware added a commit to melloware/primereact that referenced this issue Sep 9, 2023
@melloware melloware self-assigned this Sep 9, 2023
@melloware melloware added this to the 10.0.0 milestone Sep 9, 2023
@melloware
Copy link
Member

Perfect. PR submitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants