Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

menu does not expand correctly #444

Closed
1 task
ruisebastiao opened this issue May 24, 2018 · 6 comments
Closed
1 task

menu does not expand correctly #444

ruisebastiao opened this issue May 24, 2018 · 6 comments

Comments

@ruisebastiao
Copy link

ruisebastiao commented May 24, 2018

Issue type

I'm submitting a ... (check one with "x")

  • [ x] bug report
  • feature request

Issue description

Current behavior:

when sub-menu items are added asynchronous the parent menu does not expand correctly if a sub-menu is selected and a page reload occurs.

peek 2018-05-24 16-04

Expected behavior:

Steps to reproduce:

Related code:


  ngAfterViewInit(): void {
 
    this.userService.currentUser.takeUntil(this._destroyed).subscribe(user => {
      if (user && user.units) {
        const molds_menu = [];

        user.units.forEach(unit => {
          molds_menu.push({
            title: unit.userdata.unit_description,
            link: '/pages/unit/' + unit.serialnumber,
            tag: 'unitchild'
          });
        });

        this.menu[1].children = molds_menu;

        
        this.changedetectorref.detectChanges();
      }
    });
  }

Other information:

npm, node, OS, Browser

<!--
Node, npm: `node --version` and `npm --version`
OS: Windows (7/8/10). Linux (incl. distribution). macOS (El Capitan? Sierra?)
Browser: Chrome/Safari/Firefox/etc?
-->

Angular, Nebular

<!--
Check your `package-lock.json` or locate a `package.json` in the `node_modules` folder.
-->
@ruisebastiao
Copy link
Author

ruisebastiao commented May 26, 2018

this is how i solve this problem:

when the submenu is changed at run-time and if the and the

expand property is false the submenuhigh is not calculated and gets value 0 as we can see in the function:

function sumSubmenuHeight(item: NbMenuItem) {

function sumSubmenuHeight(item: NbMenuItem) {
  return item.expanded
    ? (item.subMenuHeight || 0) + item.children.filter(c => c.children).reduce((acc, c) => acc + sumSubmenuHeight(c), 0)
    : 0;
}

so i changed my code and set the expanded variable to true before setting the submenu:


        this.menu[1].expanded = true;
        this.menu[1].children = molds_menu;

        setTimeout(() => {
          this.changedetectorref.detectChanges();
        }, 250);

@nnixaa
Copy link
Collaborator

nnixaa commented May 30, 2018

Hi @ruisebastiao, thanks for reporting!

@nnixaa
Copy link
Collaborator

nnixaa commented Jun 15, 2018

Hey @ruisebastiao, have you tried NbMenuService.addItems() instead of modifying the variable by reference? Is it working properly in that case?

@nnixaa nnixaa modified the milestones: rc.9, rc.10 Jun 15, 2018
@ruisebastiao
Copy link
Author

ruisebastiao commented Jun 15, 2018

Hi @nnixaa , the only async data are the menu children, how can i use addItems to add children items? But i try to use the addItems to add the root Item with the children data and the problem persists and now the child item doesn't get selected, here is my code:


 this.userService.currentUser.takeUntil(this._destroyed).subscribe(user => {
      if (user && user.units) {
        const molds_menu = [];

        user.units.forEach(unit => {
          molds_menu.push({
            title: unit.userdata.unit_description,
            link: '/pages/unit/' + unit.serialnumber,
            tag: 'unitchild'
          });
        });


         this.menuService.addItems([
         {
             title: 'Molds',
             icon: 'ion-ios-browsers-outline',
             children: molds_menu
           }
         ]);
        this.changedetectorref.detectChanges();

      }
    });

@nnixaa
Copy link
Collaborator

nnixaa commented Jun 29, 2018

#532

@nnixaa
Copy link
Collaborator

nnixaa commented Jun 29, 2018

akveo/ngx-admin#1703

@nnixaa nnixaa modified the milestones: rc.10, 2.0.0 Aug 8, 2018
@yggg yggg mentioned this issue Aug 10, 2018
2 tasks
@nnixaa nnixaa closed this as completed Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants