Skip to content

Commit

Permalink
fix: 🐛 [Popper] Mismatch between MUIPopper type: React 17 vs 18
Browse files Browse the repository at this point in the history
  • Loading branch information
luciob committed Dec 5, 2022
1 parent 8ff5f23 commit ec58a78
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/components/Select/components/Popper/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useMemo } from "react";
import React, { CSSProperties, FC, useMemo } from "react";
import { Popper as MUIPopper, PopperProps as MUIPopperProps } from "@mui/material";

interface ISelectPopper {
Expand All @@ -12,10 +12,28 @@ const SelectPopper: FC<ISelectPopper> = ({ forwarded, popperWidth }) => {
const width = useMemo(() => {
const anchorElRef = anchorEl as any;
const anchorElWidth = anchorElRef ? anchorElRef.clientWidth : null;

return !!popperWidth && popperWidth > anchorElWidth ? popperWidth : anchorElWidth;
}, [popperWidth, anchorEl]);

return <MUIPopper {...forwarded} placement="bottom-start" style={{ width }} />;
const style = useMemo(
(): CSSProperties => ({
width,
}),
[width]
);

return (
<MUIPopper
{...forwarded}
placement="bottom-start"
style={style}
// React 17.x vs React 18.x mismatch
// See: https://github.com/mui/material-ui/issues/35287
onResize={undefined}
onResizeCapture={undefined}
/>
);
};

export default SelectPopper;

0 comments on commit ec58a78

Please sign in to comment.