-
Notifications
You must be signed in to change notification settings - Fork 4.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
Fix HStack and VStack alignment prop #47914
Changes from all commits
754d5b7
aa32c1e
172ee45
08722d9
836e38d
986f6c1
9704e62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import { isValueDefined } from '../utils/values'; | |
|
||
const H_ALIGNMENTS: Alignments = { | ||
bottom: { align: 'flex-end', justify: 'center' }, | ||
bottomLeft: { align: 'flex-start', justify: 'flex-end' }, | ||
bottomLeft: { align: 'flex-end', justify: 'flex-start' }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was buggy (inverted values) |
||
bottomRight: { align: 'flex-end', justify: 'flex-end' }, | ||
center: { align: 'center', justify: 'center' }, | ||
edge: { align: 'center', justify: 'space-between' }, | ||
|
@@ -25,13 +25,13 @@ const H_ALIGNMENTS: Alignments = { | |
|
||
const V_ALIGNMENTS: Alignments = { | ||
bottom: { justify: 'flex-end', align: 'center' }, | ||
bottomLeft: { justify: 'flex-start', align: 'flex-end' }, | ||
bottomLeft: { justify: 'flex-end', align: 'flex-start' }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was buggy (inverted values) |
||
bottomRight: { justify: 'flex-end', align: 'flex-end' }, | ||
center: { justify: 'center', align: 'center' }, | ||
edge: { justify: 'space-between', align: 'center' }, | ||
left: { justify: 'center', align: 'flex-start' }, | ||
right: { justify: 'center', align: 'flex-end' }, | ||
stretch: { justify: 'stretch' }, | ||
stretch: { align: 'stretch' }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was buggy too. |
||
top: { justify: 'flex-start', align: 'center' }, | ||
topLeft: { justify: 'flex-start', align: 'flex-start' }, | ||
topRight: { justify: 'flex-start', align: 'flex-end' }, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,29 @@ import type { ComponentMeta, ComponentStory } from '@storybook/react'; | |
import { View } from '../../view'; | ||
import { VStack } from '..'; | ||
|
||
const ALIGNMENTS = { | ||
top: 'top', | ||
topLeft: 'topLeft', | ||
topRight: 'topRight', | ||
left: 'left', | ||
center: 'center', | ||
right: 'right', | ||
bottom: 'bottom', | ||
bottomLeft: 'bottomLeft', | ||
bottomRight: 'bottomRight', | ||
edge: 'edge', | ||
stretch: 'stretch', | ||
}; | ||
|
||
const meta: ComponentMeta< typeof VStack > = { | ||
component: VStack, | ||
title: 'Components (Experimental)/VStack', | ||
argTypes: { | ||
alignment: { control: { type: 'text' } }, | ||
alignment: { | ||
control: { type: 'select' }, | ||
options: Object.keys( ALIGNMENTS ), | ||
mapping: ALIGNMENTS, | ||
}, | ||
as: { control: { type: 'text' } }, | ||
direction: { control: { type: 'text' } }, | ||
justify: { control: { type: 'text' } }, | ||
|
@@ -28,12 +46,15 @@ export default meta; | |
|
||
const Template: ComponentStory< typeof VStack > = ( props ) => { | ||
return ( | ||
<VStack { ...props }> | ||
<View>One</View> | ||
<View>Two</View> | ||
<View>Three</View> | ||
<View>Four</View> | ||
<View>Five</View> | ||
<VStack | ||
{ ...props } | ||
style={ { background: '#eee', minHeight: '200px' } } | ||
> | ||
{ [ 'One', 'Two', 'Three', 'Four', 'Five' ].map( ( text ) => ( | ||
<View key={ text } style={ { background: '#b9f9ff' } }> | ||
{ text } | ||
</View> | ||
) ) } | ||
Comment on lines
+49
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for this improvement! |
||
</VStack> | ||
); | ||
}; | ||
|
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 change definitely makes sense, but I'm not sure if the new behaviour of
HStack
is 100% correct either.I was taking a look at
HStack
whendirection="column"
, and I was playing around with thealignment
prop:trunk
, in this case changing thealignment
prop doesn't seem to make any differencesalignment="edge"
case - the items appear to be centered, but I believed they should be stretched (especially given the description of theedge
value: "Aligns content to the edges of the container.")Looks like this change would fix it
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.
If I remember properly, I based the behavior of "edge" here by comparing the behavior of "h" in HStack and applied the same behavior but in the other axis.
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.
As much as I don't love the arbitrariness of this
align
prop, I agree with Riad that this newedge
behavior for VStack is correct/consistent within the existing logic of the system.In this system, I understand
stretch
to apply only to the cross axis, andedge
to apply only to the main axis.How about we tweak the description to make that clearer?
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.
Thank you both.
Given that the separation between breaking change and bug fix can be blurry here, I agree with Lena's proposed solution