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] DateCalendar issue with customized Dialog TransitionComponent #10130

Closed
2 tasks done
laichak opened this issue Aug 24, 2023 · 3 comments
Closed
2 tasks done
Labels
component: pickers This is the name of the generic UI component, not the React module!

Comments

@laichak
Copy link

laichak commented Aug 24, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

DateCalendar issue with customized Dialog TransitionComponent.
It seems that using custom TransitionComponent in Dialog's animation is conflicting DateCalendar's animation.

Test code below (updated 8/25/2023):

import * as React from "react";
import Slide from "@mui/material/Slide";
import Button from "@mui/material/Button";
import Dialog from "@mui/material/Dialog";
import DialogContent from "@mui/material/DialogContent";
import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFns";
import { DateCalendar } from "@mui/x-date-pickers/DateCalendar";
import { TransitionProps } from "@mui/material/transitions";
import { useTheme } from '@mui/material/styles';


const Transition = React.forwardRef<
  HTMLDivElement,
  TransitionProps & { children: any }
>(({ children, ...other }, ref) => (
  <Slide ref={ref} {...other} direction="up">
    {children}
  </Slide>
));

export default function BasicDateCalendar() {
  const theme = useTheme();

  const [dateSelected, setDateSelected] = React.useState();
  const [open_input_view, setInputViewOpen] = React.useState(false);

  const initialRender = React.useRef(true);

  React.useEffect(() => {
      if (initialRender.current) {
          initialRender.current = false;

          setTimeout(() => {
            React.startTransition(() => {
              setDateSelected(new Date());
              setInputViewOpen(true);
            });
          }, theme.transitions.duration.complex); 
      }
    }, [theme.transitions.duration.complex]);

  return (
    <React.Fragment>
      <Button onClick={() => setInputViewOpen(true)}>Open dialog</Button>
      <Dialog
        maxWidth="md"
        fullWidth
        open={open_input_view}
        onClose={() => setInputViewOpen(false)}
        TransitionComponent={Transition}
        keepMounted
      >
        <DialogContent>
          <LocalizationProvider dateAdapter={AdapterDateFns}>
            <DateCalendar
              disableFuture
              value={dateSelected}
              onChange={(newDate) => setDateSelected(newDate)}
              views={["day"]}
            />
          </LocalizationProvider>
        </DialogContent>
      </Dialog>
    </React.Fragment>
  );
}

Current behavior 😯

MUI: A component is changing the uncontrolled value state of DateCalendar to be controlled.
Elements should not switch from uncontrolled to controlled (or vice versa).
Decide between using a controlled or uncontrolled DateCalendar element for the lifetime of the component.
The nature of the state is determined during the first render. It's considered controlled if the value is not undefined.
More info: https://fb.me/react-controlled-components

Expected behavior 🤔

No response

Context 🔦

No response

Your environment 🌎

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Order ID or Support key 💳 (optional)

No response

@laichak laichak added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Aug 24, 2023
@LukasTy
Copy link
Member

LukasTy commented Aug 25, 2023

I've tried reproducing your use case in codesandbox.
Could you clarify where do you seem to have problems, because I was not able to see the error you are talking about. 🤷

@LukasTy LukasTy added status: waiting for author Issue with insufficient information 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 Aug 25, 2023
@LukasTy LukasTy changed the title DateCalendar issue with customized Dialog TransitionComponent [pickers] DateCalendar issue with customized Dialog TransitionComponent Aug 25, 2023
@laichak
Copy link
Author

laichak commented Aug 25, 2023

Thank you for your response. I have edited the code in the first post.

@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label Aug 25, 2023
@LukasTy
Copy link
Member

LukasTy commented Aug 28, 2023

Thank you for providing the updated code.
In your new example, there is a tiny error in the code.
You have this interesting behavior with a useEffect and timeout, which sets the open state and the current date value.

  • Consider the need for this useEffect altogether as it seems that simply having the current date value set in the initial state and open on the dialog is enough. 🤔
  • If the first option does not cover certain use cases and is still needed, please update the initial state of dateSelected to the correct empty value to signal that you are going to control the value, rather than providing nothing on the initial render.
- const [dateSelected, setDateSelected] = React.useState();
+ const [dateSelected, setDateSelected] = React.useState(null);

@LukasTy LukasTy closed this as completed Aug 28, 2023
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!
Projects
None yet
Development

No branches or pull requests

2 participants