-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
- Fixes regression in CustomSelectControl - Fixes styles for labelPosition='bottom'
@@ -138,7 +90,6 @@ export function useFlex( props: WordPressComponentProps< FlexProps, 'div' > ) { | |||
isReverse, | |||
justify, | |||
wrap, | |||
rtlWatchResult, |
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.
We don't need to rely on rtl.watch()
anymore.
isFocused={ isFocused } | ||
labelPosition={ labelPosition } | ||
ref={ ref } | ||
> | ||
<LabelWrapper> |
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.
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.
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; |
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.
This was actually redundant because there was already a hook that added this logic and passed it as props to the Flex component:
gutenberg/packages/components/src/input-control/input-base.tsx
Lines 35 to 52 in 6987dd8
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; | |
} |
// Normalizes the margins from the <Flex /> (components/ui/flex/) container. | ||
const containerMarginStyles = ( { hideLabel }: ContainerProps ) => { | ||
return hideLabel ? css( { margin: '0 !important' } ) : null; | ||
}; |
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.
🧹 Bye hacks
Thanks for working on this, it's a deligt to see so much red code! |
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.
🚀
Such a needed refactor, getting rid of those margin hacks is a tangible improvement 👏
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
npm run storybook:dev
and check that Flex, VStack, and HStack still work as expected when thegap
andwrap
props are set.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'
:Otherwise, there shouldn't be any visual changes.