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:about disabled logic #5581

Closed
kl-nevermore opened this issue Dec 12, 2023 · 3 comments · Fixed by #5602
Closed

Calendar:about disabled logic #5581

kl-nevermore opened this issue Dec 12, 2023 · 3 comments · Fixed by #5602
Assignees
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Milestone

Comments

@kl-nevermore
Copy link
Contributor

Describe the bug

The calendar only supports disabledDates and disabledDays

But year and month have attributes data-p-disabled, this value never changed by props.disabledDates or props.disabledDays

monthPickerValues data-p-disabled always true

https://github.com/primefaces/primereact/blob/master/components/lib/calendar/Calendar.js#L3654

yearPickerValues data-p-disabled always false

https://github.com/primefaces/primereact/blob/master/components/lib/calendar/Calendar.js#L3697

is this an issue or a feature? if it will be fixed, Is it a good choice to accept a new prop like example

disabledDate?: (year: number, month: number, day: number) => boolean;

<Calendar
    value={date}
    onChange={(e) => setDate(e.value)}
    disabledDate={(y, m, d) => {
        return y > 1999 && m > 1;
    }}
/>

Reproducer

https://codesandbox.io/p/sandbox/primereact-test-forked-6y4y7n?file=%2Fsrc%2Findex.js

PrimeReact version

latest

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

No response

@kl-nevermore kl-nevermore added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Dec 12, 2023
@melloware melloware added Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Dec 12, 2023
@kl-nevermore
Copy link
Contributor Author

kl-nevermore commented Dec 13, 2023

@melloware
Now the disabling logic of the three panels has no correlation

Do you think this logic is as expected?

  • If any date can be selected in currentYear or currentMonth, then the year and month should also be selectable
  • If any month can be selected, then the year should also be selectable
  • if all date disabled ,then the year and month should also be disabled
  • if all month disabled ,then the year and date should also be disabled
  • if all year disabled ,then the mouth and date should also be disabled

@melloware
Copy link
Member

This is tricky because now you have to check the disabledDates and compare each month and or year to see if it encompasses the entire disabled Dates right? For example if disabled Dates had every date in March except March 15 then March should be active but if it also had March 15 then the month of March would be disabled?

@kl-nevermore
Copy link
Contributor Author

yes

what I thought was when I passed on the new props,the disabledDates and disabledDays will be ignored

If it's like what you said, then need to combine the logic

when changed year picker, will be checking all the days, there may be some performance issues, but I think it's okay. only 3000+ times

I will test it under slow 4x and 6x and compare it with the current situation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants