Skip to content

fix(datepicker): no input focus after close #124

Merged
merged 4 commits into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion packages/dev-app/system-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ System.config({
'main': 'main.js',
'tslib': 'node:tslib/tslib.js',
'moment': 'node:moment/min/moment-with-locales.min.js',
'messageformat': 'node:messageformat/messageformat.min.js',
'messageformat': 'node:messageformat/messageformat.js',

'rxjs': 'node_modules/rxjs/bundles/rxjs.umd.min.js',
'rxjs/operators': 'system-rxjs-operators.js',
Expand Down
18 changes: 12 additions & 6 deletions packages/mosaic/datepicker/datepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ describe('McDatepicker', () => {
flush();
}));

it('should focus input after close', fakeAsync(() => {
testComponent.datepicker.open();
fixture.detectChanges();

testComponent.datepicker.close();
fixture.detectChanges();

flush();

expect(document.activeElement).toBe(testComponent.datepicker.datepickerInput.elementRef.nativeElement);
}));

it('open non-touch should open popup', () => {
expect(document.querySelector('.cdk-overlay-pane.mc-datepicker__popup')).toBeNull();

Expand Down Expand Up @@ -1228,12 +1240,6 @@ describe('McDatepicker', () => {
}));

it('should not reopen if the browser fires the focus event asynchronously', fakeAsync(() => {
// Stub out the real focus method so we can call it reliably.
spyOn(input, 'focus').and.callFake(() => {
// Dispatch the event handler async to simulate the IE11 behavior.
Promise.resolve().then(() => dispatchFakeEvent(input, 'focus'));
});

// Open initially by focusing.
input.focus();
fixture.detectChanges();
Expand Down
2 changes: 2 additions & 0 deletions packages/mosaic/datepicker/datepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ export class McDatepicker<D> implements OnDestroy, CanColor {
this._opened = false;
this.closedStream.emit();
this.focusedElementBeforeOpen = null;

this.datepickerInput.elementRef.nativeElement.focus();
}
};

Expand Down
2 changes: 1 addition & 1 deletion tests/karma-system-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ System.config({
'rxjs': 'node:rxjs',
'tslib': 'node:tslib/tslib.js',
'moment': 'node:moment/min/moment-with-locales.min.js',
'messageformat': 'node:messageformat/messageformat.min.js',
'messageformat': 'node:messageformat/messageformat.js',

// Angular specific mappings.
'@angular/core': 'node:@angular/core/bundles/core.umd.js',
Expand Down
2 changes: 1 addition & 1 deletion tests/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = (config) => {
{pattern: 'node_modules/zone.js/dist/async-test.js', included: true, watched: false},
{pattern: 'node_modules/zone.js/dist/fake-async-test.js', included: true, watched: false},
{pattern: 'node_modules/moment/min/moment-with-locales.min.js', included: false, watched: false},
{pattern: 'node_modules/messageformat/messageformat.min.js', included: false, watched: false},
{pattern: 'node_modules/messageformat/messageformat.js', included: false, watched: false},
pimenovoleg marked this conversation as resolved.
Show resolved Hide resolved

// Include all Angular dependencies
{pattern: 'node_modules/@angular/**/*', included: false, watched: false},
Expand Down
Loading