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

MobileDateTimePicker API: Enter date and time with the keyboard #11035

Closed
lukagrbec opened this issue Nov 14, 2023 · 3 comments
Closed

MobileDateTimePicker API: Enter date and time with the keyboard #11035

lukagrbec opened this issue Nov 14, 2023 · 3 comments
Labels
component: pickers This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists

Comments

@lukagrbec
Copy link

lukagrbec commented Nov 14, 2023

Summary 💡

I'm working with MUI's MobileDateTimePicker and encountering a couple of issues with its functionality. I want users to be able to manually enter a date and time into the TextField. However, the picker dialog currently opens whenever the TextField gains focus, which is not the desired behavior. I want the date and time picker to only appear when the user clicks the calendar/clock icon at the end of the TextField.

Here's a conceptual breakdown of the desired behaviors:

The user clicks on the TextField and is able to type in a date and time directly using the keyboard.
The picker dialog (calendar and clock form) should only open when the user clicks the icon on the right side of the text form, not when the TextField itself is clicked or focused.
Currently, I am using the standard MobileDateTimePicker implementation, but it seems to lack an option to differentiate between focusing the TextField for keyboard input and clicking the icon to open the picker dialog.

This is my code:

<Controller
      name="start"
      control={control}
      render={({ field: { onChange, value, ...fieldProps } }) => {
        const [open, setOpen] = useState(false);

        const handleIconClick = (event) => {
          event.stopPropagation();
          setOpen(!open); 
        };

        const handleTextFieldFocus = (event) => {
          event.stopPropagation();
        };

        return (
          <MobileDateTimePicker
            disabled={user?.enterprise}
            open={open}
            onOpen={() => setOpen(true)}
            onClose={() => setOpen(false)}
            value={value ? new Date(value) : null}
            onChange={(newValue) => {
              onChange(newValue ? fTimestamp(newValue) : newValue);
            }}
            label="Začetek"
            format="dd/MM/yyyy HH:mm"
            ampm={false}
            slots={{
              OpenPickerIcon: () => <></>, 
            }}
            slotProps={{
              textField: {
                inputRef: fieldProps.ref,
                onFocus: handleTextFieldFocus,
                fullWidth: true,
                InputProps: {
                  ...fieldProps.InputProps,
                  endAdornment: (
                    <IconButton onClick={handleIconClick} size="large">
                      <Iconify icon='solar:calendar-mark-bold-duotone' />
                    </IconButton>
                  ),
                },
              },
            }}
          />
        );
      }}
    />

Examples 🌈

Desired Behavior: I want to enable users to input the date and time manually through the keyboard when they click on the TextField. The picker dialog should only open when the user clicks on the calendar/clock icon adjacent to the TextField:

Screenshot 2023-11-14 174816

Motivation 🔦

Currently, I am using the standard MobileDateTimePicker implementation, but it seems to lack an option to differentiate between focusing the TextField for keyboard input and clicking the icon to open the picker dialog.

Search keywords: MobileDateTimePicker, keyboard input

@lukagrbec lukagrbec added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 14, 2023
@alexfauquette
Copy link
Member

That's because you're using the <MobileDateTimePicker />. The <DesktopDateTimePicker /> has the behavior you're describing. And the <DateTimePicker /> switch between them depending on the cursor precision of your user device.

@alexfauquette alexfauquette added support: question Community support but can be turned into an improvement component: pickers This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 27, 2023
@flaviendelangle
Copy link
Member

The only problem here is that the DesktopDateTimePicker will open in a popper instead of a modal and with a desktop layout.
Right now you can't open the mobile view in a modal using an adornment to keep the field editing.

I think it duplicates #7869

@flaviendelangle flaviendelangle added duplicate This issue or pull request already exists and removed support: question Community support but can be turned into an improvement labels Nov 29, 2024
Copy link

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@lukagrbec How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

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! duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants