Skip to content

Commit

Permalink
Merge pull request #4498 from shyk001/main
Browse files Browse the repository at this point in the history
Fix - Removed defaultProps from Function Components for React 18.3.
  • Loading branch information
martijnrusschen authored Feb 2, 2024
2 parents 7344120 + 8839334 commit 60609a7
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/with_floating.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,29 @@ export const popperPlacementPositions = [

export default function withFloating(Component) {
const WithFloating = (props) => {
const alt_props = {
...props,
popperModifiers: props.popperModifiers || [],
popperProps: props.popperProps || {},
hidePopper:
typeof props.hidePopper === "boolean" ? props.hidePopper : true,
};
const arrowRef = React.useRef();
const floatingProps = useFloating({
open: !props.hidePopper,
open: !alt_props.hidePopper,
whileElementsMounted: autoUpdate,
placement: props.popperPlacement,
placement: alt_props.popperPlacement,
middleware: [
flip({ padding: 15 }),
offset(10),
arrow({ element: arrowRef }),
...props.popperModifiers,
...alt_props.popperModifiers,
],
...props.popperProps,
...alt_props.popperProps,
});

return (
<Component {...props} popperProps={{ ...floatingProps, arrowRef }} />
<Component {...alt_props} popperProps={{ ...floatingProps, arrowRef }} />
);
};

Expand All @@ -51,11 +58,5 @@ export default function withFloating(Component) {
hidePopper: PropTypes.bool,
};

WithFloating.defaultProps = {
popperModifiers: [],
popperProps: {},
hidePopper: true,
};

return WithFloating;
}

0 comments on commit 60609a7

Please sign in to comment.