Popover: refine position-to-placement conversion logic, add tests#44377
Merged
Popover: refine position-to-placement conversion logic, add tests#44377
Conversation
67 tasks
aaronrobertshaw
approved these changes
Sep 23, 2022
Contributor
aaronrobertshaw
left a comment
There was a problem hiding this comment.
Very nice @ciampo 👍
This is looking great. The changes certainly make it much easier to grok positionToPlacement.
There were two minor typos that I think we can fix up but other than that. LGTM!
✅ No build or typing errors
✅ Popover unit tests pass
cef0130 to
3113b35
Compare
ciampo
commented
Sep 23, 2022
Comment on lines
+5
to
+14
| ### Bug Fix | ||
|
|
||
| - `Popover`: fix limitShift logic by adding iframe offset correctly [#42950](https://github.com/WordPress/gutenberg/pull/42950)). | ||
| - `Popover`: refine position-to-placement conversion logic, add tests ([#44377](https://github.com/WordPress/gutenberg/pull/44377)). | ||
|
|
||
| ### Internal | ||
|
|
||
| - `Mobile` updated to ignore `react/exhaustive-deps` eslint rule ([#44207](https://github.com/WordPress/gutenberg/pull/44207)). | ||
| - `Popover`: refactor unit tests to TypeScript and modern RTL assertions ([#44373](https://github.com/WordPress/gutenberg/pull/44373)). | ||
|
|
Contributor
Author
There was a problem hiding this comment.
I also moved a few changelog entries from recent PRs to the Unreleased section, since they had been wrongly added under the 21.1.0 release
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #44339
Requires #44373 to be merged first
What?
This PR improves the logic to convert values for the
Popover(legacy)positionprop, to the newly introducedplacementprop. Until now, the conversion was done via thepositionToPlacementutility function, which doesn't cover all possible cases and has a quite complex logic.The newly proposed logic is based on the investigation carried out in #44339, so please check out that issue to see the reasoning behind the code changes from this PR.
This is the first step of a plan that aims at:
positionusages toplacementpositionprop and scheduling it for deletionpositionpropWhy?
Almost all consumers of
Popoverstill used thepositionprop, and therefore we need to make sure that the conversion frompositiontoplacementis implemented correctly.How?
positionis converted to the expectedplacementvalue (following the expected specs in Popover: assess allpositiontoplacementconversions, add unit tests #44339)positionToPlacementwith a simpler map of position-to-placement conversionsTesting Instructions
Apart from code readability, the differences between the converted
placementvalues in this PR vstrunkare:positionplacement(this PR)placement(trunk)'middle''bottom'*undefined'middle center''bottom'*'center''middle left bottom''left-end''left''middle left top''left-start''left''middle center left''bottom'*'center''middle center right''bottom'*'center''middle center bottom''bottom'*'center''middle center top''bottom'*'center''middle right bottom''right-end''right''middle right top''right-start''right''bottom left left''bottom-end''bottom-start''bottom center left''bottom''bottom-start''bottom center right''bottom''bottom-end''top left left''top-end''top-start''top center left''top''top-start''top center right''top''top-end'*:
bottomplacements marked with an asterisks are fallback values used whenpositionhasmiddle centervalues, since there's not equivalentplacementvalueNone of the positions listed in the table above is currently used in Gutenberg, and therefore:
Popovercomponent in a very significant way.