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

[pickers] Modify adapter.isValid method to accept TDate | null instead of any #10971

Merged
merged 7 commits into from
Nov 10, 2023

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Nov 9, 2023

Fixes #10970

Changelog

Breaking changes

  • The adapter.isValid method used to accept any type of value and tried to parse them before checking their validity.
    The method has been simplified and now only accepts an already-parsed date or null.
    Which is the same type as the one accepted by the components value prop.

     const adapterDayjs = new AdapterDayjs();
     const adapterLuxon = new AdapterLuxon();
     const adapterDateFns = new AdapterDateFns();
     const adapterMoment = new AdatperMoment();
    
     // Supported formats
     const isValid = adapterDayjs.isValid(null); // Same for the other adapters
     const isValid = adapterLuxon.isValid(DateTime.now());
     const isValid = adapterMoment.isValid(moment());
     const isValid = adapterDateFns.isValid(new Date());
    
     // Non-supported formats (JS Date)
    - const isValid = adapterDayjs.isValid(new Date('2022-04-17'));
    + const isValid = adapterDayjs.isValid(dayjs('2022-04-17'));
    
    - const isValid = adapterLuxon.isValid(new Date('2022-04-17'));
    + const isValid = adapterLuxon.isValid(DateTime.fromISO('2022-04-17'));
    
    - const isValid = adapterMoment.isValid(new Date('2022-04-17'));
    + const isValid = adapterMoment.isValid(moment('2022-04-17'));
    
     // Non-supported formats (string)
    - const isValid = adapterDayjs.isValid('2022-04-17');
    + const isValid = adapterDayjs.isValid(dayjs('2022-04-17'));
    
    - const isValid = adapterLuxon.isValid('2022-04-17');
    + const isValid = adapterLuxon.isValid(DateTime.fromISO('2022-04-17'));
    
    - const isValid = adapterMoment.isValid('2022-04-17');
    + const isValid = adapterMoment.isValid(moment('2022-04-17'));
    
    - const isValid = adapterDateFns.isValid('2022-04-17');
    + const isValid = adapterDateFns.isValid(new Date('2022-04-17'));

@flaviendelangle flaviendelangle added breaking change component: pickers This is the name of the generic UI component, not the React module! labels Nov 9, 2023
@flaviendelangle flaviendelangle self-assigned this Nov 9, 2023
@mui-bot
Copy link

mui-bot commented Nov 9, 2023

@flaviendelangle flaviendelangle changed the title Is valid typing [pickers] Modify adapter.isValid method to accept TDate | null instead of any Nov 9, 2023
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 10, 2023
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 10, 2023
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 10, 2023
@flaviendelangle flaviendelangle merged commit a578fc9 into mui:next Nov 10, 2023
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: pickers This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pickers] v7: Modify adapter.isValid method to accept TDate | null instead of any
3 participants