Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

Bug whit Material UI date picker #281

Open
SimonJiTa opened this issue Oct 6, 2022 · 4 comments
Open

Bug whit Material UI date picker #281

SimonJiTa opened this issue Oct 6, 2022 · 4 comments

Comments

@SimonJiTa
Copy link

image

@SimonJiTa
Copy link
Author

image

@PrimaMateria
Copy link
Collaborator

PrimaMateria commented Oct 6, 2022

Probably you need in DialogProps set container property and pass there a reference to some element that is rendered in your web component. This happens because all the MUI styles are added under the shadowRoot where the webcomponent lives. But MUI by default injects Modals to the parent document. So with the container prop you instruct MUI to inject the Modal to correct place.

@SimonJiTa
Copy link
Author

Probably you need in DialogProps set container property and pass there a reference to some element that is rendered in your web component. This happens because all the MUI styles are added under the shadowRoot where the webcomponent lives. But MUI by default injects Modals to the parent document. So with the container prop you instruct MUI to inject the Modal to correct place.

How i do that?
image

@PrimaMateria
Copy link
Collaborator

Hard to tell why exactly this doesn't work for you.
I don't use RootRef just a normal Box and I pass ref function instead of directly ref. And this ref I store in state, so I have a rerender when it becomes defined.

(Pseudocode with TS)

const [rootContainer, setRootContainer] = useState<HTMLDivElement | undefined>()
return (
  <>
    <Box ref={(ref) => setRootContainer((ref as HTMLDivElement) || undefined)}>
      /* The dialog must be inserted here */
    </Box>
    <Dialog container={rootContainer} />
  </>
);

Additionally, I passed the rootContainer to a React context, so then later anywhere down the component hierarchy tree I can access it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants