Skip to content

fix handling of flex shorthand #96

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

Closed
wants to merge 1 commit into from
Closed

fix handling of flex shorthand #96

wants to merge 1 commit into from

Conversation

quantizor
Copy link

@quantizor quantizor commented Oct 18, 2018

  1. the flex spec doesn't allow values to be in reverse order
  2. the default state of flexBasis should always be "auto"

Fixes styled-components/styled-components#1855

1. the flex spec doesn't allow values to be in reverse order
2. the default state of flexBasis should always be "auto"
@quantizor quantizor requested a review from jacobp100 October 18, 2018 00:57
@jacobp100
Copy link
Contributor

jacobp100 commented Oct 18, 2018

Thanks for the PR! I think it is currently spec compliant according to https://www.w3.org/TR/css-flexbox-1/#flex-property

The syntax is none | [ <‘flex-grow’> <‘flex-shrink’>? || <‘flex-basis’> ]

The double bar means any order is permitted.

Then for the flex basis,

<‘flex-basis’>
...
When omitted from the flex shorthand, its specified value is 0.

Feel free to correct me if I'm wrong though!

Didn't notice RN supports flexBasis: 'auto' though. We could probably clean up the return value of flex: none and flex: auto

@quantizor
Copy link
Author

quantizor commented Oct 18, 2018 via email

@jacobp100
Copy link
Contributor

Where abouts were you reading the the MDN article?

<'flex-basis'>
Defines the flex-basis of the flex item. Any value valid for width and height properties are accepted. A preferred size of 0 must have a unit to avoid being interpreted as a flexibility. Defaults to 0 when omitted.

link

@quantizor
Copy link
Author

Hmm ok I do see where you said that but the spec is at odds with itself. See this:

initial
This is the default value. The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting "flex: 0 1 auto".

That implies the default should be auto unless otherwise changed. And I do believe that's what users would expect too.

@jacobp100
Copy link
Contributor

So the initial value for flex-basis is auto.

When you use the flex shorthand, it always resets it, even if you don’t define it in the shorthand. The value it uses when you don’t define it is 0.

@quantizor
Copy link
Author

Hmm ok. Well I'll close this and feel free to poach any of my changes for setting 'auto'

@quantizor quantizor closed this Oct 18, 2018
@jacobp100
Copy link
Contributor

Done! #97

@quantizor quantizor deleted the fix-flex branch October 18, 2018 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants