Skip to content

Commit

Permalink
feat: add angular/cdk (#153)
Browse files Browse the repository at this point in the history
* fix(modal): Focus fields beyond the modal window #UIM-11 (#154)
  • Loading branch information
pimenovoleg authored Jun 27, 2019
1 parent e0b3071 commit ef06e63
Show file tree
Hide file tree
Showing 235 changed files with 368 additions and 14,574 deletions.
4 changes: 2 additions & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

#### NPM
```bash
npm install --save @ptsecurity/mosaic @ptsecurity/cdk @ptsecurity/mosaic-icons @ptsecurity/mosaic-moment-adapter moment messageformat
npm install --save @angular/cdk @ptsecurity/mosaic @ptsecurity/cdk @ptsecurity/mosaic-icons @ptsecurity/mosaic-moment-adapter moment messageformat
```

#### Yarn
```bash
yarn add @ptsecurity/mosaic @ptsecurity/cdk @ptsecurity/mosaic-icons @ptsecurity/mosaic-moment-adapter moment messageformat
yarn add @angular/cdk @ptsecurity/mosaic @ptsecurity/cdk @ptsecurity/mosaic-icons @ptsecurity/mosaic-moment-adapter moment messageformat
```

#### Snapshots builds
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"requiredAngularVersion": ">=8.0.0",
"dependencies": {
"@angular/animations": "^8.0.0",
"@angular/cdk": "^8.0.1",
"@angular/common": "^8.0.0",
"@angular/compiler": "^8.0.0",
"@angular/core": "^8.0.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/cdk/a11y/a11y-module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import { PlatformModule } from '@angular/cdk/platform';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { PlatformModule } from '@ptsecurity/cdk/platform';

import { CdkMonitorFocus, FOCUS_MONITOR_PROVIDER } from './focus-monitor/focus-monitor';

Expand Down
60 changes: 29 additions & 31 deletions packages/cdk/a11y/focus-monitor/focus-monitor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Platform, supportsPassiveEventListeners } from '@angular/cdk/platform';
import {
Directive,
ElementRef,
Expand All @@ -9,11 +10,8 @@ import {
Output,
SkipSelf
} from '@angular/core';

import { Observable, Subject, Subscription, of as observableOf } from 'rxjs';

import { Platform, supportsPassiveEventListeners } from '@ptsecurity/cdk/platform';


// Through trial and error (on iPhone 6S) they found
// that a value of around 650ms seems appropriate.
Expand All @@ -23,11 +21,11 @@ export const TOUCH_BUFFER_MS = 650;
export type FocusOrigin = 'touch' | 'mouse' | 'keyboard' | 'program' | null;


type MonitoredElementInfo = {
unlisten: Function,
checkChildren: boolean,
subject: Subject<FocusOrigin>
};
interface MonitoredElementInfo {
unlisten: Function;
checkChildren: boolean;
subject: Subject<FocusOrigin>;
}


/** Monitors mouse and keyboard events to determine the cause of focus events. */
Expand Down Expand Up @@ -57,9 +55,6 @@ export class FocusMonitor implements OnDestroy {
/** Map of elements being monitored to their info. */
private _elementInfo = new Map<HTMLElement, MonitoredElementInfo>();

/** A map of global objects to lists of current listeners. */
private _unregisterGlobalListeners = () => {};

/** The number of elements currently being monitored. */
private _monitoredElementCount = 0;

Expand Down Expand Up @@ -87,7 +82,7 @@ export class FocusMonitor implements OnDestroy {
// Create monitored element info.
const info: MonitoredElementInfo = {
unlisten: () => {},
checkChildren: checkChildren,
checkChildren,
subject: new Subject<FocusOrigin>()
};
this._elementInfo.set(element, info);
Expand Down Expand Up @@ -145,6 +140,28 @@ export class FocusMonitor implements OnDestroy {
this._elementInfo.forEach((_info, element) => this.stopMonitoring(element));
}

/**
* Handles blur events on a registered element.
* @param event The blur event.
* @param element The monitored element.
*/
_onBlur(event: FocusEvent, element: HTMLElement) {
// If we are counting child-element-focus as focused, make sure that we aren't just blurring in
// order to focus another child of the monitored element.
const elementInfo = this._elementInfo.get(element);

if (!elementInfo || (elementInfo.checkChildren && event.relatedTarget instanceof Node &&
element.contains(event.relatedTarget))) {
return;
}

this._setClasses(element);
elementInfo.subject.next(null);
}

/** A map of global objects to lists of current listeners. */
private _unregisterGlobalListeners = () => {};

/** Register necessary event listeners on the document and window. */
private _registerGlobalListeners() {
// Do nothing if we're not on the browser platform.
Expand Down Expand Up @@ -315,25 +332,6 @@ export class FocusMonitor implements OnDestroy {
this._lastFocusOrigin = origin;
}

/**
* Handles blur events on a registered element.
* @param event The blur event.
* @param element The monitored element.
*/
_onBlur(event: FocusEvent, element: HTMLElement) {
// If we are counting child-element-focus as focused, make sure that we aren't just blurring in
// order to focus another child of the monitored element.
const elementInfo = this._elementInfo.get(element);

if (!elementInfo || (elementInfo.checkChildren && event.relatedTarget instanceof Node &&
element.contains(event.relatedTarget))) {
return;
}

this._setClasses(element);
elementInfo.subject.next(null);
}

private _emitOrigin(subject: Subject<FocusOrigin>, origin: FocusOrigin) {
this._ngZone.run(() => subject.next(origin));
}
Expand Down
Loading

0 comments on commit ef06e63

Please sign in to comment.