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

ngClass changes incorrectly when printing #1201

Closed

Description

@JustACodeMonkey

Bug Report

On elements with ngClass, the media observers misbehave when printing. For example, if I have...

<p class="text-left" ngClass.lt-sm="text-center">Some text here</p>

...When I press Ctrl + P to print the page, then return, the text is centered (even though the screen size is still 1920px).

What is the expected behavior?

ngClass.lt-sm should be removed when printing is complete

What is the current behavior?

ngClass.lt-sm remains applied

What are the steps to reproduce?

What is the use-case or motivation for changing an existing behavior?

The screen looks incorrect when printing completes

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

I have tested in the latest Angular 8 and 9 releases with FlexLayout 8.0.0-beta.27 and 9.0.0-beta.29 respectively.

Is there anything else we should know?

Activity

  1. alex-vg commented on Apr 3, 2020

    @alex-vg

    I think the activatedBreakpoints are not properly restored in stopPrinting()

    edit: yes, I can confirm, activatedBreakpoints are not restored correctly. If you just dump=[...target.activatedBreakpoints] in startPrinting() and set target.activatedBreakpoints = dump in stopPrinting() it works in my case. This also affects other breakpoint styles like fxFlex.lg-md etc.

    this was my case:

    target.activatedBreakpoints.map((x)=>x.alias) the correct array in startPrinting():
    ["xl", "gt-lg", "gt-md", "gt-sm", "gt-xs"]

    this.deactivations.map((x)=>x.alias) the faulty array in stopPrinting():
    ["xs", "lt-sm", "lt-md", "lt-lg", "lt-xl", "xl", "gt-lg", "gt-md", "gt-sm", "gt-xs"]

  2. alex-vg commented on Apr 3, 2020

    @alex-vg

    My little dirty hack until this gets resolved....

    export class CommonMaterialModule {
      lastValue;
    
      public constructor (
        m: MediaMarshaller,
      ) {
        // hack until resolve: https://github.com/angular/flex-layout/issues/1201
        // @ts-ignore
        m.subject.subscribe((x) => {
          // @ts-ignore
          if (m.activatedBreakpoints.filter((b) => b.alias === 'print').length === 0) {
            // @ts-ignore
            this.lastValue = [...m.activatedBreakpoints];
          } else {
            // @ts-ignore
            m.activatedBreakpoints = [...this.lastValue];
            // @ts-ignore
            m.hook.collectActivations = () => {};
            // @ts-ignore
            m.hook.deactivations = [...this.lastValue];
          }
        });
      }
    
    }
    
    

    CommonMaterialModule is my only module that imports (and re-exports) FlexLayoutModule.

  3. PsyStorm25 commented on May 20, 2020

    @PsyStorm25

    @alex-vg thank you, your temporary fix works for me.
    Seems this bug is a duplicate of #1228 (or the opposite).

  4. lambertwen commented on May 22, 2020

    @lambertwen

    @alex-vg much appreciated! this fix did the trick.

  5. qliqdev commented on Jul 15, 2020

    @qliqdev

    I'm using "@angular/flex-layout": "^10.0.0-beta.32" and the problem is still exists in todays.

  6. jnfaerch commented on Nov 12, 2020

    @jnfaerch

    Just chiming in as this bug is still present. Thx to @alex-vg for the temporary fix 👍

  7. FloNeu commented on Mar 4, 2021

    @FloNeu

    Hello! Also ran into this bug - and was searching for hours - any reason this isn't resolved yet - the hack, did solf the issue for now!

  8. tyeety commented on Mar 17, 2021

    @tyeety

    Same bug here. I'm using ^11.0.0-beta.33 facing this error. even if I use *ngIf to remove elements before calling window.print, all elements use fxFlex.sm value.

  9. FloNeu commented on Mar 17, 2021

    @FloNeu

    @tyeety use the fix from @alex-vg - it restores the correct breakpoints after the print-window closes

  10. tyeety commented on Mar 17, 2021

    @tyeety

    Yes, Thank you @FloNeu and many thanks to @alex-vg for the solution. I imported this module in my root module and problem fixed for the entire solution. Hope to see that the problem is fixed in the very next version

  11. borox2k commented on Apr 27, 2021

    @borox2k

    @alex-vg thanks, your workaround still works 2021 angular 11
    gracias

  12. Amirroracle commented on May 7, 2021

    @Amirroracle

    The issue with @alex-vg 's solution is that it restores the breakpoint but I found that the print preview is now broken instead.

  13. alex-vg commented on May 7, 2021

    @alex-vg

    The issue with @alex-vg 's solution is that it restores the breakpoint but I found that the print preview is now broken instead.

    Which breakpoints are active when printing?
    In case you want to set the print breakpoints: https://github.com/angular/flex-layout/blob/master/docs/documentation/BreakPoints.md

    The workaround just restores breakpoints, it does not write print breakpoints on print-begin.

  14. Amirroracle commented on May 10, 2021

    @Amirroracle

    @alex-vg

    So I found out what the issue was, and for anyone else also running into the same issue where the print preview is malformed, it is due to centering using fxLayoutAlign. Basically instead of using fxLayoutAlign="center center" I would replace it with this in your component style:

        .body-print {
          place-content: stretch center;
        }
        @media print {
          .body-print {
            place-content: stretch start;
          }
         }
  15. rdanielst commented on May 20, 2021

    @rdanielst

    Thank you very much @alex-vg !!!!!

  16. 1 remaining item

  17. dhammond371 commented on Dec 14, 2021

    @dhammond371

    Problem still exists

  18. added
    has pr
    P0
    print
    on Dec 29, 2021
  19. self-assigned this
    on Dec 29, 2021
  20. added this to the 13.0.0-beta.37 milestone on Dec 29, 2021
  21. CaerusKaru commented on Dec 29, 2021

    @CaerusKaru
    Member

    First of all, thank you so much to @alex-vg for the patch that helped users while we tracked this issue. Contributions like this are invaluable and greatly appreciated by the entire team.

    Now, the issue at hand, it turns out the root cause was a lot simpler than I thought it was going to be, and was just an issue of array reference assignment. In essence, we were restoring breakpoints correctly, but then immediately unassigning them. This led to the outcome all of you were seeing during print, which was obviously less than optimal. We've patched this in #1379, which has landed in the nightly release for those who'd like to try it out and report back. If not, it'll be in the next minor/major release.

    Thank you all for your patience, and again, thank you @alex-vg.

  22. CaerusKaru commented on Dec 29, 2021

    @CaerusKaru
    Member

    Ok quick followup here; my solution worked about half-way. The other half involved incorporating much of what @alex-vg's solution put forth. They were correct that our accumulation routine was not working, and that a better method is to just capture the breakpoints before the event and restore them after. Unfortunately, this went against the intention of the accumulator in the first place (we essentially had that approach to begin with); we support beforeprint and afterprint events as well for browsers that have quirky print behaviors. Therefore, in #1380, I have adapted this approach so that it works in both instances. This should close out the issue, and in testing with the docs site I think we're in the clear.

  23. Sergiobop commented on Jan 28, 2022

    @Sergiobop

    @CaerusKaru Thank you! Can we have a minor release with the patch?

  24. CaerusKaru commented on Jan 28, 2022

    @CaerusKaru
    Member

    Patch release 13.0.0-beta.37 cut. Please let us know it you have any further issues.

  25. angular-automatic-lock-bot commented on Feb 28, 2022

    @angular-automatic-lock-bot

    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.

  26. locked and limited conversation to collaborators on Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P0bughas prin-progressprint

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions