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

feat(util): make common the enum Key #2473

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 1 addition & 4 deletions src/datepicker/datepicker-input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {createGenericTestComponent} from '../test/common';

import {Component, Injectable} from '@angular/core';
import {FormsModule, NgForm} from '@angular/forms';
import {Key} from '../util/key';

import {NgbDateAdapter, NgbDatepickerModule} from './datepicker.module';
import {NgbInputDatepicker} from './datepicker-input';
Expand All @@ -17,10 +18,6 @@ const createTestCmpt = (html: string) =>
const createTestNativeCmpt = (html: string) =>
createGenericTestComponent(html, TestNativeComponent) as ComponentFixture<TestNativeComponent>;

enum Key {
Escape = 27
}

function dispatchKeyUpEvent(key: Key) {
const event = document.createEvent('KeyboardEvent') as any;
let initEventFn = (event.initKeyEvent || event.initKeyboardEvent).bind(event);
Expand Down
5 changes: 1 addition & 4 deletions src/datepicker/datepicker-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {NgbDateParserFormatter} from './ngb-date-parser-formatter';

import {positionElements, PlacementArray} from '../util/positioning';
import {ngbFocusTrap} from '../util/focus-trap';
import {Key} from '../util/key';
import {NgbDateStruct} from './ngb-date-struct';
import {NgbDateAdapter} from './adapters/ngb-date-adapter';
import {NgbCalendar} from './ngb-calendar';
Expand All @@ -46,10 +47,6 @@ const NGB_DATEPICKER_VALIDATOR = {
multi: true
};

enum Key {
Escape = 27
}

/**
* A directive that makes it possible to have datepickers on input fields.
* Manages integration with the input field itself (data entry) and ngModel (validation etc.).
Expand Down
14 changes: 1 addition & 13 deletions src/datepicker/datepicker-keymap-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,7 @@ import {NgbDatepickerService} from './datepicker-service';
import {TestBed} from '@angular/core/testing';
import {Subject} from 'rxjs';
import {NgbDate} from './ngb-date';

enum Key {
Enter = 13,
Space = 32,
PageUp = 33,
PageDown = 34,
End = 35,
Home = 36,
ArrowLeft = 37,
ArrowUp = 38,
ArrowRight = 39,
ArrowDown = 40
}
import {Key} from '../util/key';

const event = (keyCode: number, shift = false) =>
<any>({which: keyCode, shiftKey: shift, preventDefault: () => {}, stopPropagation: () => {}});
Expand Down
14 changes: 1 addition & 13 deletions src/datepicker/datepicker-keymap-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@ import {Injectable} from '@angular/core';
import {NgbDatepickerService} from './datepicker-service';
import {NgbCalendar} from './ngb-calendar';
import {toString} from '../util/util';
import {Key} from '../util/key';
import {NgbDate} from './ngb-date';

enum Key {
Enter = 13,
Space = 32,
PageUp = 33,
PageDown = 34,
End = 35,
Home = 36,
ArrowLeft = 37,
ArrowUp = 38,
ArrowRight = 39,
ArrowDown = 40
}

@Injectable()
export class NgbDatepickerKeyMapService {
private _minDate: NgbDate;
Expand Down
10 changes: 1 addition & 9 deletions src/rating/rating.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {TestBed, ComponentFixture, inject, async, fakeAsync, tick} from '@angular/core/testing';
import {createGenericTestComponent} from '../test/common';
import {Key} from '../util/key';

import {Component, DebugElement} from '@angular/core';
import {FormsModule, ReactiveFormsModule, FormGroup, FormControl, Validators} from '@angular/forms';
Expand All @@ -12,15 +13,6 @@ import {By} from '@angular/platform-browser';
const createTestComponent = (html: string) =>
createGenericTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;

enum Key {
End = 35,
Home = 36,
ArrowLeft = 37,
ArrowUp = 38,
ArrowRight = 39,
ArrowDown = 40
}

function createKeyDownEvent(key: number) {
const event = {which: key, preventDefault: () => {}};
spyOn(event, 'preventDefault');
Expand Down
10 changes: 1 addition & 9 deletions src/rating/rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,9 @@ import {
} from '@angular/core';
import {NgbRatingConfig} from './rating-config';
import {toString, getValueInRange} from '../util/util';
import {Key} from '../util/key';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';

enum Key {
End = 35,
Home = 36,
ArrowLeft = 37,
ArrowUp = 38,
ArrowRight = 39,
ArrowDown = 40
}

/**
* Context for the custom star display template
*/
Expand Down
9 changes: 1 addition & 8 deletions src/typeahead/typeahead.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {NgbTypeaheadConfig} from './typeahead-config';
import {debounceTime, filter, map, merge} from 'rxjs/operators';

import {ARIA_LIVE_DELAY} from '../util/accessibility/live';
import {Key} from '../util/key';

const createTestComponent = (html: string) =>
createGenericTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
Expand All @@ -23,14 +24,6 @@ const createOnPushTestComponent = (html: string) =>
const createAsyncTestComponent = (html: string) =>
createGenericTestComponent(html, TestAsyncComponent) as ComponentFixture<TestAsyncComponent>;

enum Key {
Tab = 9,
Enter = 13,
Escape = 27,
ArrowUp = 38,
ArrowDown = 40
}

function createKeyDownEvent(key: number) {
const event = {which: key, preventDefault: () => {}, stopPropagation: () => {}};
spyOn(event, 'preventDefault');
Expand Down
9 changes: 1 addition & 8 deletions src/typeahead/typeahead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,11 @@ import {positionElements, PlacementArray} from '../util/positioning';
import {NgbTypeaheadWindow, ResultTemplateContext} from './typeahead-window';
import {PopupService} from '../util/popup';
import {toString, isDefined} from '../util/util';
import {Key} from '../util/key';
import {Live} from '../util/accessibility/live';
import {NgbTypeaheadConfig} from './typeahead-config';
import {map, switchMap, tap} from 'rxjs/operators';

enum Key {
Tab = 9,
Enter = 13,
Escape = 27,
ArrowUp = 38,
ArrowDown = 40
}

const NGB_TYPEAHEAD_VALUE_ACCESSOR = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => NgbTypeahead),
Expand Down
5 changes: 1 addition & 4 deletions src/util/focus-trap.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {fromEvent, Observable} from 'rxjs';
import {filter, map, takeUntil, withLatestFrom} from 'rxjs/operators';

enum Key {
Tab = 9
}
import {Key} from '../util/key';

const FOCUSABLE_ELEMENTS_SELECTOR = [
'a[href]', 'button:not([disabled])', 'input:not([disabled]):not([type="hidden"])', 'select:not([disabled])',
Expand Down
14 changes: 14 additions & 0 deletions src/util/key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export enum Key {
Tab = 9,
Enter = 13,
Escape = 27,
Space = 32,
PageUp = 33,
PageDown = 34,
End = 35,
Home = 36,
ArrowLeft = 37,
ArrowUp = 38,
ArrowRight = 39,
ArrowDown = 40
}