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

fix(overlay): default options not being applied correctly #9088

Merged
merged 1 commit into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/cdk/overlay/overlay-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export class OverlayConfig {

constructor(config?: OverlayConfig) {
if (config) {
Object.keys(config).forEach(key => this[key] = config[key]);
Object.keys(config)
.filter(key => typeof config[key] !== 'undefined')
.forEach(key => this[key] = config[key]);
}
}
}
10 changes: 10 additions & 0 deletions src/cdk/overlay/overlay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ describe('Overlay', () => {
expect(callbackOrder).toEqual(['attach', 'detach']);
});

it('should default to the ltr direction', () => {
const overlayRef = overlay.create({hasBackdrop: true});
expect(overlayRef.getConfig().direction).toBe('ltr');
});

it('should skip undefined values when applying the defaults', () => {
const overlayRef = overlay.create({direction: undefined});
expect(overlayRef.getConfig().direction).toBe('ltr');
});

describe('positioning', () => {
let config: OverlayConfig;

Expand Down
9 changes: 3 additions & 6 deletions src/cdk/overlay/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ import {DOCUMENT} from '@angular/common';
/** Next overlay unique ID. */
let nextUniqueId = 0;

/** The default config for newly created overlays. */
let defaultConfig = new OverlayConfig();


/**
* Service to create Overlays. Overlays are dynamically added pieces of floating UI, meant to be
* used as a low-level building building block for other components. Dialogs, tooltips, menus,
Expand Down Expand Up @@ -58,10 +54,11 @@ export class Overlay {
* @param config Configuration applied to the overlay.
* @returns Reference to the created overlay.
*/
create(config: OverlayConfig = defaultConfig): OverlayRef {
create(config?: OverlayConfig): OverlayRef {
const pane = this._createPaneElement();
const portalOutlet = this._createPortalOutlet(pane);
return new OverlayRef(portalOutlet, pane, config, this._ngZone, this._keyboardDispatcher);
return new OverlayRef(portalOutlet, pane, new OverlayConfig(config), this._ngZone,
this._keyboardDispatcher);
}

/**
Expand Down