Skip to content

Commit

Permalink
fix(menu-toggle): move logic for css class to the menu toggle
Browse files Browse the repository at this point in the history
fixes #8943
  • Loading branch information
brandyscarney committed Nov 23, 2016
1 parent e09aee4 commit 5c84ff3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
11 changes: 0 additions & 11 deletions src/components/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ export class Button extends Ion {
/** @private */
_role: string = 'button'; // bar-button

/** @private */
_mt: boolean; // menutoggle

/** @private */
_size: string; // large/small/default

Expand Down Expand Up @@ -259,7 +256,6 @@ export class Button extends Ion {
}

constructor(
@Attribute('menuToggle') menuToggle: string,
@Attribute('ion-button') ionButton: string,
config: Config,
elementRef: ElementRef,
Expand All @@ -275,12 +271,6 @@ export class Button extends Ion {
if (ionButton.trim().length > 0) {
this.setRole(ionButton);
}

// menuToggle can be added with or without a string
// but if the attribute isn't added it will be null
if (menuToggle !== null) {
this._mt = true;
}
}

/** @private */
Expand All @@ -307,7 +297,6 @@ export class Button extends Ion {
this.setElementClass(role, assignCssClass); // button
this.setElementClass(`${role}-${this._mode}`, assignCssClass); // button

this._setClass('menutoggle', this._mt); // menutoggle
this._setClass(this._style, assignCssClass); // button-clear
this._setClass(this._shape, assignCssClass); // button-round
this._setClass(this._display, assignCssClass); // button-full
Expand Down
21 changes: 17 additions & 4 deletions src/components/menu/menu-toggle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Directive, ElementRef, Input, HostListener, Optional } from '@angular/core';
import { Directive, Input, HostListener, Optional } from '@angular/core';

import { Button } from '../button/button';
import { MenuController } from './menu-controller';
import { Navbar } from '../navbar/navbar';
import { ViewController } from '../../navigation/view-controller';
Expand Down Expand Up @@ -86,8 +87,7 @@ import { ViewController } from '../../navigation/view-controller';
@Directive({
selector: '[menuToggle]',
host: {
'[hidden]': 'isHidden',
'menuToggle': '' // ensures the attr is there for css when using [menuToggle]
'[hidden]': 'isHidden'
}
})
export class MenuToggle {
Expand All @@ -97,20 +97,33 @@ export class MenuToggle {
*/
@Input() menuToggle: string;

/**
* @private
*/
private _isButton: boolean;

/**
* @private
*/
private _inNavbar: boolean;

constructor(
private _menu: MenuController,
elementRef: ElementRef,
@Optional() private _viewCtrl: ViewController,
@Optional() private _button: Button,
@Optional() private _navbar: Navbar
) {
this._isButton = !!_button;
this._inNavbar = !!_navbar;
}

ngAfterContentInit() {
// Add the bar-button-menutoggle / button-menutoggle class
if (this._isButton) {
this._button._setClass('menutoggle', true);
}
}

/**
* @private
*/
Expand Down
21 changes: 11 additions & 10 deletions src/components/menu/test/basic/app-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ export class Page1 {
constructor(
public navCtrl: NavController,
public alertCtrl: AlertController,
public modalCtrl: ModalController
) { }
public modalCtrl: ModalController) { }

myMenu: string = 'right';

presentAlert() {
let alert = this.alertCtrl.create({
Expand All @@ -32,22 +33,22 @@ export class Page1 {
}
}

@Component({templateUrl: 'modal.html'})
@Component({ templateUrl: 'modal.html' })
export class Modal {
constructor(public viewController: ViewController) {}
constructor(public viewController: ViewController) { }
close() {
this.viewController.dismiss();
}
}


@Component({templateUrl: 'page3.html'})
export class Page3 {}
@Component({ templateUrl: 'page3.html' })
export class Page3 { }


@Component({templateUrl: 'page2.html'})
@Component({ templateUrl: 'page2.html' })
export class Page2 {
constructor(public navCtrl: NavController) {}
constructor(public navCtrl: NavController) { }

page3() {
this.navCtrl.push(Page3);
Expand All @@ -61,7 +62,7 @@ export class Page2 {
export class E2EPage {
rootPage: any;
changeDetectionCount: number = 0;
pages: Array<{title: string, component: any}>;
pages: Array<{ title: string, component: any }>;
@ViewChild(Nav) nav: Nav;

constructor(public menuCtrl: MenuController) {
Expand Down Expand Up @@ -139,4 +140,4 @@ export class E2EApp {
Modal
]
})
export class AppModule {}
export class AppModule { }
2 changes: 1 addition & 1 deletion src/components/menu/test/basic/page1.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</button>
</ion-buttons>

<button ion-button menuToggle="right" right color="secondary">
<button ion-button [menuToggle]="myMenu" right color="secondary">
<ion-icon name="menu"></ion-icon>
</button>

Expand Down

0 comments on commit 5c84ff3

Please sign in to comment.