-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[Popper] Refactor to more commonly known react patterns #16613
Conversation
Details of bundle changes.Comparing: 6dc4ca3...97d2ca4
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
@@ -102,11 +113,10 @@ const Popper = React.forwardRef(function Popper(props, ref) { | |||
}, | |||
// We could have been using a custom modifier like react-popper is doing. | |||
// But it seems this is the best public API for this use case. | |||
onCreate: createChainedFunction(handlePopperUpdate, popperOptions.onCreate), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remember why it was added in #12085. Let's try without 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In RTL you create the placement with flipPlacement
so when you change placement in an RTL environment you only create a new PopperJS which wouldn't update the child prop. Since it's now immediately derived we no longer need this line.
/** | ||
* Flips placement if in <body dir="rtl" /> | ||
* @param {string} placement | ||
*/ | ||
function flipPlacement(placement) { | ||
const direction = (typeof window !== 'undefined' && document.body.getAttribute('dir')) || 'ltr'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's funny. I might have done it this way so we didn't have to bundle the default theme. As of today, we could probably use the useTheme from styles. But anyway, that's outside of the scope :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was thinking about this as well but would've required a test change. Wanted to be sure it's clear that this is only a refactor. Will follow-up.
Makes the controlled/uncontrolled + derived state pattern more obvious which results in one less
create
callback (wasteful popper re-creation) andflipPlacement
call.Videos are taken with
<Popper flip />
and we're about to scroll to a position where the placement needs to be flipped. When this happens we used to get this weirdcreate-update-create-update
chain that is now replaced by a continuous update.https://material-ui.com/components/popper/#scroll-playground
PR:
And we even got less shipped code. Hope that makes the implementation more reasonable.