Skip to content

Commit

Permalink
fix(common): prevent deprecated also fixed test (datepicker close on …
Browse files Browse the repository at this point in the history
…esc) for IE11 (souce tests) (#4940)

* fix(common): prevent deprecated

* fix(test): fix test related with keyCode
  • Loading branch information
Domainv authored and valorkin committed Jan 14, 2019
1 parent 5f6a781 commit d338dbf
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class DemoRatingSelectOnEnterComponent {
isReadonly = false;

confirmSelection(event: KeyboardEvent) {
if (event.keyCode === 13) {
if (event.keyCode === 13 || event.key === 'Enter') {
this.isReadonly = true;
}
}
Expand Down
106 changes: 84 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"@angular/router": "6.0.1",
"@angular/service-worker": "6.0.1",
"@cypress/webpack-preprocessor": "3.0.1",
"@netbasal/spectator": "2.2.0-rc.2",
"@nguniversal/express-engine": "6.0.0",
"@nguniversal/module-map-ngfactory-loader": "6.0.0",
"@schematics/angular": "0.8.5",
Expand Down
7 changes: 2 additions & 5 deletions src/datepicker/bs-datepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BsDatepickerConfig, BsDatepickerDirective, BsDatepickerModule } from '.';
import { BsDatepickerContainerComponent } from './themes/bs/bs-datepicker-container.component';
import { CalendarCellViewModel } from './models';
import { dispatchKeyboardEvent } from '@netbasal/spectator';
import { registerEscClick } from '../utils';

@Component({
Expand Down Expand Up @@ -94,11 +95,7 @@ describe('datepicker:', () => {
hide: () => datepicker.hide()
});

const event = new KeyboardEvent('keyup', {
key: 'Escape'
});

document.dispatchEvent(event);
dispatchKeyboardEvent(document, 'keyup', 'Escape');

expect(spy).toHaveBeenCalled();
}));
Expand Down
20 changes: 10 additions & 10 deletions src/typeahead/typeahead.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,35 +205,35 @@ export class TypeaheadDirective implements OnInit, OnDestroy {
}

@HostListener('keyup', ['$event'])
onChange(e: KeyboardEvent): void {
onChange(event: KeyboardEvent): void {
if (this._container) {
// esc
/* tslint:disable-next-line: deprecation */
if (e.keyCode === 27) {
if (event.keyCode === 27 || event.key === 'Escape') {
this.hide();

return;
}

// up
/* tslint:disable-next-line: deprecation */
if (e.keyCode === 38) {
if (event.keyCode === 38 || event.key === 'ArrowUp') {
this._container.prevActiveMatch();

return;
}

// down
/* tslint:disable-next-line: deprecation */
if (e.keyCode === 40) {
if (event.keyCode === 40 || event.key === 'ArrowDown') {
this._container.nextActiveMatch();

return;
}

// enter, tab
/* tslint:disable-next-line: deprecation */
if (e.keyCode === 13) {
if (event.keyCode === 13 || event.key === 'Enter') {
this._container.selectActiveMatch();

return;
Expand All @@ -258,24 +258,24 @@ export class TypeaheadDirective implements OnInit, OnDestroy {
}

@HostListener('keydown', ['$event'])
onKeydown(e: KeyboardEvent): void {
onKeydown(event: KeyboardEvent): void {
// no container - no problems
if (!this._container) {
return;
}

// if an item is visible - prevent form submission
/* tslint:disable-next-line: deprecation */
if (e.keyCode === 13) {
e.preventDefault();
if (event.keyCode === 13 || event.key === 'Enter') {
event.preventDefault();

return;
}

// if an item is visible - don't change focus
/* tslint:disable-next-line: deprecation */
if (e.keyCode === 9) {
e.preventDefault();
if (event.keyCode === 9 || event.key === 'Tab') {
event.preventDefault();
this._container.selectActiveMatch();

return;
Expand Down

0 comments on commit d338dbf

Please sign in to comment.