-
Notifications
You must be signed in to change notification settings - Fork 772
fix(flexbox): scan flex-direction in css stylesheet #365
Conversation
@crisbeto - can you review ? Thx. |
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.
LGTM, a few nits.
src/lib/flexbox/api/base.ts
Outdated
@@ -146,7 +152,7 @@ export abstract class BaseFxDirective implements OnDestroy, OnChanges { | |||
try { | |||
if (element) { | |||
let immediateValue = getDom().getStyle(element, styleName); | |||
value = immediateValue || getDom().getComputedStyle(element).display; | |||
value = immediateValue || getDom().getComputedStyle(element)[styleName]; |
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.
Instead of getDom().getComputedStyle(element)[styleName]
you can use getDom().getComputedStyle(element).getPropertyValue(styleName)
.
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.
IYO, which is preferred/better ?
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.
I believe getPropertyValue
guarantees that the style will be recalculated.
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.
Good to know. Thx.
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 I know, in iOS 9 the getPropertyValue
returns null
instead of empty string as in browsers on other OS. Not sure how much people still use the iOS 9 so my comment is just for info.
src/lib/flexbox/api/flex.ts
Outdated
/** | ||
* Constructor | ||
* | ||
* Note: Explicitly @SkipSelf on LayoutDirective and LayoutWrapDirective because we are looking |
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 note might be better as a regular comment, otherwise it'll show up in any generated docs and typings.
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.
Good point. Thx.
src/lib/flexbox/api/flex.spec.ts
Outdated
@@ -118,6 +118,26 @@ describe('flex directive', () => { | |||
expect(element).not.toHaveCssStyle({'min-width': '30px'}); | |||
}); | |||
|
|||
it('should CSS stylesheet and not inject flex-direction on parent', () => { | |||
componentWithTemplate(` | |||
<style type="text/css"> |
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.
The text/css
shouldn't be necessary.
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.
k. will remove.
src/lib/flexbox/api/base.ts
Outdated
@@ -123,6 +123,12 @@ export abstract class BaseFxDirective implements OnDestroy, OnChanges { | |||
return value ? value.trim() : ((element.nodeType === 1) ? 'block' : 'inline-block'); |
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.
Not something that was added in this PR, but instead of hardcoding the 1
, you can use the built-in browser constant: element.nodeType === Node.ELEMENT_NODE
.
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.
sgtm. Thx.
dde889d
to
07f9a63
Compare
07f9a63
to
55a7636
Compare
@crisbeto using |
90f4238
to
16f8656
Compare
`fxFlex` works best if the parent container has flexbox styles assigned (display, flex-direction, etc.). If not assigned (inline or via stylesheet), then these styles are auto-injected inline on the DOM parent element. When scanning parent DOM element for flexbox flow direction, first scan the in element's inline style and then scan the computed stylesheet for the `flex-direction` value. > It is assumed that if the parent element has a `flex-direction` style property set, then the other required properties (display, border-box, etc.) have also been assigned. Fixes #272, #364.
16f8656
to
4d16c03
Compare
Sorry for saying this but i think you guys are trying to apply styles where you don't need to. This is causing many issues and non expected behaviors. I'm saying this because i had some problems already with things like using @ThomasBurleson, you said: "fxFlex works best if the parent container has flexbox styles assigned.." I ask you: Wouldn't it be better to let the user choose if he wants a flexbox parent? Really, i think that worse then having a |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
fxFlex
works best if the parent container has flexbox styles assigned (display, flex-direction, etc.). If not assigned (inline or via stylesheet), then these styles are auto-injected inline on the DOM parent element.When scanning parent DOM element for flexbox flow direction, first scan the in element's inline style and then scan the computed stylesheet for the
flex-direction
value.Fixes #272, #364.