Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

Commit

Permalink
refactor(dialog): Refactor and export focus-trap for Rollup AoT bundle (
Browse files Browse the repository at this point in the history
  • Loading branch information
trimox authored Aug 18, 2017
1 parent 7d5f7a7 commit e4fcf9b
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/lib/dialog/dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@ import {
} from '@angular/core';
import { isBrowser } from '../common/platform';
import { EventRegistry } from '../common/event-registry';
import * as createFocusTrap from 'focus-trap';
import focusTrap from 'focus-trap';

import { Ripple } from '.././ripple/ripple.directive';
import { ButtonComponent } from '../button/button.component';

import { MDCDialogAdapter } from './dialog-adapter';
import { MDCDialogFoundation } from '@material/dialog';

export function createFocusTrapInstance(surfaceEl, acceptButtonEl, clickOutsideCloses, focusTrapFactory = createFocusTrap) {
return focusTrapFactory(surfaceEl, {
initialFocus: acceptButtonEl,
clickOutsideDeactivates: clickOutsideCloses,
});
}
export { focusTrap };

@Directive({
selector: '[mdc-dialog-surface], mdc-dialog-surface'
Expand Down Expand Up @@ -261,10 +256,12 @@ export class DialogComponent implements AfterViewInit, OnDestroy {
}

show() {
this.focusTrap_ = createFocusTrapInstance(this.dialogSurface.elementRef.nativeElement,
this.dialogAcceptButton ? this.dialogAcceptButton.elementRef.nativeElement :
this.focusTrap_ = focusTrap(this.dialogSurface.elementRef.nativeElement, {
initialFocus: this.dialogAcceptButton ? this.dialogAcceptButton.elementRef.nativeElement :
this.dialogButtons.length > 0 ? this.dialogButtons.find((_) => _.accept).elementRef.nativeElement
: this.dialogSurface.elementRef.nativeElement, this.clickOutsideToClose);
: this.dialogSurface.elementRef.nativeElement,
clickOutsideDeactivates: this.clickOutsideToClose,
});
this._foundation.open();
}

Expand Down

0 comments on commit e4fcf9b

Please sign in to comment.