Skip to content

Commit

Permalink
refactor(overlay): simplify focusOutActiveElement (#12023)
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat authored Jun 15, 2017
1 parent 7a1342c commit 2743c63
Show file tree
Hide file tree
Showing 13 changed files with 6 additions and 39 deletions.
2 changes: 0 additions & 2 deletions src/components/action-sheet/action-sheet-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ export class ActionSheetCmp {
}

ionViewDidEnter() {
this._plt.focusOutActiveElement();

const focusableEle = this._elementRef.nativeElement.querySelector('button');
if (focusableEle) {
focusableEle.focus();
Expand Down
8 changes: 0 additions & 8 deletions src/components/alert/alert-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,10 @@ export class AlertCmp {
}

ionViewDidLeave() {
this._plt.focusOutActiveElement();
this.gestureBlocker.unblock();
}

ionViewWillLeave() {
this._plt.focusOutActiveElement();
}

ionViewDidEnter() {
// focus out of the active element
this._plt.focusOutActiveElement();

// set focus on the first input or button in the alert
// note that this does not always work and bring up the keyboard on
// devices since the focus command must come from the user's touch event
Expand Down
3 changes: 1 addition & 2 deletions src/components/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,14 @@ export class App {
// TODO: move _setNav() to the earlier stages of NavController. _queueTrns()
enteringView._setNav(portal);

opts.keyboardClose = false;
opts.direction = DIRECTION_FORWARD;

if (!opts.animation) {
opts.animation = enteringView.getTransitionName(DIRECTION_FORWARD);
}

enteringView.setLeavingOpts({
keyboardClose: false,
keyboardClose: opts.keyboardClose,
direction: DIRECTION_BACK,
animation: enteringView.getTransitionName(DIRECTION_BACK),
ev: opts.ev
Expand Down
4 changes: 1 addition & 3 deletions src/components/app/overlay-portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Config } from '../../config/config';
import { DeepLinker } from '../../navigation/deep-linker';
import { DomController } from '../../platform/dom-controller';
import { GestureController } from '../../gestures/gesture-controller';
import { Keyboard } from '../../platform/keyboard';
import { NavControllerBase } from '../../navigation/nav-controller-base';
import { Platform } from '../../platform/platform';
import { TransitionController } from '../../transitions/transition-controller';
Expand All @@ -22,7 +21,6 @@ export class OverlayPortal extends NavControllerBase {
@Inject(forwardRef(() => App)) app: App,
config: Config,
plt: Platform,
keyboard: Keyboard,
elementRef: ElementRef,
zone: NgZone,
renderer: Renderer,
Expand All @@ -34,7 +32,7 @@ export class OverlayPortal extends NavControllerBase {
domCtrl: DomController,
errHandler: ErrorHandler
) {
super(null, app, config, plt, keyboard, elementRef, zone, renderer, cfr, gestureCtrl, transCtrl, linker, domCtrl, errHandler);
super(null, app, config, plt, elementRef, zone, renderer, cfr, gestureCtrl, transCtrl, linker, domCtrl, errHandler);
this._isPortal = true;
this._init = true;
this.setViewport(viewPort);
Expand Down
2 changes: 0 additions & 2 deletions src/components/loading/loading-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ export class LoadingCmp {
}

ionViewDidEnter() {
this._plt.focusOutActiveElement();

// If there is a duration, dismiss after that amount of time
if ( this.d && this.d.duration ) {
this.durationTimeout = setTimeout(() => this.dismiss('backdrop'), this.d.duration);
Expand Down
4 changes: 1 addition & 3 deletions src/components/nav/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Config } from '../../config/config';
import { DeepLinker } from '../../navigation/deep-linker';
import { DomController } from '../../platform/dom-controller';
import { GestureController } from '../../gestures/gesture-controller';
import { Keyboard } from '../../platform/keyboard';
import { Nav as INav } from '../../navigation/nav-interfaces';
import { NavController } from '../../navigation/nav-controller';
import { NavControllerBase } from '../../navigation/nav-controller-base';
Expand Down Expand Up @@ -66,7 +65,6 @@ export class Nav extends NavControllerBase implements AfterViewInit, RootNode, I
app: App,
config: Config,
plt: Platform,
keyboard: Keyboard,
elementRef: ElementRef,
zone: NgZone,
renderer: Renderer,
Expand All @@ -77,7 +75,7 @@ export class Nav extends NavControllerBase implements AfterViewInit, RootNode, I
domCtrl: DomController,
errHandler: ErrorHandler
) {
super(parent, app, config, plt, keyboard, elementRef, zone, renderer, cfr, gestureCtrl, transCtrl, linker, domCtrl, errHandler);
super(parent, app, config, plt, elementRef, zone, renderer, cfr, gestureCtrl, transCtrl, linker, domCtrl, errHandler);

if (viewCtrl) {
// an ion-nav can also act as an ion-page within a parent ion-nav
Expand Down
3 changes: 0 additions & 3 deletions src/components/nav/test/nav.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Nav } from '../nav';

import { GestureController } from '../../../gestures/gesture-controller';
import { Keyboard } from '../../../platform/keyboard';
import {
mockApp,
mockConfig,
Expand Down Expand Up @@ -88,7 +87,6 @@ function getNav() {
const app = mockApp(config, platform);
const zone = mockZone();
const dom = mockDomController(platform);
const keyboard = new Keyboard(config, platform, zone, dom);
const elementRef = mockElementRef();
const renderer = mockRenderer();
const componentFactoryResolver: any = null;
Expand All @@ -101,7 +99,6 @@ function getNav() {
app,
config,
platform,
keyboard,
elementRef,
zone,
renderer,
Expand Down
2 changes: 0 additions & 2 deletions src/components/picker/picker-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ export class PickerCmp {
}

ionViewDidEnter() {
this._plt.focusOutActiveElement();

let focusableEle = this._elementRef.nativeElement.querySelector('button');
if (focusableEle) {
focusableEle.focus();
Expand Down
1 change: 0 additions & 1 deletion src/components/popover/popover-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export class PopoverCmp {
}

ionViewPreLoad() {
this._plt.focusOutActiveElement();
this._load(this._navParams.data.component);
}

Expand Down
4 changes: 1 addition & 3 deletions src/components/tabs/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { DeepLinker } from '../../navigation/deep-linker';
import { DomController } from '../../platform/dom-controller';
import { GestureController } from '../../gestures/gesture-controller';
import { isTrueProperty } from '../../util/util';
import { Keyboard } from '../../platform/keyboard';
import { Tab as ITab } from '../../navigation/nav-interfaces';
import { NavControllerBase } from '../../navigation/nav-controller-base';
import { NavOptions } from '../../navigation/nav-util';
Expand Down Expand Up @@ -255,7 +254,6 @@ export class Tab extends NavControllerBase implements ITab {
app: App,
config: Config,
plt: Platform,
keyboard: Keyboard,
elementRef: ElementRef,
zone: NgZone,
renderer: Renderer,
Expand All @@ -268,7 +266,7 @@ export class Tab extends NavControllerBase implements ITab {
errHandler: ErrorHandler
) {
// A Tab is a NavController for its child pages
super(parent, app, config, plt, keyboard, elementRef, zone, renderer, cfr, gestureCtrl, transCtrl, linker, _dom, errHandler);
super(parent, app, config, plt, elementRef, zone, renderer, cfr, gestureCtrl, transCtrl, linker, _dom, errHandler);

this.id = parent.add(this);
this._tabsHideOnSubPages = config.getBoolean('tabsHideOnSubPages');
Expand Down
1 change: 1 addition & 0 deletions src/components/toast/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class Toast extends ViewController {
*/
present(navOptions: NavOptions = {}): Promise<any> {
navOptions.disableApp = false;
navOptions.keyboardClose = false;
return this._app.present(this, navOptions, PORTAL_TOAST);
}

Expand Down
4 changes: 1 addition & 3 deletions src/navigation/nav-controller-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { GestureController } from '../gestures/gesture-controller';
import { isBlank, isNumber, isPresent, isTrueProperty, assert, removeArrayItem } from '../util/util';
import { isViewController, ViewController } from './view-controller';
import { Ion } from '../components/ion';
import { Keyboard } from '../platform/keyboard';
import { NavController } from './nav-controller';
import { NavParams } from './nav-params';
import { Platform } from '../platform/platform';
Expand Down Expand Up @@ -63,7 +62,6 @@ export class NavControllerBase extends Ion implements NavController {
public _app: App,
public config: Config,
public plt: Platform,
public _keyboard: Keyboard,
elementRef: ElementRef,
public _zone: NgZone,
renderer: Renderer,
Expand Down Expand Up @@ -760,7 +758,7 @@ export class NavControllerBase extends Ion implements NavController {
if (opts.keyboardClose !== false) {
// the keyboard is still open!
// no problem, let's just close for them
this._keyboard.close();
this.plt.focusOutActiveElement();
}
}

Expand Down
7 changes: 0 additions & 7 deletions src/util/mock-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { DomController } from '../platform/dom-controller';
import { GestureController } from '../gestures/gesture-controller';
import { Haptic } from '../tap-click/haptic';
import { IonicApp } from '../components/app/app-root';
import { Keyboard } from '../platform/keyboard';
import { Menu } from '../components/menu/menu';
import { NavOptions } from '../navigation/nav-util';
import { NavControllerBase } from '../navigation/nav-controller-base';
Expand Down Expand Up @@ -403,7 +402,6 @@ export function mockNavController(): NavControllerBase {
let app = mockApp(config, platform);
let zone = mockZone();
let dom = mockDomController(platform);
let keyboard = new Keyboard(config, platform, zone, dom);
let elementRef = mockElementRef();
let renderer = mockRenderer();
let componentFactoryResolver: any = null;
Expand All @@ -415,7 +413,6 @@ export function mockNavController(): NavControllerBase {
app,
config,
platform,
keyboard,
elementRef,
zone,
renderer,
Expand Down Expand Up @@ -447,7 +444,6 @@ export function mockNavController(): NavControllerBase {
export function mockOverlayPortal(app: App, config: Config, plt: MockPlatform): OverlayPortal {
let zone = mockZone();
let dom = mockDomController(plt);
let keyboard = new Keyboard(config, plt, zone, dom);
let elementRef = mockElementRef();
let renderer = mockRenderer();
let componentFactoryResolver: any = null;
Expand All @@ -460,7 +456,6 @@ export function mockOverlayPortal(app: App, config: Config, plt: MockPlatform):
app,
config,
plt,
keyboard,
elementRef,
zone,
renderer,
Expand All @@ -480,7 +475,6 @@ export function mockTab(parentTabs: Tabs): Tab {
let app = (<any>parentTabs)._app || mockApp(config, platform);
let zone = mockZone();
let dom = mockDomController(platform);
let keyboard = new Keyboard(config, platform, zone, dom);
let elementRef = mockElementRef();
let renderer = mockRenderer();
let changeDetectorRef = mockChangeDetectorRef();
Expand All @@ -493,7 +487,6 @@ export function mockTab(parentTabs: Tabs): Tab {
app,
config,
platform,
keyboard,
elementRef,
zone,
renderer,
Expand Down

0 comments on commit 2743c63

Please sign in to comment.