Skip to content
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

Flex: Remove flex gap polyfill #43995

Merged
merged 5 commits into from Sep 12, 2022
Merged

Flex: Remove flex gap polyfill #43995

merged 5 commits into from Sep 12, 2022

Conversation

mirka
Copy link
Member

@mirka mirka commented Sep 8, 2022

What?

Removes the margin-based polyfill implementation of flex gap.

Why?

Flex gap is now at an acceptable adoption percentage.

Using the browser's native flex gap will make our code much simpler, and will avoid complications with child components having legacy style overrides involving margins.

Testing Instructions

  1. npm run storybook:dev and check that Flex, VStack, and HStack still work as expected when the gap and wrap props are set.
  2. npm run dev and smoke test the editor UI.

There is a good chance of whitespace regressions where there are margin overrides involved. The only one I could find was a regression in CustomSelectControl, which I fixed at the root by removing margin overrides in InputControl.

Screenshots

This cleanup also fixes a bug in InputControl when labelPosition='bottom':

Before After
InputControl with bottom label, before InputControl with bottom label, after

Otherwise, there shouldn't be any visual changes.

- Fixes regression in CustomSelectControl
- Fixes styles for labelPosition='bottom'
@mirka mirka added [Type] Bug An existing feature does not function as intended [Type] Code Quality Issues or PRs that relate to code quality [Package] Components /packages/components labels Sep 8, 2022
@mirka mirka self-assigned this Sep 8, 2022
@mirka mirka added this to In progress (owned) ⏳ in WordPress Components via automation Sep 8, 2022
@mirka mirka requested a review from ellatrix as a code owner September 8, 2022 19:07
@@ -138,7 +90,6 @@ export function useFlex( props: WordPressComponentProps< FlexProps, 'div' > ) {
isReverse,
justify,
wrap,
rtlWatchResult,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to rely on rtl.watch() anymore.

isFocused={ isFocused }
labelPosition={ labelPosition }
ref={ ref }
>
<LabelWrapper>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LabelWrapper was moved into Label itself, so it can be rendered only when the label is visible. Otherwise it stays in the DOM even when the label is visually hidden, and messes with the flex gap.

Comment on lines -36 to -50
const rootLabelPositionStyles = ( { labelPosition }: RootProps ) => {
switch ( labelPosition ) {
case 'top':
return css`
align-items: flex-start;
flex-direction: column;
`;
case 'bottom':
return css`
align-items: flex-start;
flex-direction: column-reverse;
`;
case 'edge':
return css`
justify-content: space-between;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was actually redundant because there was already a hook that added this logic and passed it as props to the Flex component:

function getUIFlexProps( labelPosition?: LabelPosition ) {
const props: { direction?: string; gap?: number; justify?: string } = {};
switch ( labelPosition ) {
case 'top':
props.direction = 'column';
props.gap = 0;
break;
case 'bottom':
props.direction = 'column-reverse';
props.gap = 0;
break;
case 'edge':
props.justify = 'space-between';
break;
}
return props;
}

Comment on lines -73 to -76
// Normalizes the margins from the <Flex /> (components/ui/flex/) container.
const containerMarginStyles = ( { hideLabel }: ContainerProps ) => {
return hideLabel ? css( { margin: '0 !important' } ) : null;
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Bye hacks

@jasmussen
Copy link
Contributor

Thanks for working on this, it's a deligt to see so much red code!

Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Such a needed refactor, getting rid of those margin hacks is a tangible improvement 👏

@mirka mirka merged commit 77b940d into trunk Sep 12, 2022
WordPress Components automation moved this from In progress (owned) ⏳ to Done 🎉 Sep 12, 2022
@mirka mirka deleted the native-flex-gap branch September 12, 2022 17:01
@github-actions github-actions bot added this to the Gutenberg 14.1 milestone Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Bug An existing feature does not function as intended [Type] Code Quality Issues or PRs that relate to code quality
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants