question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Responsive fxFlex applying incorrect value

See original GitHub issue

Bug Report

Using the following markup:

<section fxLayout="row wrap" fxLayoutGap="0" fxLayoutGap.gt-xs="20px">
  <mat-card
    *ngFor="let widget of widgets"
    fxFlex.gt-sm="0 1 calc(100% / 3 - 20px)"
    fxFlex.gt-xs="0 1 calc(100% / 2 - 20px)"
    fxFlex="0 1 100%">
    <mat-card-header>
      <mat-card-title>
        <a [routerLink]="['widget', widget.color]">{{ widget.color }} widget</a>
      </mat-card-title>
    </mat-card-header>
  </mat-card>
</section>

What is the expected behavior?

On a sufficiently large screen, render 3 columns of cards, applying the correct flex value of 0 1 calc(33.3333% - 20px)

What is the current behavior?

Only 2 columns of cards are rendered, applying flex value of 0 1 calc(50% - 20px).

If you shrink the browser window to mobile, then back up to full screen you’ll notice the correct flex-basis values are applied.

What are the steps to reproduce?

Stackblitz: https://angular-flex-repro.stackblitz.io/

Note: A project I’m working on now initially renders 3 cards, but upon navigating to another route and coming back, there were only 2 cards. A refresh fixed it that case, but that is why the additional routing functionality is included in the blitz (even though I can’t reproduce that exact behavior there).

Edit: When I resize the window to get 3 card layout, navigate away, and back, cards are back to 2 cols. Same behavior as initial render.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Tested on Chrome 69, Firefox 61, Safari 11.1, MacOS 10.13. Dependency versions can be seen in the stackblitz.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
probert94commented, Oct 5, 2018

After investigating a bit more I noticed a few things. In my usecase, I need different flex settings for xs, sm and all others.

Here is what I noticed:

  1. Using fxFlex.xs, fxFlex.sm and fxFlex.gt-sm will only correctly apply fxFlex.gt-sm. All others use the fallback (fxFlex).
  2. Using fxFlex.lt-sm, fxFlex.lt-md and fxFlex.gt-sm will correctly apply fxFlex.gt-sm and fxFlex.lt-md on sm-Screens. On xs-Screens, however, fxFlex.lt-md is used instead of fxFlex.lt-sm.
  3. Using fxFlex.lt-sm, fxFlex and fxFlex.gt-sm applies everything correctly. The fallback (fxFlex) is only used for sm-Screens.

Note, that in all cases, the results were correct after resizing the screen.

@itsthesteve The workaround from case 3 might solve your problem too. You probably can just redifine your fxFlex definitions:

  • fxFlex.gt-sm="0 1 calc(100% / 3 - 20px)" –> fxFlex.gt-sm="0 1 calc(100% / 3 - 20px)"
  • fxFlex.gt-xs="0 1 calc(100% / 2 - 20px)" –> fxFlex="0 1 calc(100% / 2 - 20px)"
  • fxFlex="0 1 100%" –> fxFlex.lt-sm="0 1 100%"
0reactions
angular-automatic-lock-bot[bot]commented, Sep 5, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular/flex-layout How To: different class based on screensize?
Is there a way to have @angular/flex-layout change the class based on screen size? I know I can do this: <div fxFlex="grow" fxLayout="row" ......
Read more >
Building Responsive Applications with Angular Flex Layout
One wrong move with the mug and the whole meaning is changed. ... The Angular Flex Layout package is a great way to...
Read more >
angular/flex-layout - Gitter
I get an error in any module that imports it. Something like this: Unexpected value 'undefined' imported by the module 'AppModule'.
Read more >
How To Use Flex Layout for Angular - DigitalOcean
... to create responsive layouts. In this tutorial, you will build an example Angular application and use Flex Layout to arrange items.
Read more >
Implementing Flex Layout in Angular: A How-To Guide
In this cloud tutorial, we will create a simple Angular application and inject Flex ... and different directives can be used to create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found