Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

fix(flexbox): scan flex-direction in css stylesheet #365

Merged
merged 1 commit into from
Aug 7, 2017

Conversation

ThomasBurleson
Copy link
Contributor

@ThomasBurleson ThomasBurleson commented Aug 6, 2017

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.

@ThomasBurleson
Copy link
Contributor Author

ThomasBurleson commented Aug 6, 2017

@crisbeto - can you review ? Thx.

@ThomasBurleson ThomasBurleson added this to the v2.0.0-beta.9 milestone Aug 6, 2017
Copy link
Member

@crisbeto crisbeto left a 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.

@@ -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];
Copy link
Member

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).

Copy link
Contributor Author

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 ?

Copy link
Member

@crisbeto crisbeto Aug 6, 2017

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know. Thx.

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.

/**
* Constructor
*
* Note: Explicitly @SkipSelf on LayoutDirective and LayoutWrapDirective because we are looking
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Thx.

@@ -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">
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

k. will remove.

@@ -123,6 +123,12 @@ export abstract class BaseFxDirective implements OnDestroy, OnChanges {
return value ? value.trim() : ((element.nodeType === 1) ? 'block' : 'inline-block');
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sgtm. Thx.

@ThomasBurleson ThomasBurleson added pr: lgtm This PR has been approved by the reviewer pr: needs presubmit labels Aug 6, 2017
@ThomasBurleson
Copy link
Contributor Author

@crisbeto using Node.ELEMENT_NODE causes problems with angular universal compiles.

@ThomasBurleson ThomasBurleson force-pushed the thomas/issue-364 branch 3 times, most recently from 90f4238 to 16f8656 Compare August 7, 2017 13:52
`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.
@matheusdavidson
Copy link

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 fxFlex.gt-xs and flex layout adding styles even when breakpoint is under xs(talked about this in another issue #296).

@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 fxFlex without flexbox parent(this obvious) is to have no idea why my parent element got flexbox in the first place, since i was already applying it in my css file and flex layout just override the whole thing.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes pr: lgtm This PR has been approved by the reviewer pr: needs presubmit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parent container flexbox injection logic is wrong
6 participants