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

Add 'menu-left-open' and 'menu-right-open' classes #1072

Closed
wants to merge 6 commits into from
Closed

Add 'menu-left-open' and 'menu-right-open' classes #1072

wants to merge 6 commits into from

Conversation

rvanbaalen
Copy link

When opening a left side menu or right side menu, toggle a 'menu-right-open' or 'menu-left-open' class on the ion-side-menu-content element.

This allows for custom styling of the content pane (for example; show a dark overlay) when one of the menus is open.

When opening a left side menu or right side menu, toggle a 'menu-right-open' or 'menu-left-open' class on the `ion-side-menu-content` element.

This allows for custom styling of the content pane (for example; show a dark overlay) when one of the menus is open.
@rvanbaalen
Copy link
Author

Not sure what you mean by that @adamdbradley. Could you perhaps explain that with a small snippet?

The reason for the PR originated when I wanted to show a dark overlay over my content pane when one of the menu's is opened. At this point, without the PR, there was no point to do this with pure CSS.

@rvanbaalen
Copy link
Author

@adamdbradley I think I understand your question now. If I'm not mistaken, you assume that these dynamic classes are applied to the side menu's itself? That wouldn't make any sense indeed.

Instead, they are applied to the ion-side-menu-content element which slided to the left/right when the menu opened.

@adamdbradley
Copy link
Contributor

Sure if they are applied to the menu content then yes I see its value. Before I merge this in could you write some tests first to make sure they're being added and removed correctly? Thanks.

@rvanbaalen
Copy link
Author

@adamdbradley Sure. Since I'm not that familiar with the tests in Ionic, could you point me to the file where I should add the test?
I can't find that many tests; the closest thing I found was this:
https://github.com/rvanbaalen/ionic/blob/patch-2/test/unit/views/sideMenu.unit.js

@ajoslin
Copy link
Contributor

ajoslin commented Apr 7, 2014

Our test structure right now is super confusing; we're amending that soon. It's here: https://github.com/rvanbaalen/ionic/blob/patch-2/js/ext/angular/test/directive/ionicSideMenu.unit.js

@ajoslin
Copy link
Contributor

ajoslin commented Apr 7, 2014

Although this isn't actually the right place to be adding a class. You'll be manipulating the DOM every time setTranslateX is called.

I would do it in js/controllers/sideMenuController.js, openPercentage function. Add it to this.content.el - but be sure to do an if (this.content) around it.

@rvanbaalen
Copy link
Author

👍 I'm on it.

Reverted last edit
@rvanbaalen
Copy link
Author

@ajoslin There is no this.content.el from what I can see this quick.

@ajoslin
Copy link
Contributor

ajoslin commented Apr 7, 2014

this.content is an instance of js/views/sideMenuView.js

@rvanbaalen
Copy link
Author

I noticed that and I see that this.el is being used within the sideMenuView but it doesn't seem to be a public property. This is what I get when I console.log(this.content, this.content.el, percentage) from within openPercentage():

screen shot 2014-04-07 at 14 08 28

Notice the undefined and no el property on this.content

@ajoslin
Copy link
Contributor

ajoslin commented Apr 7, 2014

I see. You're right.

js/views/sideMenuView.js is actually not used! The side menu code is weird because it started without angular and we 'patched' angular on to the code.

The content is set through sideMenuCtrl.setContent() in ionicSideMenu directive.

Umm, you could just add an 'el: $element[0]' field on line 295 of directives/ionicSideMenu.js

Add classes to menu-content element based on which side menu is currently open.
This allows for custom CSS based styling of the content element when one of the side menus has opened (for example; show a dark overlay)
Added test to check if `content.el` is available from sideMenuController's public API
@rvanbaalen
Copy link
Author

Pretty new to the whole test writing thing. Am I doing it right @ajoslin? At least I did get all the proper code in place to add / remove the classes. Just aren't able to write the tests (yet).

@rvanbaalen
Copy link
Author

@ajoslin @adamdbradley Nevermind this pull request. I've found a better way to achieve this goal without un-needed DOM manipulation by adding classes that might never be used.

This is how I archieve my goal now:

<ion-content
    scroll="true"
    class="has-header"
    ng-class="{
        'has-loading': loadingMessage,
        'menu-open': $ionicSideMenuDelegate.isOpenLeft() || $ionicSideMenuDelegate.isOpenRight()
    }">

Perhaps it would be nice to have a $ionicSideMenuDelegate.isOpen() which returns true if any of the side menus are open.

@rvanbaalen rvanbaalen closed this Apr 7, 2014
@rvanbaalen rvanbaalen deleted the patch-2 branch April 7, 2014 19:15
@ajoslin
Copy link
Contributor

ajoslin commented Apr 7, 2014

@rvanbaalen cool! Thanks for trying. I was going to say, the way you were doing actually wouldn't have worked in all cases now that I thought about it - since when the user is dragging the side menu, openPercentage isn't actually called.

The way to do it (if we were going to do it) would be to setup a $watch in the ionSideMenuContent directive:

$scope.$watch(function() { 
  return sideMenuCtrl._leftShowing; 
}, function(isLeft) {
  $element.toggleClass('menu-left-open', !!isLeft);
});

Then the same for right.

This would be super easy to unit test, too.

Sorry for the runaround! Glad you figured it out.

@rvanbaalen
Copy link
Author

Opened two new related pull requests:
#1074
#1075

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants