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

[DateRangePicker] Using SingleInputDateRangeField with readOnly=true causes unexpected UX #12576

Closed
TimESQuit opened this issue Mar 26, 2024 · 8 comments · Fixed by #12593
Closed
Assignees
Labels
component: DateRangePicker The React component. component: pickers This is the name of the generic UI component, not the React module! support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/

Comments

@TimESQuit
Copy link

TimESQuit commented Mar 26, 2024

Steps to reproduce

Minimal example of DateRangePicker using SingleInputDateRangeField and readOnly: true:
https://codesandbox.io/p/devbox/loving-tree-lphyk2?file=%2Fsrc%2FDemo.tsx

Steps:

  1. Click somewhere in the starting date area of the field.
  2. Notice that the ending date area of the field is now highlighted.
  3. Click a date in the calendar.
  4. Notice the single selected date displays in the field as (and acts in the calendar(s) as) the end date.

Current behavior

Using DateRangePicker with SingleInputDateRangeField and readOnly: true forces the the first date selected to be the end date of the range, with no apparent way to easily override/modify this behavior. Note: this only seems to happen with readOnly: true.

Expected behavior

Using DateRangePicker with SingleInputDateRangeField and readOnly: true behaves the same as when readOnly: false and selects the start date first.

Context

Using @mui/x-date-pickers-pro@^5, we used the DateRangePicker with renderInput to create a single element to display both start and end dates. For our UX, we found it more trouble to allow a user to edit the field directly (not from the UI calendar popups), so disabled the field. With the move to SingleInputDateRangeField and removal of renderInput in v6 and v7, there doesn't seem to be a great way to replicate a single basic read-only field with DateRangePicker.

Your environment

npx @mui/envinfo
 # Command run inside codesandbox terminal

 System:
    OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
  Binaries:
    Node: 20.9.0 - /usr/local/bin/node
    npm: 9.8.1 - /usr/local/bin/npm
    pnpm: 8.10.2 - /usr/local/share/npm-global/bin/pnpm
  Browsers:
    Chrome: Not Found
  npmPackages:
    @emotion/react: latest => 11.11.4 
    @emotion/styled: latest => 11.11.0 
    @mui/material: latest => 5.15.14 
    @mui/x-date-pickers: latest => 7.0.0 
    @mui/x-date-pickers-pro: latest => 7.0.0 
    @types/react: latest => 18.2.72 
    react: latest => 18.2.0 
    react-dom: latest => 18.2.0 
    typescript: latest => 5.4.3 

Search keywords: readOnly single input SingleInputDateRangeField DateRangePicker
Order ID: 85560

@TimESQuit TimESQuit added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 26, 2024
@zannager zannager added component: pickers This is the name of the generic UI component, not the React module! support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/ labels Mar 27, 2024
@michelengelen
Copy link
Member

Hey @TimESQuit your Codesandbox is unavailable. You might have to make it public.
Could you do that and comment here when it is available so we can have a look? Thanks!

@michelengelen michelengelen added status: waiting for author Issue with insufficient information component: DateRangePicker The React component. and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 27, 2024
@michelengelen michelengelen changed the title [DateRangePicker] - using SingleInputDateRangeField with readOnly=true causes unexpected UX [p\ickers][DateRangePicker] using SingleInputDateRangeField with readOnly=true causes unexpected UX Mar 27, 2024
@TimESQuit
Copy link
Author

@michelengelen
Sorry about that - should be public now

@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 Mar 27, 2024
@LukasTy LukasTy self-assigned this Mar 28, 2024
@LukasTy LukasTy changed the title [p\ickers][DateRangePicker] using SingleInputDateRangeField with readOnly=true causes unexpected UX [DateRangePicker] using SingleInputDateRangeField with readOnly=true causes unexpected UX Mar 28, 2024
@LukasTy LukasTy removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 28, 2024
@LukasTy LukasTy changed the title [DateRangePicker] using SingleInputDateRangeField with readOnly=true causes unexpected UX [DateRangePicker] Using SingleInputDateRangeField with readOnly=true causes unexpected UX Mar 28, 2024
@LukasTy
Copy link
Member

LukasTy commented Mar 28, 2024

@TimESQuit The problem has been identified and a possible fix PR raised.
I've also noticed that the focused flag has not been properly added to the SingleInputDateRangeField—it does not receive focus style when focused, only when Picker is opened.

P.S. If you would try adding an enableAccessibleFieldDOMStructure prop—the UX behavior would work as expected even on v7.0.0.
Feel free to try these new Field components if you have the option. 😉

Copy link

⚠️ This issue has been closed.
If you have a similar problem, please open a new issue and provide details about your specific problem.
If you can provide additional information related to this topic that could help future readers, please feel free to leave a comment.

How did we do @TimESQuit?
Your experience with our support team matters to us. If you have a moment, please share your thoughts through our brief survey.

@TimESQuit
Copy link
Author

I can't fully tell, but does the code fix just apply to v7? We recently migrated to v6 and are not looking to migrate to v7 right away so would really need this change in v6 as well. Thanks!

@LukasTy
Copy link
Member

LukasTy commented Mar 29, 2024

I can't fully tell, but does the code fix just apply to v7? We recently migrated to v6 and are not looking to migrate to v7 right away so would really need this change in v6 as well. Thanks!

It has been fixed only on v7 for now.
We'll backport the fix to v6 as well. 👌

@LukasTy
Copy link
Member

LukasTy commented Mar 29, 2024

@TimESQuit Would it be fine if we released this fix on v6 in around a week (~next Thursday)?

@TimESQuit
Copy link
Author

Around next Thursday works. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: DateRangePicker The React component. component: pickers This is the name of the generic UI component, not the React module! support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants