Skip to content

Commit

Permalink
fix(ion-backdrop): new ion-backdrop can prevent background scrolling
Browse files Browse the repository at this point in the history
closes #6656
  • Loading branch information
manucorporat committed Jun 2, 2016
1 parent c42bf97 commit a1a582b
Show file tree
Hide file tree
Showing 21 changed files with 153 additions and 115 deletions.
1 change: 1 addition & 0 deletions src/components.core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

// Core Components
@import
"components/backdrop/backdrop",
"components/grid/grid",
"components/icon/icon",
"components/img/img",
Expand Down
14 changes: 7 additions & 7 deletions src/components/action-sheet/action-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class ActionSheet extends ViewController {
@Component({
selector: 'ion-action-sheet',
template:
'<div (click)="bdClick()" tappable disable-activated class="backdrop" role="presentation"></div>' +
'<ion-backdrop (click)="bdClick()"></ion-backdrop>' +
'<div class="action-sheet-wrapper">' +
'<div class="action-sheet-container">' +
'<div class="action-sheet-group">' +
Expand Down Expand Up @@ -384,7 +384,7 @@ class ActionSheetSlideIn extends Transition {
super(opts);

let ele = enteringView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.action-sheet-wrapper'));

backdrop.fromTo('opacity', 0.01, 0.4);
Expand All @@ -401,7 +401,7 @@ class ActionSheetSlideOut extends Transition {
super(opts);

let ele = leavingView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.action-sheet-wrapper'));

backdrop.fromTo('opacity', 0.4, 0);
Expand All @@ -418,7 +418,7 @@ class ActionSheetMdSlideIn extends Transition {
super(opts);

let ele = enteringView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.action-sheet-wrapper'));

backdrop.fromTo('opacity', 0.01, 0.26);
Expand All @@ -435,7 +435,7 @@ class ActionSheetMdSlideOut extends Transition {
super(opts);

let ele = leavingView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.action-sheet-wrapper'));

backdrop.fromTo('opacity', 0.26, 0);
Expand All @@ -451,7 +451,7 @@ class ActionSheetWpSlideIn extends Transition {
super(opts);

let ele = enteringView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.action-sheet-wrapper'));

backdrop.fromTo('opacity', 0.01, 0.16);
Expand All @@ -468,7 +468,7 @@ class ActionSheetWpSlideOut extends Transition {
super(opts);

let ele = leavingView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.action-sheet-wrapper'));

backdrop.fromTo('opacity', 0.1, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/components/action-sheet/test/basic/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ it('should open action sheet', function() {
});

it('should close with backdrop click', function() {
element(by.css('.backdrop')).click();
element(by.css('ion-backdrop')).click();
});
14 changes: 7 additions & 7 deletions src/components/alert/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export class Alert extends ViewController {
@Component({
selector: 'ion-alert',
template:
'<div (click)="bdClick()" tappable disable-activated class="backdrop" role="presentation"></div>' +
'<ion-backdrop (click)="bdClick()"></ion-backdrop>' +
'<div class="alert-wrapper">' +
'<div class="alert-head">' +
'<h2 id="{{hdrId}}" class="alert-title" *ngIf="d.title" [innerHTML]="d.title"></h2>' +
Expand Down Expand Up @@ -612,7 +612,7 @@ class AlertPopIn extends Transition {
super(opts);

let ele = enteringView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.alert-wrapper'));

wrapper.fromTo('opacity', '0.01', '1').fromTo('scale', '1.1', '1');
Expand All @@ -633,7 +633,7 @@ class AlertPopOut extends Transition {
super(opts);

let ele = leavingView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.alert-wrapper'));

wrapper.fromTo('opacity', '1', '0').fromTo('scale', '1', '0.9');
Expand All @@ -654,7 +654,7 @@ class AlertMdPopIn extends Transition {
super(opts);

let ele = enteringView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.alert-wrapper'));

wrapper.fromTo('opacity', '0.01', '1').fromTo('scale', '1.1', '1');
Expand All @@ -675,7 +675,7 @@ class AlertMdPopOut extends Transition {
super(opts);

let ele = leavingView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.alert-wrapper'));

wrapper.fromTo('opacity', '1', '0').fromTo('scale', '1', '0.9');
Expand All @@ -697,7 +697,7 @@ class AlertWpPopIn extends Transition {
super(opts);

let ele = enteringView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.alert-wrapper'));

wrapper.fromTo('opacity', '0.01', '1').fromTo('scale', '1.3', '1');
Expand All @@ -718,7 +718,7 @@ class AlertWpPopOut extends Transition {
super(opts);

let ele = leavingView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.alert-wrapper'));

wrapper.fromTo('opacity', '1', '0').fromTo('scale', '1', '1.3');
Expand Down
2 changes: 1 addition & 1 deletion src/components/alert/alert.wp.scss
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ $alert-wp-checkbox-icon-transform: rotate(45deg) !default;


ion-alert {
.backdrop {
ion-backdrop {
background: $alert-wp-backdrop-background;
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/components/backdrop/backdrop.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@import "../../globals.core";

// Backdrop
// --------------------------------------------------

$backdrop-color: #000 !default;

ion-backdrop {
position: absolute;
top: 0;
left: 0;
z-index: $z-index-backdrop;
display: block;

width: 100%;
height: 100%;

background-color: $backdrop-color;
opacity: 0.01;
transform: translateZ(0);
}

ion-backdrop.hide-backdrop {
display: none;
}
61 changes: 61 additions & 0 deletions src/components/backdrop/backdrop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {Directive, ViewEncapsulation, HostListener, ElementRef, Input} from '@angular/core';
import {isTrueProperty} from '../../util/util';

const DISABLE_SCROLL = 'disable-scroll';

/**
* @private
*/
@Directive({
selector: 'ion-backdrop',
host: {
'role': 'presentation',
'tappable': '',
'disable-activated': ''
},
})
export class Backdrop {
private static nuBackDrops: number = 0;

private static push() {
if (this.nuBackDrops === 0) {
console.debug('adding .disable-scroll to body');
document.body.classList.add(DISABLE_SCROLL);
} else {
console.warn('several backdrops on screen? probably a bug');
}
this.nuBackDrops++;
}

private static pop() {
if (this.nuBackDrops === 0) {
console.error('pop requires a push');
return;
}
this.nuBackDrops--;
if (this.nuBackDrops === 0) {
console.debug('removing .disable-scroll from body');
document.body.classList.remove(DISABLE_SCROLL);
}
}

private pushed: boolean = false;
@Input() disableScroll = true;

constructor(public elementRef: ElementRef) {}

ngOnInit() {
if (isTrueProperty(this.disableScroll)) {
Backdrop.push();
this.pushed = true;
}
}

ngOnDestroy() {
if (this.pushed) {
Backdrop.pop();
this.pushed = false;
}
}

}
8 changes: 0 additions & 8 deletions src/components/loading/loading.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Loading Indicator
// --------------------------------------------------


ion-loading {
position: absolute;
top: 0;
Expand All @@ -26,10 +25,3 @@ ion-loading {

opacity: 0;
}

// Loading Backdrop
// -----------------------------------------

.hide-backdrop {
display: none;
}
14 changes: 7 additions & 7 deletions src/components/loading/loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class Loading extends ViewController {
@Component({
selector: 'ion-loading',
template:
'<div disable-activated class="backdrop" [class.hide-backdrop]="!d.showBackdrop" role="presentation"></div>' +
'<ion-backdrop [class.hide-backdrop]="!d.showBackdrop"></ion-backdrop>' +
'<div class="loading-wrapper">' +
'<div *ngIf="showSpinner" class="loading-spinner">' +
'<ion-spinner [name]="d.spinner"></ion-spinner>' +
Expand Down Expand Up @@ -240,7 +240,7 @@ export interface LoadingOptions {
super(opts);

let ele = enteringView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.loading-wrapper'));

wrapper.fromTo('opacity', '0.01', '1').fromTo('scale', '1.1', '1');
Expand All @@ -261,7 +261,7 @@ export interface LoadingOptions {
super(opts);

let ele = leavingView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.loading-wrapper'));

wrapper.fromTo('opacity', '1', '0').fromTo('scale', '1', '0.9');
Expand All @@ -282,7 +282,7 @@ export interface LoadingOptions {
super(opts);

let ele = enteringView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.loading-wrapper'));

wrapper.fromTo('opacity', '0.01', '1').fromTo('scale', '1.1', '1');
Expand All @@ -303,7 +303,7 @@ export interface LoadingOptions {
super(opts);

let ele = leavingView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.loading-wrapper'));

wrapper.fromTo('opacity', '1', '0').fromTo('scale', '1', '0.9');
Expand All @@ -324,7 +324,7 @@ export interface LoadingOptions {
super(opts);

let ele = enteringView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.loading-wrapper'));

wrapper.fromTo('opacity', '0.01', '1').fromTo('scale', '1.3', '1');
Expand All @@ -345,7 +345,7 @@ export interface LoadingOptions {
super(opts);

let ele = leavingView.pageRef().nativeElement;
let backdrop = new Animation(ele.querySelector('.backdrop'));
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
let wrapper = new Animation(ele.querySelector('.loading-wrapper'));

wrapper.fromTo('opacity', '1', '0').fromTo('scale', '1', '1.3');
Expand Down
6 changes: 3 additions & 3 deletions src/components/menu/menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ion-menu[side=right] {
left: auto;
}

ion-menu .backdrop {
ion-menu ion-backdrop {
z-index: -1;
display: none;
}
Expand Down Expand Up @@ -74,13 +74,13 @@ ion-menu[type=overlay] {
left: -8px; // make up for the box-shadow hanging over on the left
z-index: $z-index-menu-overlay;

.backdrop {
ion-backdrop {
left: -3000px;
display: block;

width: 6000px;

opacity: .01;
opacity: 0.01;
transform: translate3d(-9999px, 0, 0);

&.show-backdrop {
Expand Down
Loading

0 comments on commit a1a582b

Please sign in to comment.