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] TimePicker minTime prop not allowing to pick the minimum time #14480

Open
Tracked by #13899
guna81 opened this issue Sep 4, 2024 · 5 comments
Open
Tracked by #13899
Labels
component: pickers This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it

Comments

@guna81
Copy link

guna81 commented Sep 4, 2024

Steps to reproduce

Link to live example: https://codesandbox.io/p/sandbox/mui-time-picker-mintime-issue-xlnqhf

Steps:

  1. Select the hour and minutes that specified in the minTime prop in the time picker

Current behavior

Couldn't able to select the time that is given in the minTime prop of the TimPicker.

Expected behavior

Should be able to select the time that is given in the minTime prop of the TimPicker.

Context

When I am trying to pick the minimum time of the picker that I mentioned in the minTime props, I am getting an error behavior.
eg. I am setting 6:00 as a minimum, but if I select 6:00 in the picker, I will get an error in the picker.

Your environment

npx @mui/envinfo
  System:
    OS: Ubuntu 22.04.4 LTS
  Binaries:
    node: v18.20.4
    npm: 10.7.0
  Browsers:
    Chrome: Version 125.0.6422.112 (Official Build) (64-bit)
  npmPackages:
    "@emotion/react": "latest",
    "@emotion/styled": "latest",
    "@mui/material": "latest",
    "@mui/x-date-pickers": "latest",
    "dayjs": "^1.11.10",
    "react": "latest",
    "react-dom": "latest"

Search keywords: time-picker, validation, minTime

@guna81 guna81 added bug 🐛 Something doesn't work status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 4, 2024
@github-actions github-actions bot added the component: pickers This is the name of the generic UI component, not the React module! label Sep 4, 2024
@noraleonte
Copy link
Contributor

Hey @guna81 👋

You should be able to pass a correct minTime to the picker if you also set the seconds to 0 (otherwise its value will always be the current exact date and time, with just the hour and minutes modified). Or you can just pass a string value specifying the time, just like here

mintime.mp4

Hope this helps 😄

@noraleonte noraleonte added status: waiting for author Issue with insufficient information and removed bug 🐛 Something doesn't work status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 4, 2024
@guna81
Copy link
Author

guna81 commented Sep 4, 2024

Hi @noraleonte,

I tried to set second as 0, now it seems fine. I didn't know this minTime also using current time for second value.
Thank you for you help.

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Sep 4, 2024
@michelengelen
Copy link
Member

@noraleonte should we add a recipe/example or callout to the docs for this? Feels like this might not be clear enough!

@michelengelen michelengelen changed the title TimePicker minTime prop not allowing to pick the minimum time [pickers] TimePicker minTime prop not allowing to pick the minimum time Sep 4, 2024
@michelengelen michelengelen added the status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it label Sep 4, 2024
@noraleonte
Copy link
Contributor

@michelengelen We could!

@guna81 Happy to hear it works! It's something specific to dayjs though. Calling dayjs() gives you the current time, and setting the hour and minutes works, but leaves the seconds unchanged 🙈 That's why depending on when you open the picker the minTime is actually 06:00:xx where the xx is taken from the current time

@michelengelen michelengelen added docs Improvements or additions to the documentation recipe and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 4, 2024
@LukasTy
Copy link
Member

LukasTy commented Sep 9, 2024

@noraleonte @michelengelen Are you sure that we are missing any documentation in this regard? 🤔
It's just the nature of how specific APIs behave.
In our validation example we already use the startOf function to avoid such issues. 🤔
What extra would you add? 🤷

@LukasTy LukasTy removed the recipe label Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pickers This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it
Projects
None yet
Development

No branches or pull requests

4 participants