-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[pickers] text field loses focus on third click #17223
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
Comments
This is due to the way the focus-management is built around the pickers. May I ask what your intentions are? What's the preferred way for you implementation to look like/work? |
Hi @michelengelen ... Thank you for the reply. I'm looking to make it open on click in the input and keep it editable while the picker is open. Ideally, a timepicker with autocomplete would be awesome. Similar to google calendar. It's more easier and intuitive. A prop Screen.Recording.2025-04-02.at.10.18.07.AM.mov |
ah, i get it ... for a first iteration you can do this: import * as React from 'react';
import { DemoContainer } from '@mui/x-date-pickers/internals/demo';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { TimePicker } from '@mui/x-date-pickers/TimePicker';
export default function BasicTimePicker() {
const [open, setOpen] = React.useState(false);
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['TimePicker']}>
<TimePicker
open={open}
label="Basic time picker"
autoFocus={false}
slotProps={{ textField: { onClick: () => setOpen(true) } }}
/>
</DemoContainer>
</LocalizationProvider>
);
} We do not have a way of mimickng autocomplete though. |
I have something like that in the sandbox link I provided. It's not working. Having the problem I mentioned. An Autocomplete picker similar to google calendar would be awesome.I don't wanna create it myself because then I'll have to maintain it. Are there any plans for this? |
It works for me ... the important part is
No, not at the moment I am afraid. |
Thanks @michelengelen ... It seems to work for opening. How to handle closing of picker? ... I tried Screen.Recording.2025-04-03.at.10.38.14.AM.mov |
Well, you can always pass this: onAccept={() => setOpen(false)} But the overlay will stay open until you actually accept. You can have a workaround that handles the closing on click away by listening for click events on the components (using refs) and closing if the click target is not on the overlay or textfield. |
Steps to reproduce
Steps:
Screen.Recording.2025-04-01.at.5.10.49.PM.mov
Current behavior
The field loses focus even though it has focus
Expected behavior
The field should not lose focus on any interaction with it.
Context
No response
Your environment
npx @mui/envinfo
Search keywords: timepicker, textfield, focus, click
The text was updated successfully, but these errors were encountered: