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

fxFlex directive adding styles to both parent and host element #263

Closed
rosslavery opened this issue Apr 21, 2017 · 13 comments · Fixed by #670
Closed

fxFlex directive adding styles to both parent and host element #263

rosslavery opened this issue Apr 21, 2017 · 13 comments · Fixed by #670
Assignees
Labels
has pr A PR has been created to address this issue P2 Issue that is important to resolve as soon as possible

Comments

@rosslavery
Copy link

rosslavery commented Apr 21, 2017

When fxFlex is added to a child element whose parent does not contain fxLayout, the library is automatically adding inline styles to the parent element (as well as the host) that essentially convert the parent to a flex row.

While I understand the documentation states:

The fxFlex directive should be used on elements within a fxLayout container and identifies the resizing of that element within the flexbox container flow.

There are valid use-cases that require the use of fxFlex to be used while not inside an fxLayout container, and the expected result would be a simply application of flex: 1 1 auto or whatever the desired style is on the host element, while leaving the parent element alone.

One such example would be a routing component that needs to be a flex column. Currently, I have styles in my component stylesheet that set it to be a flex column on the :host. Then the child elements inside the component template use fxFlex to stretch to fill that container. Unfortunately flex-layout is currently converting those routed components to be a flex row with inline styles that clobber the component stylesheet.

The desired behaviour would therefore be to leave the parent component of the host untouched.

Originally posted here: angular/angular#15726

@ThomasBurleson
Copy link
Contributor

@rosslavery - The flex css is injected onto the parent because you used fxFlex on the inner div. fxFlex attempts to resize the host element with respect to its parent flex container. So it adds flex css stylings to the parent (if needed) to insure that the parent container is a flex container.

Is this not a viable behaviour ?

@rosslavery
Copy link
Author

I suppose it's viable, but since the host element in this case already has styles added via it's stylesheet, ideally flex-layout wouldn't clobber the stylesheet styles with it's own assumption about what the parent should be (row vs column).

How else could one define a routed component to be a flex column, since you can't access it's tag to add fxLayout="column" to it? Even with a @HostBinding to add a class or inline styles, I suspect that flex-layout would take precedence over those styles.

@rosslavery
Copy link
Author

It can be fixed with flex-direction: column !important in the component :host stylesheet, it just seemed like an unusual/unexpected behaviour.

As a consumer of the library I was expecting the fxLayout* directives to handle container-related styling, and the fxFlex* directives to handle child-related styling.

@ThomasBurleson
Copy link
Contributor

ThomasBurleson commented Apr 21, 2017

@rosslavery:

RE > As a consumer of the library I was expecting the fxLayout* directives to handle container-related styling, and the fxFlex* directives to handle child-related styling.

True. However, we also tried to add some smarts to tweak the parent if needed using _getFlowDirection ().

I wonder if line 98 should be:

if ( !value && addIfMissing ) {
   value = 'row';
   this._applyStyleToElements(buildLayoutCSS(value), [target]);
 }

RE > How else could one define a routed component to be a flex column, since you can't access it's tag to add fxLayout="column" to it?

This is a great question / consideration.

@rosslavery
Copy link
Author

I mean, I'd appreciate a change like that, would be very helpful.

Thanks for taking the time to consider it!

@ThomasBurleson
Copy link
Contributor

@rosslavery - together (community + flex-layout team), we make a great library!

@mcwebdev
Copy link

I have an open issue for this feature. Add flex attributes to host elements.
#76

@ThomasBurleson
Copy link
Contributor

Refs #272

@ThomasBurleson ThomasBurleson added the P2 Issue that is important to resolve as soon as possible label Jun 22, 2017
@ThomasBurleson ThomasBurleson added this to the Backlog milestone Nov 28, 2017
@CaerusKaru CaerusKaru added has pr A PR has been created to address this issue and removed in-progress labels Mar 18, 2018
@CaerusKaru CaerusKaru modified the milestones: Backlog, v6.0.0-beta.14 Mar 18, 2018
@rmathi
Copy link

rmathi commented Feb 7, 2019

When fxFlex is added to a child element whose parent does not contain fxLayout, the library is automatically adding inline styles to the parent element (as well as the host) that essentially convert the parent to a flex row.

While I understand the documentation states:

The fxFlex directive should be used on elements within a fxLayout container and identifies the resizing of that element within the flexbox container flow.

There are valid use-cases that require the use of fxFlex to be used while not inside an fxLayout container, and the expected result would be a simply application of flex: 1 1 auto or whatever the desired style is on the host element, while leaving the parent element alone.

One such example would be a routing component that needs to be a flex column. Currently, I have styles in my component stylesheet that set it to be a flex column on the :host. Then the child elements inside the component template use fxFlex to stretch to fill that container. Unfortunately flex-layout is currently converting those routed components to be a flex row with inline styles that clobber the component stylesheet.

The desired behaviour would therefore be to leave the parent component of the host untouched.

Originally posted here: angular/angular#15726

Hi.. My doubt/question is..Why its getting automatically applied when AOT compiler on not JIT ? @rosslavery @ThomasBurleson

@rmathi
Copy link

rmathi commented Feb 7, 2019

@rosslavery - The flex css is injected onto the parent because you used fxFlex on the inner div. fxFlex attempts to resize the host element with respect to its parent flex container. So it adds flex css stylings to the parent (if needed) to insure that the parent container is a flex container.

Is this not a viable behaviour ?

Hi.. My doubt/question is..Why its getting automatically applied when AOT compiler on not JIT ? @ThomasBurleson

@naveenrawat51
Copy link

naveenrawat51 commented Jun 14, 2019

Following worked for me in component:

:host {
flex-direction: column !important;
}

Thank you all :-)

@sterlp
Copy link

sterlp commented Jul 8, 2019

I am using "@angular/flex-layout": "^8.0.0-beta.26", and it is still bugged. @naveenrawat51 your workaround works fine -- I am not a CSS pro but just using it as a "client" the current behavior seems wrong to me.

e.g.: using this in the current version requires the fix metioned above ...
https://rawgit.com/start-javascript/sb-admin-material/master/dist/grid

I looked into the demo app by adding
FlexLayoutModule.withConfig({ addFlexToParent: false, }),

to the app.module.ts it is fine too.

@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 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
has pr A PR has been created to address this issue P2 Issue that is important to resolve as soon as possible
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants