Skip to content

[Proposal] Tab content hidden option #731

Closed

Description

@RicardoVaranda

Bug, feature request, or proposal:

Proposal

What is the expected behavior?

Tab content hiding instead of ngIf removing them from DOM

What is the current behavior?

Temporarily Removed from DOM and inserted again once ngIf is active

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

Switching between tabs seems to be a lot faster for me after adopting the content hiding instead of ngIf, along with that I'm creating a socket connection within each content which is being reset every time I load a new tab.

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

All

Is there anything else we should know?

If allowed I'd like to post a pull request which would adapt both methods of doing this leaving the ngIf as default and only using hidden if a certain flag is used.

Activity

  1. aminebizid commented on Jun 21, 2016

    @aminebizid

    Personnaly I prefer ngIf because I need content to reload when changing tabs.
    Suppose I have two tabs
    Tab1: managing roles and functionalities
    Tab2: Managing user roles

    If I add a new role in tab1 I need it to be shown on tab2 after switching tabs.

  2. aminebizid commented on Jun 21, 2016

    @aminebizid

    And I believe tab group is using portal host (no ngIf)

  3. added
    perf
    on Jun 21, 2016
  4. jelbourn commented on Jun 21, 2016

    @jelbourn
    Contributor

    @robertmesserle we should look into the performance implications of this

  5. added this to the before beta milestone on Jun 21, 2016
  6. added
    feature
    on Jun 21, 2016
  7. no-more commented on Jun 21, 2016

    @no-more

    Hi,

    I think both case are very useful and depends on usage. It would be great to be able to choose which mode to use. Another great feature could be to load content only when the tab was selected once and then keep the content even when changing tabs.

    Thanks.

  8. RicardoVaranda commented on Jun 21, 2016

    @RicardoVaranda
    Author

    @jelbourn For me the performance is amazing, switching between all of the tabs is a lot faster since I don´t have to keep reconnecting.

    @Zigzag95 I know it's *ngIf as I've analysed the source code:
    L23

    What I did to make it work was quite simple, since [hidden] can't be used in a template, I had to surround it with a div and place the directive there.

    Let me know if you want me to post a PR so you can test the performance.

  9. robertmesserle commented on Jun 21, 2016

    @robertmesserle
    Contributor

    @jelbourn @RicardoVaranda I think I agree that we should support both options. When dealing with a small number of tabs, hiding the inactive tabs will typically be faster; however, when dealing with a large number of tabs, this can cause performance issues.

    The ideal solution would be something like what we tried in Material 1 with disconnectScope, but I'm not sure if there's a good bug-free way to do that.

  10. no-more commented on Jun 22, 2016

    @no-more

    I can see one other major bonus of hiding instead of removing the element from the dom, it's when the content of the tab is editable and unsaved. When switching tabs the changes are lost.
    But once again both options should be supported as they both have their own use cases.

  11. RajeeNedunchezhian commented on Aug 18, 2016

    @RajeeNedunchezhian

    Yes i agree that we should have both options, as @no-more mentioned, i have similar use case where i group the grid , now after switching tabs the grouping/filtering doesnt stay. The data bound to grid in different tabs are not the same , so putting the datamodel outside wont work in this case . @RicardoVaranda can you provide your solution if possible. Thanks

  12. RicardoVaranda commented on Aug 19, 2016

    @RicardoVaranda
    Author

    I will create a pull request with the solution for this in the morning.

  13. RajeeNedunchezhian commented on Aug 19, 2016

    @RajeeNedunchezhian
  14. HeavenlyHost commented on Sep 15, 2016

    @HeavenlyHost

    Agree, but please make this an option as we are currently using the original feature whereby ngIf removes it from dom, this matches our user requirements !!! Please do not remove this feature :-)

  15. FoodBuster commented on Sep 15, 2016

    @FoodBuster

    @RicardoVaranda Did you make that pull request for [hidden] md-tabs? I couldn't find it. I'd really appreciate a look.

  16. 1 remaining item

  17. FoodBuster commented on Sep 15, 2016

    @FoodBuster

    @RicardoVaranda Much appreciated!

  18. RicardoVaranda commented on Oct 11, 2016

    @RicardoVaranda
    Author

    Sorry for the delay, I've created a PR for this:

    #1472

    This will allow us to use the tabs just like before but by passing hideTabs input of true it will hide the tab contents instead of removing and adding them to the DOM, there are some setbacks to this and it should be used with moderation, i.e you shouldn't hide the contents if you have a large number of tabs e.g 10+

    Example below:

    <md-tab-group [hideTabs]="true" class="demo-tab-group">
      <md-tab *ngFor="let tab of tabs; let i = index" [disabled]="i == 1">
        <template md-tab-label>{{tab.label}}</template>
        <template md-tab-content>
          {{tab.content}}
          <br>
          <br>
          <br>
          <md-input placeholder="Tab Label" [(ngModel)]="tab.label"></md-input>
        </template>
      </md-tab>
    </md-tab-group>
    
  19. tomwanzek commented on Oct 11, 2016

    @tomwanzek

    +1 for allowing an option to hide without DOM teardown.

    The other reason, I ran into is that, placing a (secondary) <router-outlet> into the tab content, means its content currently is not being re-populated after switching back and forth between tabs (while there is no route change). See tab-related issues #1445 and #524.

  20. tomwanzek commented on Nov 2, 2016

    @tomwanzek

    This item seems all the more important now.

    As far as the "Tab + Router" issue #524 goes, it has just been closed with a solution that does not seem to address the use case I initially opened as issue #1445 (I.e. using a secondary router outlet as one of the tabs in a tab-group.)

  21. self-assigned this
    on Nov 3, 2016
  22. andrewseguin commented on Nov 10, 2016

    @andrewseguin
    Contributor

    Tabs no longer use ngIf but attach/detach the content using a portalHost. Changes made to the content are preserved when switching tabs. I am not seeing any performance issues using this method.

  23. dayong38 commented on Jun 11, 2017

    @dayong38

    @andrewseguin
    I'm now using <iframe> tag as tab-content, and it is reloaded as I change tabs. Not sure if there is any workaround for this to prevent reloading the iframe contents.
    Thanks.

  24. jelbourn commented on Jun 12, 2017

    @jelbourn
    Contributor
  25. dayong38 commented on Jun 13, 2017

    @dayong38

    @jelbourn Thanks so much. Lemme chek.

  26. dayong38 commented on Jun 13, 2017

    @dayong38

    @jelbourn Does md-tab support a feature that do not hide it's contents though tab is deselected and only shows the contents once the tab is activated again?
    I'm using <iframe> in the md-tab and it always reloads when tab is changed.
    Thanks in advance.

  27. RicardoVaranda commented on Jun 13, 2017

    @RicardoVaranda
    Author

    @dayong38 What I did was, fork the repo and applied the following changes:
    RicardoVaranda@43b0bc6

    Also this commit to fix a bug:
    RicardoVaranda@4391f70

    Make sure you check both of them out as the second one is to fix a bug so if you want to implement it make sure you follow that also 😄

  28. anupvarma commented on Jun 20, 2017

    @anupvarma

    Can somebody let me know if my issue #5239 is related to this issue.
    plunker: http://plnkr.co/edit/DADYadzGOFI5GqkkITkA?p=preview

  29. angular-automatic-lock-bot commented on Sep 5, 2019

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

  30. locked and limited conversation to collaborators on Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

featureperf

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions