Skip to content
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
7,748 changes: 3,134 additions & 4,614 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,14 +26,14 @@
"node": ">= 5.4.1"
},
"dependencies": {
"@angular/animations": ">=6.0.0-beta.7 <7.0.0",
"@angular/common": ">=6.0.0-beta.7 <7.0.0",
"@angular/compiler": ">=6.0.0-beta.7 <7.0.0",
"@angular/core": ">=6.0.0-beta.7 <7.0.0",
"@angular/forms": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-browser": ">=6.0.0-beta.7 <7.0.0",
"@angular/animations": "6.0.0-beta.8",
"@angular/common": "6.0.0-beta.8",
"@angular/compiler": "6.0.0-beta.8",
"@angular/core": "6.0.0-beta.8",
"@angular/forms": "6.0.0-beta.8",
"@angular/platform-browser": "6.0.0-beta.8",
"core-js": "^2.4.1",
"rxjs": "^5.5.5",
"rxjs": "^5.5.7",
"systemjs": "0.19.43",
"tsickle": "^0.24.x",
"tslib": "^1.7.1",
Expand All@@ -42,11 +42,11 @@
"devDependencies": {
"@angular-devkit/core": "^0.4.5",
"@angular-devkit/schematics": "^0.4.5",
"@angular/bazel": ">=6.0.0-beta.7 <7.0.0",
"@angular/compiler-cli": ">=6.0.0-beta.7 <7.0.0",
"@angular/http": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-browser-dynamic": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-server": ">=6.0.0-beta.7 <7.0.0",
"@angular/bazel": "6.0.0-beta.8",
"@angular/compiler-cli": "6.0.0-beta.8",
"@angular/http": "6.0.0-beta.8",
"@angular/platform-browser-dynamic": "6.0.0-beta.8",
"@angular/platform-server": "6.0.0-beta.8",
"@angular/router": ">=6.0.0-beta.7 <7.0.0",
"@angular/upgrade": "^5.0.1",
"@bazel/ibazel": "0.3.1",
Expand DownExpand Up@@ -126,7 +126,7 @@
"tsconfig-paths": "^2.3.0",
"tslint": "^5.9.1",
"tsutils": "^2.6.0",
"typescript": "~2.6.0",
"typescript": "~2.7.0",
"uglify-js": "^2.8.14",
"web-animations-js": "^2.2.5"
}
Expand Down
15 changes: 2 additions & 13 deletions src/cdk/a11y/a11y-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,23 +9,12 @@
import {PlatformModule} from '@angular/cdk/platform';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {ARIA_DESCRIBER_PROVIDER, AriaDescriber} from './aria-describer/aria-describer';
import {CdkMonitorFocus, FOCUS_MONITOR_PROVIDER} from './focus-monitor/focus-monitor';
import {CdkTrapFocus, FocusTrapFactory} from './focus-trap/focus-trap';
import {InteractivityChecker} from './interactivity-checker/interactivity-checker';
import {LIVE_ANNOUNCER_PROVIDER} from './live-announcer/live-announcer';
import {CdkMonitorFocus} from './focus-monitor/focus-monitor';
import {CdkTrapFocus} from './focus-trap/focus-trap';

@NgModule({
imports: [CommonModule, PlatformModule],
declarations: [CdkTrapFocus, CdkMonitorFocus],
exports: [CdkTrapFocus, CdkMonitorFocus],
providers: [
InteractivityChecker,
FocusTrapFactory,
AriaDescriber,
LIVE_ANNOUNCER_PROVIDER,
ARIA_DESCRIBER_PROVIDER,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with how the app-wide providers work yet, but should the AriaDescriber still be set in the providers in this case? I believe that it's the only reason why, for example, the tooltip imports the A11yModule.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, module imports just for this kind of injectable shouldn't be necessary any more. I'll address those in my next PR that applies this to material.

FOCUS_MONITOR_PROVIDER,
]
})
export class A11yModule {}
16 changes: 12 additions & 4 deletions src/cdk/a11y/aria-describer/aria-describer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,10 +6,17 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable, Inject, InjectionToken, Optional, SkipSelf} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
Optional,
SkipSelf,
} from '@angular/core';
import {addAriaReferencedId, getAriaReferenceIds, removeAriaReferencedId} from './aria-reference';


/**
* Interface used to register message elements and keep a count of how many registrations have
* the same message and the reference to the message element used for the `aria-describedby`.
Expand DownExpand Up@@ -46,7 +53,7 @@ let messagesContainer: HTMLElement | null = null;
* content.
* @docs-private
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class AriaDescriber {
private _document: Document;

Expand DownExpand Up@@ -204,12 +211,13 @@ export class AriaDescriber {

}

/** @docs-private */

/** @docs-private @deprecated @deletion-target 7.0.0 */
export function ARIA_DESCRIBER_PROVIDER_FACTORY(parentDispatcher: AriaDescriber, _document: any) {
return parentDispatcher || new AriaDescriber(_document);
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const ARIA_DESCRIBER_PROVIDER = {
// If there is already an AriaDescriber available, use that. Otherwise, provide a new one.
provide: AriaDescriber,
Expand Down
7 changes: 4 additions & 3 deletions src/cdk/a11y/focus-monitor/focus-monitor.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {Platform, supportsPassiveEventListeners} from '@angular/cdk/platform';
import {
Directive,
Expand DownExpand Up@@ -39,7 +40,7 @@ type MonitoredElementInfo = {


/** Monitors mouse and keyboard events to determine the cause of focus events. */
@Injectable()
@Injectable({providedIn: 'root'})
export class FocusMonitor implements OnDestroy {
/** The focus origin that the next focus event is a result of. */
private _origin: FocusOrigin = null;
Expand DownExpand Up@@ -380,13 +381,13 @@ export class CdkMonitorFocus implements OnDestroy {
}
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export function FOCUS_MONITOR_PROVIDER_FACTORY(
parentDispatcher: FocusMonitor, ngZone: NgZone, platform: Platform) {
return parentDispatcher || new FocusMonitor(ngZone, platform);
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const FOCUS_MONITOR_PROVIDER = {
// If there is already a FocusMonitor available, use that. Otherwise, provide a new one.
provide: FocusMonitor,
Expand Down
12 changes: 6 additions & 6 deletions src/cdk/a11y/focus-trap/focus-trap.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,20 +6,20 @@
* found in the LICENSE file at https://angular.io/license
*/

import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {DOCUMENT} from '@angular/common';
import {
AfterContentInit,
Directive,
ElementRef,
Inject,
Injectable,
Input,
NgZone,
OnDestroy,
AfterContentInit,
Injectable,
Inject,
} from '@angular/core';
import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {take} from 'rxjs/operators/take';
import {InteractivityChecker} from '../interactivity-checker/interactivity-checker';
import {DOCUMENT} from '@angular/common';


/**
Expand DownExpand Up@@ -278,7 +278,7 @@ export class FocusTrap {


/** Factory that allows easy instantiation of focus traps. */
@Injectable()
@Injectable({providedIn: 'root'})
export class FocusTrapFactory {
private _document: Document;

Expand Down
4 changes: 2 additions & 2 deletions src/cdk/a11y/interactivity-checker/interactivity-checker.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable} from '@angular/core';
import {Platform} from '@angular/cdk/platform';
import {Injectable} from '@angular/core';


// The InteractivityChecker leans heavily on the ally.js accessibility utilities.
Expand All@@ -18,7 +18,7 @@ import {Platform} from '@angular/cdk/platform';
* Utility for checking the interactivity of an element, such as whether is is focusable or
* tabbable.
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class InteractivityChecker {

constructor(private _platform: Platform) {}
Expand Down
18 changes: 18 additions & 0 deletions src/cdk/a11y/live-announcer/live-announcer-token.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {InjectionToken} from '@angular/core';

// The token for the live announcer element is defined in a separate file from LiveAnnouncer
// as a workaround for https://github.com/angular/angular/issues/22559

export const LIVE_ANNOUNCER_ELEMENT_TOKEN =
new InjectionToken<HTMLElement | null>('liveAnnouncerElement', {
providedIn: 'root',
factory: () => null,
});
5 changes: 3 additions & 2 deletions src/cdk/a11y/live-announcer/live-announcer.spec.ts
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
import {inject, fakeAsync, tick, ComponentFixture, TestBed} from '@angular/core/testing';
import {Component} from '@angular/core';
import {ComponentFixture, fakeAsync, inject, TestBed, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {LiveAnnouncer, LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer';
import {A11yModule} from '../index';
import {LiveAnnouncer} from './live-announcer';
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';


describe('LiveAnnouncer', () => {
Expand Down
22 changes: 11 additions & 11 deletions src/cdk/a11y/live-announcer/live-announcer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,25 +6,24 @@
* found in the LICENSE file at https://angular.io/license
*/

import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
OnDestroy,
Optional,
Inject,
Provider,
SkipSelf,
OnDestroy,
} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';


export const LIVE_ANNOUNCER_ELEMENT_TOKEN = new InjectionToken<HTMLElement>('liveAnnouncerElement');

/** Possible politeness levels. */
export type AriaLivePoliteness = 'off' | 'polite' | 'assertive';

@Injectable()
@Injectable({providedIn: 'root'})
export class LiveAnnouncer implements OnDestroy {
private _liveElement: Element;
private readonly _liveElement: Element;

constructor(
@Optional() @Inject(LIVE_ANNOUNCER_ELEMENT_TOKEN) elementToken: any,
Expand DownExpand Up@@ -81,14 +80,15 @@ export class LiveAnnouncer implements OnDestroy {

}

/** @docs-private */

/** @docs-private @deprecated @deletion-target 7.0.0 */
export function LIVE_ANNOUNCER_PROVIDER_FACTORY(
parentDispatcher: LiveAnnouncer, liveElement: any, _document: any) {
return parentDispatcher || new LiveAnnouncer(liveElement, _document);
}

/** @docs-private */
export const LIVE_ANNOUNCER_PROVIDER = {
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const LIVE_ANNOUNCER_PROVIDER: Provider = {
// If there is already a LiveAnnouncer available, use that. Otherwise, provide a new one.
provide: LiveAnnouncer,
deps: [
Expand Down
1 change: 1 addition & 0 deletions src/cdk/a11y/public-api.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@ export * from './key-manager/list-key-manager';
export * from './focus-trap/focus-trap';
export * from './interactivity-checker/interactivity-checker';
export * from './live-announcer/live-announcer';
export * from './live-announcer/live-announcer-token';
export * from './focus-monitor/focus-monitor';
export * from './fake-mousedown';
export * from './a11y-module';
3 changes: 1 addition & 2 deletions src/cdk/accordion/accordion-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,13 +7,12 @@
*/

import {NgModule} from '@angular/core';
import {UNIQUE_SELECTION_DISPATCHER_PROVIDER} from '@angular/cdk/collections';
import {CdkAccordion} from './accordion';
import {CdkAccordionItem} from './accordion-item';


@NgModule({
exports: [CdkAccordion, CdkAccordionItem],
declarations: [CdkAccordion, CdkAccordionItem],
providers: [UNIQUE_SELECTION_DISPATCHER_PROVIDER],
})
export class CdkAccordionModule {}
29 changes: 29 additions & 0 deletions src/cdk/bidi/BUILD.bazel
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")


ng_module(
name = "bidi",
Expand All@@ -8,3 +10,30 @@ ng_module(
deps = ["@rxjs"],
tsconfig = ":tsconfig-build.json",
)

ts_library(
name = "bidi_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":bidi",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)

ts_web_test(
name = "unit_tests",
bootstrap = [
"//:web_test_bootstrap_scripts",
],

# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":bidi_test_sources",
],
)
6 changes: 0 additions & 6 deletions src/cdk/bidi/bidi-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,17 +7,11 @@
*/

import {NgModule} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {Dir} from './dir';
import {DIR_DOCUMENT, Directionality} from './directionality';


@NgModule({
exports: [Dir],
declarations: [Dir],
providers: [
{provide: DIR_DOCUMENT, useExisting: DOCUMENT},
Directionality,
]
})
export class BidiModule { }
31 changes: 31 additions & 0 deletions src/cdk/bidi/dir-document-token.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {DOCUMENT} from '@angular/common';
import {inject, InjectionToken} from '@angular/core';


/**
* Injection token used to inject the document into Directionality.
* This is used so that the value can be faked in tests.
*
* We can't use the real document in tests because changing the real `dir` causes geometry-based
* tests in Safari to fail.
*
* We also can't re-provide the DOCUMENT token from platform-brower because the unit tests
* themselves use things like `querySelector` in test code.
*
* This token is defined in a separate file from Directionality as a workaround for
* https://github.com/angular/angular/issues/22559
*
* @docs-private
*/
export const DIR_DOCUMENT = new InjectionToken<Document>('cdk-dir-doc', {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside, do we really need a separate token for the document here? We can easily stub out the DOCUMENT itself in the tests.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was originally doing this I found that re-providing common's DOCUMENT with something else made Angular not work.

providedIn: 'root',
factory: () => inject(DOCUMENT),
});
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
feat(cdk): switch injectables to new scope API by jelbourn · Pull Request #10301 · angular/components · GitHub
Skip to content
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
7,748 changes: 3,134 additions & 4,614 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,14 +26,14 @@
"node": ">= 5.4.1"
},
"dependencies": {
"@angular/animations": ">=6.0.0-beta.7 <7.0.0",
"@angular/common": ">=6.0.0-beta.7 <7.0.0",
"@angular/compiler": ">=6.0.0-beta.7 <7.0.0",
"@angular/core": ">=6.0.0-beta.7 <7.0.0",
"@angular/forms": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-browser": ">=6.0.0-beta.7 <7.0.0",
"@angular/animations": "6.0.0-beta.8",
"@angular/common": "6.0.0-beta.8",
"@angular/compiler": "6.0.0-beta.8",
"@angular/core": "6.0.0-beta.8",
"@angular/forms": "6.0.0-beta.8",
"@angular/platform-browser": "6.0.0-beta.8",
"core-js": "^2.4.1",
"rxjs": "^5.5.5",
"rxjs": "^5.5.7",
"systemjs": "0.19.43",
"tsickle": "^0.24.x",
"tslib": "^1.7.1",
Expand All@@ -42,11 +42,11 @@
"devDependencies": {
"@angular-devkit/core": "^0.4.5",
"@angular-devkit/schematics": "^0.4.5",
"@angular/bazel": ">=6.0.0-beta.7 <7.0.0",
"@angular/compiler-cli": ">=6.0.0-beta.7 <7.0.0",
"@angular/http": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-browser-dynamic": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-server": ">=6.0.0-beta.7 <7.0.0",
"@angular/bazel": "6.0.0-beta.8",
"@angular/compiler-cli": "6.0.0-beta.8",
"@angular/http": "6.0.0-beta.8",
"@angular/platform-browser-dynamic": "6.0.0-beta.8",
"@angular/platform-server": "6.0.0-beta.8",
"@angular/router": ">=6.0.0-beta.7 <7.0.0",
"@angular/upgrade": "^5.0.1",
"@bazel/ibazel": "0.3.1",
Expand DownExpand Up@@ -126,7 +126,7 @@
"tsconfig-paths": "^2.3.0",
"tslint": "^5.9.1",
"tsutils": "^2.6.0",
"typescript": "~2.6.0",
"typescript": "~2.7.0",
"uglify-js": "^2.8.14",
"web-animations-js": "^2.2.5"
}
Expand Down
15 changes: 2 additions & 13 deletions src/cdk/a11y/a11y-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,23 +9,12 @@
import {PlatformModule} from '@angular/cdk/platform';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {ARIA_DESCRIBER_PROVIDER, AriaDescriber} from './aria-describer/aria-describer';
import {CdkMonitorFocus, FOCUS_MONITOR_PROVIDER} from './focus-monitor/focus-monitor';
import {CdkTrapFocus, FocusTrapFactory} from './focus-trap/focus-trap';
import {InteractivityChecker} from './interactivity-checker/interactivity-checker';
import {LIVE_ANNOUNCER_PROVIDER} from './live-announcer/live-announcer';
import {CdkMonitorFocus} from './focus-monitor/focus-monitor';
import {CdkTrapFocus} from './focus-trap/focus-trap';

@NgModule({
imports: [CommonModule, PlatformModule],
declarations: [CdkTrapFocus, CdkMonitorFocus],
exports: [CdkTrapFocus, CdkMonitorFocus],
providers: [
InteractivityChecker,
FocusTrapFactory,
AriaDescriber,
LIVE_ANNOUNCER_PROVIDER,
ARIA_DESCRIBER_PROVIDER,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with how the app-wide providers work yet, but should the AriaDescriber still be set in the providers in this case? I believe that it's the only reason why, for example, the tooltip imports the A11yModule.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, module imports just for this kind of injectable shouldn't be necessary any more. I'll address those in my next PR that applies this to material.

FOCUS_MONITOR_PROVIDER,
]
})
export class A11yModule {}
16 changes: 12 additions & 4 deletions src/cdk/a11y/aria-describer/aria-describer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,10 +6,17 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable, Inject, InjectionToken, Optional, SkipSelf} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
Optional,
SkipSelf,
} from '@angular/core';
import {addAriaReferencedId, getAriaReferenceIds, removeAriaReferencedId} from './aria-reference';


/**
* Interface used to register message elements and keep a count of how many registrations have
* the same message and the reference to the message element used for the `aria-describedby`.
Expand DownExpand Up@@ -46,7 +53,7 @@ let messagesContainer: HTMLElement | null = null;
* content.
* @docs-private
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class AriaDescriber {
private _document: Document;

Expand DownExpand Up@@ -204,12 +211,13 @@ export class AriaDescriber {

}

/** @docs-private */

/** @docs-private @deprecated @deletion-target 7.0.0 */
export function ARIA_DESCRIBER_PROVIDER_FACTORY(parentDispatcher: AriaDescriber, _document: any) {
return parentDispatcher || new AriaDescriber(_document);
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const ARIA_DESCRIBER_PROVIDER = {
// If there is already an AriaDescriber available, use that. Otherwise, provide a new one.
provide: AriaDescriber,
Expand Down
7 changes: 4 additions & 3 deletions src/cdk/a11y/focus-monitor/focus-monitor.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {Platform, supportsPassiveEventListeners} from '@angular/cdk/platform';
import {
Directive,
Expand DownExpand Up@@ -39,7 +40,7 @@ type MonitoredElementInfo = {


/** Monitors mouse and keyboard events to determine the cause of focus events. */
@Injectable()
@Injectable({providedIn: 'root'})
export class FocusMonitor implements OnDestroy {
/** The focus origin that the next focus event is a result of. */
private _origin: FocusOrigin = null;
Expand DownExpand Up@@ -380,13 +381,13 @@ export class CdkMonitorFocus implements OnDestroy {
}
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export function FOCUS_MONITOR_PROVIDER_FACTORY(
parentDispatcher: FocusMonitor, ngZone: NgZone, platform: Platform) {
return parentDispatcher || new FocusMonitor(ngZone, platform);
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const FOCUS_MONITOR_PROVIDER = {
// If there is already a FocusMonitor available, use that. Otherwise, provide a new one.
provide: FocusMonitor,
Expand Down
12 changes: 6 additions & 6 deletions src/cdk/a11y/focus-trap/focus-trap.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,20 +6,20 @@
* found in the LICENSE file at https://angular.io/license
*/

import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {DOCUMENT} from '@angular/common';
import {
AfterContentInit,
Directive,
ElementRef,
Inject,
Injectable,
Input,
NgZone,
OnDestroy,
AfterContentInit,
Injectable,
Inject,
} from '@angular/core';
import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {take} from 'rxjs/operators/take';
import {InteractivityChecker} from '../interactivity-checker/interactivity-checker';
import {DOCUMENT} from '@angular/common';


/**
Expand DownExpand Up@@ -278,7 +278,7 @@ export class FocusTrap {


/** Factory that allows easy instantiation of focus traps. */
@Injectable()
@Injectable({providedIn: 'root'})
export class FocusTrapFactory {
private _document: Document;

Expand Down
4 changes: 2 additions & 2 deletions src/cdk/a11y/interactivity-checker/interactivity-checker.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable} from '@angular/core';
import {Platform} from '@angular/cdk/platform';
import {Injectable} from '@angular/core';


// The InteractivityChecker leans heavily on the ally.js accessibility utilities.
Expand All@@ -18,7 +18,7 @@ import {Platform} from '@angular/cdk/platform';
* Utility for checking the interactivity of an element, such as whether is is focusable or
* tabbable.
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class InteractivityChecker {

constructor(private _platform: Platform) {}
Expand Down
18 changes: 18 additions & 0 deletions src/cdk/a11y/live-announcer/live-announcer-token.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {InjectionToken} from '@angular/core';

// The token for the live announcer element is defined in a separate file from LiveAnnouncer
// as a workaround for https://github.com/angular/angular/issues/22559

export const LIVE_ANNOUNCER_ELEMENT_TOKEN =
new InjectionToken<HTMLElement | null>('liveAnnouncerElement', {
providedIn: 'root',
factory: () => null,
});
5 changes: 3 additions & 2 deletions src/cdk/a11y/live-announcer/live-announcer.spec.ts
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
import {inject, fakeAsync, tick, ComponentFixture, TestBed} from '@angular/core/testing';
import {Component} from '@angular/core';
import {ComponentFixture, fakeAsync, inject, TestBed, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {LiveAnnouncer, LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer';
import {A11yModule} from '../index';
import {LiveAnnouncer} from './live-announcer';
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';


describe('LiveAnnouncer', () => {
Expand Down
22 changes: 11 additions & 11 deletions src/cdk/a11y/live-announcer/live-announcer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,25 +6,24 @@
* found in the LICENSE file at https://angular.io/license
*/

import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
OnDestroy,
Optional,
Inject,
Provider,
SkipSelf,
OnDestroy,
} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';


export const LIVE_ANNOUNCER_ELEMENT_TOKEN = new InjectionToken<HTMLElement>('liveAnnouncerElement');

/** Possible politeness levels. */
export type AriaLivePoliteness = 'off' | 'polite' | 'assertive';

@Injectable()
@Injectable({providedIn: 'root'})
export class LiveAnnouncer implements OnDestroy {
private _liveElement: Element;
private readonly _liveElement: Element;

constructor(
@Optional() @Inject(LIVE_ANNOUNCER_ELEMENT_TOKEN) elementToken: any,
Expand DownExpand Up@@ -81,14 +80,15 @@ export class LiveAnnouncer implements OnDestroy {

}

/** @docs-private */

/** @docs-private @deprecated @deletion-target 7.0.0 */
export function LIVE_ANNOUNCER_PROVIDER_FACTORY(
parentDispatcher: LiveAnnouncer, liveElement: any, _document: any) {
return parentDispatcher || new LiveAnnouncer(liveElement, _document);
}

/** @docs-private */
export const LIVE_ANNOUNCER_PROVIDER = {
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const LIVE_ANNOUNCER_PROVIDER: Provider = {
// If there is already a LiveAnnouncer available, use that. Otherwise, provide a new one.
provide: LiveAnnouncer,
deps: [
Expand Down
1 change: 1 addition & 0 deletions src/cdk/a11y/public-api.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@ export * from './key-manager/list-key-manager';
export * from './focus-trap/focus-trap';
export * from './interactivity-checker/interactivity-checker';
export * from './live-announcer/live-announcer';
export * from './live-announcer/live-announcer-token';
export * from './focus-monitor/focus-monitor';
export * from './fake-mousedown';
export * from './a11y-module';
3 changes: 1 addition & 2 deletions src/cdk/accordion/accordion-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,13 +7,12 @@
*/

import {NgModule} from '@angular/core';
import {UNIQUE_SELECTION_DISPATCHER_PROVIDER} from '@angular/cdk/collections';
import {CdkAccordion} from './accordion';
import {CdkAccordionItem} from './accordion-item';


@NgModule({
exports: [CdkAccordion, CdkAccordionItem],
declarations: [CdkAccordion, CdkAccordionItem],
providers: [UNIQUE_SELECTION_DISPATCHER_PROVIDER],
})
export class CdkAccordionModule {}
29 changes: 29 additions & 0 deletions src/cdk/bidi/BUILD.bazel
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")


ng_module(
name = "bidi",
Expand All@@ -8,3 +10,30 @@ ng_module(
deps = ["@rxjs"],
tsconfig = ":tsconfig-build.json",
)

ts_library(
name = "bidi_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":bidi",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)

ts_web_test(
name = "unit_tests",
bootstrap = [
"//:web_test_bootstrap_scripts",
],

# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":bidi_test_sources",
],
)
6 changes: 0 additions & 6 deletions src/cdk/bidi/bidi-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,17 +7,11 @@
*/

import {NgModule} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {Dir} from './dir';
import {DIR_DOCUMENT, Directionality} from './directionality';


@NgModule({
exports: [Dir],
declarations: [Dir],
providers: [
{provide: DIR_DOCUMENT, useExisting: DOCUMENT},
Directionality,
]
})
export class BidiModule { }
31 changes: 31 additions & 0 deletions src/cdk/bidi/dir-document-token.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {DOCUMENT} from '@angular/common';
import {inject, InjectionToken} from '@angular/core';


/**
* Injection token used to inject the document into Directionality.
* This is used so that the value can be faked in tests.
*
* We can't use the real document in tests because changing the real `dir` causes geometry-based
* tests in Safari to fail.
*
* We also can't re-provide the DOCUMENT token from platform-brower because the unit tests
* themselves use things like `querySelector` in test code.
*
* This token is defined in a separate file from Directionality as a workaround for
* https://github.com/angular/angular/issues/22559
*
* @docs-private
*/
export const DIR_DOCUMENT = new InjectionToken<Document>('cdk-dir-doc', {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside, do we really need a separate token for the document here? We can easily stub out the DOCUMENT itself in the tests.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was originally doing this I found that re-providing common's DOCUMENT with something else made Angular not work.

providedIn: 'root',
factory: () => inject(DOCUMENT),
});
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' feat(cdk): switch injectables to new scope API by jelbourn · Pull Request #10301 · angular/components · GitHub
Skip to content
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
7,748 changes: 3,134 additions & 4,614 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,14 +26,14 @@
"node": ">= 5.4.1"
},
"dependencies": {
"@angular/animations": ">=6.0.0-beta.7 <7.0.0",
"@angular/common": ">=6.0.0-beta.7 <7.0.0",
"@angular/compiler": ">=6.0.0-beta.7 <7.0.0",
"@angular/core": ">=6.0.0-beta.7 <7.0.0",
"@angular/forms": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-browser": ">=6.0.0-beta.7 <7.0.0",
"@angular/animations": "6.0.0-beta.8",
"@angular/common": "6.0.0-beta.8",
"@angular/compiler": "6.0.0-beta.8",
"@angular/core": "6.0.0-beta.8",
"@angular/forms": "6.0.0-beta.8",
"@angular/platform-browser": "6.0.0-beta.8",
"core-js": "^2.4.1",
"rxjs": "^5.5.5",
"rxjs": "^5.5.7",
"systemjs": "0.19.43",
"tsickle": "^0.24.x",
"tslib": "^1.7.1",
Expand All@@ -42,11 +42,11 @@
"devDependencies": {
"@angular-devkit/core": "^0.4.5",
"@angular-devkit/schematics": "^0.4.5",
"@angular/bazel": ">=6.0.0-beta.7 <7.0.0",
"@angular/compiler-cli": ">=6.0.0-beta.7 <7.0.0",
"@angular/http": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-browser-dynamic": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-server": ">=6.0.0-beta.7 <7.0.0",
"@angular/bazel": "6.0.0-beta.8",
"@angular/compiler-cli": "6.0.0-beta.8",
"@angular/http": "6.0.0-beta.8",
"@angular/platform-browser-dynamic": "6.0.0-beta.8",
"@angular/platform-server": "6.0.0-beta.8",
"@angular/router": ">=6.0.0-beta.7 <7.0.0",
"@angular/upgrade": "^5.0.1",
"@bazel/ibazel": "0.3.1",
Expand DownExpand Up@@ -126,7 +126,7 @@
"tsconfig-paths": "^2.3.0",
"tslint": "^5.9.1",
"tsutils": "^2.6.0",
"typescript": "~2.6.0",
"typescript": "~2.7.0",
"uglify-js": "^2.8.14",
"web-animations-js": "^2.2.5"
}
Expand Down
15 changes: 2 additions & 13 deletions src/cdk/a11y/a11y-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,23 +9,12 @@
import {PlatformModule} from '@angular/cdk/platform';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {ARIA_DESCRIBER_PROVIDER, AriaDescriber} from './aria-describer/aria-describer';
import {CdkMonitorFocus, FOCUS_MONITOR_PROVIDER} from './focus-monitor/focus-monitor';
import {CdkTrapFocus, FocusTrapFactory} from './focus-trap/focus-trap';
import {InteractivityChecker} from './interactivity-checker/interactivity-checker';
import {LIVE_ANNOUNCER_PROVIDER} from './live-announcer/live-announcer';
import {CdkMonitorFocus} from './focus-monitor/focus-monitor';
import {CdkTrapFocus} from './focus-trap/focus-trap';

@NgModule({
imports: [CommonModule, PlatformModule],
declarations: [CdkTrapFocus, CdkMonitorFocus],
exports: [CdkTrapFocus, CdkMonitorFocus],
providers: [
InteractivityChecker,
FocusTrapFactory,
AriaDescriber,
LIVE_ANNOUNCER_PROVIDER,
ARIA_DESCRIBER_PROVIDER,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with how the app-wide providers work yet, but should the AriaDescriber still be set in the providers in this case? I believe that it's the only reason why, for example, the tooltip imports the A11yModule.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, module imports just for this kind of injectable shouldn't be necessary any more. I'll address those in my next PR that applies this to material.

FOCUS_MONITOR_PROVIDER,
]
})
export class A11yModule {}
16 changes: 12 additions & 4 deletions src/cdk/a11y/aria-describer/aria-describer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,10 +6,17 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable, Inject, InjectionToken, Optional, SkipSelf} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
Optional,
SkipSelf,
} from '@angular/core';
import {addAriaReferencedId, getAriaReferenceIds, removeAriaReferencedId} from './aria-reference';


/**
* Interface used to register message elements and keep a count of how many registrations have
* the same message and the reference to the message element used for the `aria-describedby`.
Expand DownExpand Up@@ -46,7 +53,7 @@ let messagesContainer: HTMLElement | null = null;
* content.
* @docs-private
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class AriaDescriber {
private _document: Document;

Expand DownExpand Up@@ -204,12 +211,13 @@ export class AriaDescriber {

}

/** @docs-private */

/** @docs-private @deprecated @deletion-target 7.0.0 */
export function ARIA_DESCRIBER_PROVIDER_FACTORY(parentDispatcher: AriaDescriber, _document: any) {
return parentDispatcher || new AriaDescriber(_document);
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const ARIA_DESCRIBER_PROVIDER = {
// If there is already an AriaDescriber available, use that. Otherwise, provide a new one.
provide: AriaDescriber,
Expand Down
7 changes: 4 additions & 3 deletions src/cdk/a11y/focus-monitor/focus-monitor.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {Platform, supportsPassiveEventListeners} from '@angular/cdk/platform';
import {
Directive,
Expand DownExpand Up@@ -39,7 +40,7 @@ type MonitoredElementInfo = {


/** Monitors mouse and keyboard events to determine the cause of focus events. */
@Injectable()
@Injectable({providedIn: 'root'})
export class FocusMonitor implements OnDestroy {
/** The focus origin that the next focus event is a result of. */
private _origin: FocusOrigin = null;
Expand DownExpand Up@@ -380,13 +381,13 @@ export class CdkMonitorFocus implements OnDestroy {
}
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export function FOCUS_MONITOR_PROVIDER_FACTORY(
parentDispatcher: FocusMonitor, ngZone: NgZone, platform: Platform) {
return parentDispatcher || new FocusMonitor(ngZone, platform);
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const FOCUS_MONITOR_PROVIDER = {
// If there is already a FocusMonitor available, use that. Otherwise, provide a new one.
provide: FocusMonitor,
Expand Down
12 changes: 6 additions & 6 deletions src/cdk/a11y/focus-trap/focus-trap.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,20 +6,20 @@
* found in the LICENSE file at https://angular.io/license
*/

import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {DOCUMENT} from '@angular/common';
import {
AfterContentInit,
Directive,
ElementRef,
Inject,
Injectable,
Input,
NgZone,
OnDestroy,
AfterContentInit,
Injectable,
Inject,
} from '@angular/core';
import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {take} from 'rxjs/operators/take';
import {InteractivityChecker} from '../interactivity-checker/interactivity-checker';
import {DOCUMENT} from '@angular/common';


/**
Expand DownExpand Up@@ -278,7 +278,7 @@ export class FocusTrap {


/** Factory that allows easy instantiation of focus traps. */
@Injectable()
@Injectable({providedIn: 'root'})
export class FocusTrapFactory {
private _document: Document;

Expand Down
4 changes: 2 additions & 2 deletions src/cdk/a11y/interactivity-checker/interactivity-checker.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable} from '@angular/core';
import {Platform} from '@angular/cdk/platform';
import {Injectable} from '@angular/core';


// The InteractivityChecker leans heavily on the ally.js accessibility utilities.
Expand All@@ -18,7 +18,7 @@ import {Platform} from '@angular/cdk/platform';
* Utility for checking the interactivity of an element, such as whether is is focusable or
* tabbable.
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class InteractivityChecker {

constructor(private _platform: Platform) {}
Expand Down
18 changes: 18 additions & 0 deletions src/cdk/a11y/live-announcer/live-announcer-token.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {InjectionToken} from '@angular/core';

// The token for the live announcer element is defined in a separate file from LiveAnnouncer
// as a workaround for https://github.com/angular/angular/issues/22559

export const LIVE_ANNOUNCER_ELEMENT_TOKEN =
new InjectionToken<HTMLElement | null>('liveAnnouncerElement', {
providedIn: 'root',
factory: () => null,
});
5 changes: 3 additions & 2 deletions src/cdk/a11y/live-announcer/live-announcer.spec.ts
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
import {inject, fakeAsync, tick, ComponentFixture, TestBed} from '@angular/core/testing';
import {Component} from '@angular/core';
import {ComponentFixture, fakeAsync, inject, TestBed, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {LiveAnnouncer, LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer';
import {A11yModule} from '../index';
import {LiveAnnouncer} from './live-announcer';
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';


describe('LiveAnnouncer', () => {
Expand Down
22 changes: 11 additions & 11 deletions src/cdk/a11y/live-announcer/live-announcer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,25 +6,24 @@
* found in the LICENSE file at https://angular.io/license
*/

import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
OnDestroy,
Optional,
Inject,
Provider,
SkipSelf,
OnDestroy,
} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';


export const LIVE_ANNOUNCER_ELEMENT_TOKEN = new InjectionToken<HTMLElement>('liveAnnouncerElement');

/** Possible politeness levels. */
export type AriaLivePoliteness = 'off' | 'polite' | 'assertive';

@Injectable()
@Injectable({providedIn: 'root'})
export class LiveAnnouncer implements OnDestroy {
private _liveElement: Element;
private readonly _liveElement: Element;

constructor(
@Optional() @Inject(LIVE_ANNOUNCER_ELEMENT_TOKEN) elementToken: any,
Expand DownExpand Up@@ -81,14 +80,15 @@ export class LiveAnnouncer implements OnDestroy {

}

/** @docs-private */

/** @docs-private @deprecated @deletion-target 7.0.0 */
export function LIVE_ANNOUNCER_PROVIDER_FACTORY(
parentDispatcher: LiveAnnouncer, liveElement: any, _document: any) {
return parentDispatcher || new LiveAnnouncer(liveElement, _document);
}

/** @docs-private */
export const LIVE_ANNOUNCER_PROVIDER = {
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const LIVE_ANNOUNCER_PROVIDER: Provider = {
// If there is already a LiveAnnouncer available, use that. Otherwise, provide a new one.
provide: LiveAnnouncer,
deps: [
Expand Down
1 change: 1 addition & 0 deletions src/cdk/a11y/public-api.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@ export * from './key-manager/list-key-manager';
export * from './focus-trap/focus-trap';
export * from './interactivity-checker/interactivity-checker';
export * from './live-announcer/live-announcer';
export * from './live-announcer/live-announcer-token';
export * from './focus-monitor/focus-monitor';
export * from './fake-mousedown';
export * from './a11y-module';
3 changes: 1 addition & 2 deletions src/cdk/accordion/accordion-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,13 +7,12 @@
*/

import {NgModule} from '@angular/core';
import {UNIQUE_SELECTION_DISPATCHER_PROVIDER} from '@angular/cdk/collections';
import {CdkAccordion} from './accordion';
import {CdkAccordionItem} from './accordion-item';


@NgModule({
exports: [CdkAccordion, CdkAccordionItem],
declarations: [CdkAccordion, CdkAccordionItem],
providers: [UNIQUE_SELECTION_DISPATCHER_PROVIDER],
})
export class CdkAccordionModule {}
29 changes: 29 additions & 0 deletions src/cdk/bidi/BUILD.bazel
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")


ng_module(
name = "bidi",
Expand All@@ -8,3 +10,30 @@ ng_module(
deps = ["@rxjs"],
tsconfig = ":tsconfig-build.json",
)

ts_library(
name = "bidi_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":bidi",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)

ts_web_test(
name = "unit_tests",
bootstrap = [
"//:web_test_bootstrap_scripts",
],

# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":bidi_test_sources",
],
)
6 changes: 0 additions & 6 deletions src/cdk/bidi/bidi-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,17 +7,11 @@
*/

import {NgModule} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {Dir} from './dir';
import {DIR_DOCUMENT, Directionality} from './directionality';


@NgModule({
exports: [Dir],
declarations: [Dir],
providers: [
{provide: DIR_DOCUMENT, useExisting: DOCUMENT},
Directionality,
]
})
export class BidiModule { }
31 changes: 31 additions & 0 deletions src/cdk/bidi/dir-document-token.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {DOCUMENT} from '@angular/common';
import {inject, InjectionToken} from '@angular/core';


/**
* Injection token used to inject the document into Directionality.
* This is used so that the value can be faked in tests.
*
* We can't use the real document in tests because changing the real `dir` causes geometry-based
* tests in Safari to fail.
*
* We also can't re-provide the DOCUMENT token from platform-brower because the unit tests
* themselves use things like `querySelector` in test code.
*
* This token is defined in a separate file from Directionality as a workaround for
* https://github.com/angular/angular/issues/22559
*
* @docs-private
*/
export const DIR_DOCUMENT = new InjectionToken<Document>('cdk-dir-doc', {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside, do we really need a separate token for the document here? We can easily stub out the DOCUMENT itself in the tests.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was originally doing this I found that re-providing common's DOCUMENT with something else made Angular not work.

providedIn: 'root',
factory: () => inject(DOCUMENT),
});
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' feat(cdk): switch injectables to new scope API by jelbourn · Pull Request #10301 · angular/components · GitHub
Skip to content
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
7,748 changes: 3,134 additions & 4,614 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,14 +26,14 @@
"node": ">= 5.4.1"
},
"dependencies": {
"@angular/animations": ">=6.0.0-beta.7 <7.0.0",
"@angular/common": ">=6.0.0-beta.7 <7.0.0",
"@angular/compiler": ">=6.0.0-beta.7 <7.0.0",
"@angular/core": ">=6.0.0-beta.7 <7.0.0",
"@angular/forms": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-browser": ">=6.0.0-beta.7 <7.0.0",
"@angular/animations": "6.0.0-beta.8",
"@angular/common": "6.0.0-beta.8",
"@angular/compiler": "6.0.0-beta.8",
"@angular/core": "6.0.0-beta.8",
"@angular/forms": "6.0.0-beta.8",
"@angular/platform-browser": "6.0.0-beta.8",
"core-js": "^2.4.1",
"rxjs": "^5.5.5",
"rxjs": "^5.5.7",
"systemjs": "0.19.43",
"tsickle": "^0.24.x",
"tslib": "^1.7.1",
Expand All@@ -42,11 +42,11 @@
"devDependencies": {
"@angular-devkit/core": "^0.4.5",
"@angular-devkit/schematics": "^0.4.5",
"@angular/bazel": ">=6.0.0-beta.7 <7.0.0",
"@angular/compiler-cli": ">=6.0.0-beta.7 <7.0.0",
"@angular/http": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-browser-dynamic": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-server": ">=6.0.0-beta.7 <7.0.0",
"@angular/bazel": "6.0.0-beta.8",
"@angular/compiler-cli": "6.0.0-beta.8",
"@angular/http": "6.0.0-beta.8",
"@angular/platform-browser-dynamic": "6.0.0-beta.8",
"@angular/platform-server": "6.0.0-beta.8",
"@angular/router": ">=6.0.0-beta.7 <7.0.0",
"@angular/upgrade": "^5.0.1",
"@bazel/ibazel": "0.3.1",
Expand DownExpand Up@@ -126,7 +126,7 @@
"tsconfig-paths": "^2.3.0",
"tslint": "^5.9.1",
"tsutils": "^2.6.0",
"typescript": "~2.6.0",
"typescript": "~2.7.0",
"uglify-js": "^2.8.14",
"web-animations-js": "^2.2.5"
}
Expand Down
15 changes: 2 additions & 13 deletions src/cdk/a11y/a11y-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,23 +9,12 @@
import {PlatformModule} from '@angular/cdk/platform';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {ARIA_DESCRIBER_PROVIDER, AriaDescriber} from './aria-describer/aria-describer';
import {CdkMonitorFocus, FOCUS_MONITOR_PROVIDER} from './focus-monitor/focus-monitor';
import {CdkTrapFocus, FocusTrapFactory} from './focus-trap/focus-trap';
import {InteractivityChecker} from './interactivity-checker/interactivity-checker';
import {LIVE_ANNOUNCER_PROVIDER} from './live-announcer/live-announcer';
import {CdkMonitorFocus} from './focus-monitor/focus-monitor';
import {CdkTrapFocus} from './focus-trap/focus-trap';

@NgModule({
imports: [CommonModule, PlatformModule],
declarations: [CdkTrapFocus, CdkMonitorFocus],
exports: [CdkTrapFocus, CdkMonitorFocus],
providers: [
InteractivityChecker,
FocusTrapFactory,
AriaDescriber,
LIVE_ANNOUNCER_PROVIDER,
ARIA_DESCRIBER_PROVIDER,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with how the app-wide providers work yet, but should the AriaDescriber still be set in the providers in this case? I believe that it's the only reason why, for example, the tooltip imports the A11yModule.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, module imports just for this kind of injectable shouldn't be necessary any more. I'll address those in my next PR that applies this to material.

FOCUS_MONITOR_PROVIDER,
]
})
export class A11yModule {}
16 changes: 12 additions & 4 deletions src/cdk/a11y/aria-describer/aria-describer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,10 +6,17 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable, Inject, InjectionToken, Optional, SkipSelf} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
Optional,
SkipSelf,
} from '@angular/core';
import {addAriaReferencedId, getAriaReferenceIds, removeAriaReferencedId} from './aria-reference';


/**
* Interface used to register message elements and keep a count of how many registrations have
* the same message and the reference to the message element used for the `aria-describedby`.
Expand DownExpand Up@@ -46,7 +53,7 @@ let messagesContainer: HTMLElement | null = null;
* content.
* @docs-private
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class AriaDescriber {
private _document: Document;

Expand DownExpand Up@@ -204,12 +211,13 @@ export class AriaDescriber {

}

/** @docs-private */

/** @docs-private @deprecated @deletion-target 7.0.0 */
export function ARIA_DESCRIBER_PROVIDER_FACTORY(parentDispatcher: AriaDescriber, _document: any) {
return parentDispatcher || new AriaDescriber(_document);
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const ARIA_DESCRIBER_PROVIDER = {
// If there is already an AriaDescriber available, use that. Otherwise, provide a new one.
provide: AriaDescriber,
Expand Down
7 changes: 4 additions & 3 deletions src/cdk/a11y/focus-monitor/focus-monitor.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {Platform, supportsPassiveEventListeners} from '@angular/cdk/platform';
import {
Directive,
Expand DownExpand Up@@ -39,7 +40,7 @@ type MonitoredElementInfo = {


/** Monitors mouse and keyboard events to determine the cause of focus events. */
@Injectable()
@Injectable({providedIn: 'root'})
export class FocusMonitor implements OnDestroy {
/** The focus origin that the next focus event is a result of. */
private _origin: FocusOrigin = null;
Expand DownExpand Up@@ -380,13 +381,13 @@ export class CdkMonitorFocus implements OnDestroy {
}
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export function FOCUS_MONITOR_PROVIDER_FACTORY(
parentDispatcher: FocusMonitor, ngZone: NgZone, platform: Platform) {
return parentDispatcher || new FocusMonitor(ngZone, platform);
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const FOCUS_MONITOR_PROVIDER = {
// If there is already a FocusMonitor available, use that. Otherwise, provide a new one.
provide: FocusMonitor,
Expand Down
12 changes: 6 additions & 6 deletions src/cdk/a11y/focus-trap/focus-trap.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,20 +6,20 @@
* found in the LICENSE file at https://angular.io/license
*/

import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {DOCUMENT} from '@angular/common';
import {
AfterContentInit,
Directive,
ElementRef,
Inject,
Injectable,
Input,
NgZone,
OnDestroy,
AfterContentInit,
Injectable,
Inject,
} from '@angular/core';
import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {take} from 'rxjs/operators/take';
import {InteractivityChecker} from '../interactivity-checker/interactivity-checker';
import {DOCUMENT} from '@angular/common';


/**
Expand DownExpand Up@@ -278,7 +278,7 @@ export class FocusTrap {


/** Factory that allows easy instantiation of focus traps. */
@Injectable()
@Injectable({providedIn: 'root'})
export class FocusTrapFactory {
private _document: Document;

Expand Down
4 changes: 2 additions & 2 deletions src/cdk/a11y/interactivity-checker/interactivity-checker.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable} from '@angular/core';
import {Platform} from '@angular/cdk/platform';
import {Injectable} from '@angular/core';


// The InteractivityChecker leans heavily on the ally.js accessibility utilities.
Expand All@@ -18,7 +18,7 @@ import {Platform} from '@angular/cdk/platform';
* Utility for checking the interactivity of an element, such as whether is is focusable or
* tabbable.
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class InteractivityChecker {

constructor(private _platform: Platform) {}
Expand Down
18 changes: 18 additions & 0 deletions src/cdk/a11y/live-announcer/live-announcer-token.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {InjectionToken} from '@angular/core';

// The token for the live announcer element is defined in a separate file from LiveAnnouncer
// as a workaround for https://github.com/angular/angular/issues/22559

export const LIVE_ANNOUNCER_ELEMENT_TOKEN =
new InjectionToken<HTMLElement | null>('liveAnnouncerElement', {
providedIn: 'root',
factory: () => null,
});
5 changes: 3 additions & 2 deletions src/cdk/a11y/live-announcer/live-announcer.spec.ts
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
import {inject, fakeAsync, tick, ComponentFixture, TestBed} from '@angular/core/testing';
import {Component} from '@angular/core';
import {ComponentFixture, fakeAsync, inject, TestBed, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {LiveAnnouncer, LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer';
import {A11yModule} from '../index';
import {LiveAnnouncer} from './live-announcer';
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';


describe('LiveAnnouncer', () => {
Expand Down
22 changes: 11 additions & 11 deletions src/cdk/a11y/live-announcer/live-announcer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,25 +6,24 @@
* found in the LICENSE file at https://angular.io/license
*/

import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
OnDestroy,
Optional,
Inject,
Provider,
SkipSelf,
OnDestroy,
} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';


export const LIVE_ANNOUNCER_ELEMENT_TOKEN = new InjectionToken<HTMLElement>('liveAnnouncerElement');

/** Possible politeness levels. */
export type AriaLivePoliteness = 'off' | 'polite' | 'assertive';

@Injectable()
@Injectable({providedIn: 'root'})
export class LiveAnnouncer implements OnDestroy {
private _liveElement: Element;
private readonly _liveElement: Element;

constructor(
@Optional() @Inject(LIVE_ANNOUNCER_ELEMENT_TOKEN) elementToken: any,
Expand DownExpand Up@@ -81,14 +80,15 @@ export class LiveAnnouncer implements OnDestroy {

}

/** @docs-private */

/** @docs-private @deprecated @deletion-target 7.0.0 */
export function LIVE_ANNOUNCER_PROVIDER_FACTORY(
parentDispatcher: LiveAnnouncer, liveElement: any, _document: any) {
return parentDispatcher || new LiveAnnouncer(liveElement, _document);
}

/** @docs-private */
export const LIVE_ANNOUNCER_PROVIDER = {
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const LIVE_ANNOUNCER_PROVIDER: Provider = {
// If there is already a LiveAnnouncer available, use that. Otherwise, provide a new one.
provide: LiveAnnouncer,
deps: [
Expand Down
1 change: 1 addition & 0 deletions src/cdk/a11y/public-api.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@ export * from './key-manager/list-key-manager';
export * from './focus-trap/focus-trap';
export * from './interactivity-checker/interactivity-checker';
export * from './live-announcer/live-announcer';
export * from './live-announcer/live-announcer-token';
export * from './focus-monitor/focus-monitor';
export * from './fake-mousedown';
export * from './a11y-module';
3 changes: 1 addition & 2 deletions src/cdk/accordion/accordion-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,13 +7,12 @@
*/

import {NgModule} from '@angular/core';
import {UNIQUE_SELECTION_DISPATCHER_PROVIDER} from '@angular/cdk/collections';
import {CdkAccordion} from './accordion';
import {CdkAccordionItem} from './accordion-item';


@NgModule({
exports: [CdkAccordion, CdkAccordionItem],
declarations: [CdkAccordion, CdkAccordionItem],
providers: [UNIQUE_SELECTION_DISPATCHER_PROVIDER],
})
export class CdkAccordionModule {}
29 changes: 29 additions & 0 deletions src/cdk/bidi/BUILD.bazel
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")


ng_module(
name = "bidi",
Expand All@@ -8,3 +10,30 @@ ng_module(
deps = ["@rxjs"],
tsconfig = ":tsconfig-build.json",
)

ts_library(
name = "bidi_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":bidi",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)

ts_web_test(
name = "unit_tests",
bootstrap = [
"//:web_test_bootstrap_scripts",
],

# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":bidi_test_sources",
],
)
6 changes: 0 additions & 6 deletions src/cdk/bidi/bidi-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,17 +7,11 @@
*/

import {NgModule} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {Dir} from './dir';
import {DIR_DOCUMENT, Directionality} from './directionality';


@NgModule({
exports: [Dir],
declarations: [Dir],
providers: [
{provide: DIR_DOCUMENT, useExisting: DOCUMENT},
Directionality,
]
})
export class BidiModule { }
31 changes: 31 additions & 0 deletions src/cdk/bidi/dir-document-token.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {DOCUMENT} from '@angular/common';
import {inject, InjectionToken} from '@angular/core';


/**
* Injection token used to inject the document into Directionality.
* This is used so that the value can be faked in tests.
*
* We can't use the real document in tests because changing the real `dir` causes geometry-based
* tests in Safari to fail.
*
* We also can't re-provide the DOCUMENT token from platform-brower because the unit tests
* themselves use things like `querySelector` in test code.
*
* This token is defined in a separate file from Directionality as a workaround for
* https://github.com/angular/angular/issues/22559
*
* @docs-private
*/
export const DIR_DOCUMENT = new InjectionToken<Document>('cdk-dir-doc', {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside, do we really need a separate token for the document here? We can easily stub out the DOCUMENT itself in the tests.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was originally doing this I found that re-providing common's DOCUMENT with something else made Angular not work.

providedIn: 'root',
factory: () => inject(DOCUMENT),
});
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' feat(cdk): switch injectables to new scope API by jelbourn · Pull Request #10301 · angular/components · GitHub
Skip to content
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
7,748 changes: 3,134 additions & 4,614 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,14 +26,14 @@
"node": ">= 5.4.1"
},
"dependencies": {
"@angular/animations": ">=6.0.0-beta.7 <7.0.0",
"@angular/common": ">=6.0.0-beta.7 <7.0.0",
"@angular/compiler": ">=6.0.0-beta.7 <7.0.0",
"@angular/core": ">=6.0.0-beta.7 <7.0.0",
"@angular/forms": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-browser": ">=6.0.0-beta.7 <7.0.0",
"@angular/animations": "6.0.0-beta.8",
"@angular/common": "6.0.0-beta.8",
"@angular/compiler": "6.0.0-beta.8",
"@angular/core": "6.0.0-beta.8",
"@angular/forms": "6.0.0-beta.8",
"@angular/platform-browser": "6.0.0-beta.8",
"core-js": "^2.4.1",
"rxjs": "^5.5.5",
"rxjs": "^5.5.7",
"systemjs": "0.19.43",
"tsickle": "^0.24.x",
"tslib": "^1.7.1",
Expand All@@ -42,11 +42,11 @@
"devDependencies": {
"@angular-devkit/core": "^0.4.5",
"@angular-devkit/schematics": "^0.4.5",
"@angular/bazel": ">=6.0.0-beta.7 <7.0.0",
"@angular/compiler-cli": ">=6.0.0-beta.7 <7.0.0",
"@angular/http": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-browser-dynamic": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-server": ">=6.0.0-beta.7 <7.0.0",
"@angular/bazel": "6.0.0-beta.8",
"@angular/compiler-cli": "6.0.0-beta.8",
"@angular/http": "6.0.0-beta.8",
"@angular/platform-browser-dynamic": "6.0.0-beta.8",
"@angular/platform-server": "6.0.0-beta.8",
"@angular/router": ">=6.0.0-beta.7 <7.0.0",
"@angular/upgrade": "^5.0.1",
"@bazel/ibazel": "0.3.1",
Expand DownExpand Up@@ -126,7 +126,7 @@
"tsconfig-paths": "^2.3.0",
"tslint": "^5.9.1",
"tsutils": "^2.6.0",
"typescript": "~2.6.0",
"typescript": "~2.7.0",
"uglify-js": "^2.8.14",
"web-animations-js": "^2.2.5"
}
Expand Down
15 changes: 2 additions & 13 deletions src/cdk/a11y/a11y-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,23 +9,12 @@
import {PlatformModule} from '@angular/cdk/platform';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {ARIA_DESCRIBER_PROVIDER, AriaDescriber} from './aria-describer/aria-describer';
import {CdkMonitorFocus, FOCUS_MONITOR_PROVIDER} from './focus-monitor/focus-monitor';
import {CdkTrapFocus, FocusTrapFactory} from './focus-trap/focus-trap';
import {InteractivityChecker} from './interactivity-checker/interactivity-checker';
import {LIVE_ANNOUNCER_PROVIDER} from './live-announcer/live-announcer';
import {CdkMonitorFocus} from './focus-monitor/focus-monitor';
import {CdkTrapFocus} from './focus-trap/focus-trap';

@NgModule({
imports: [CommonModule, PlatformModule],
declarations: [CdkTrapFocus, CdkMonitorFocus],
exports: [CdkTrapFocus, CdkMonitorFocus],
providers: [
InteractivityChecker,
FocusTrapFactory,
AriaDescriber,
LIVE_ANNOUNCER_PROVIDER,
ARIA_DESCRIBER_PROVIDER,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with how the app-wide providers work yet, but should the AriaDescriber still be set in the providers in this case? I believe that it's the only reason why, for example, the tooltip imports the A11yModule.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, module imports just for this kind of injectable shouldn't be necessary any more. I'll address those in my next PR that applies this to material.

FOCUS_MONITOR_PROVIDER,
]
})
export class A11yModule {}
16 changes: 12 additions & 4 deletions src/cdk/a11y/aria-describer/aria-describer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,10 +6,17 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable, Inject, InjectionToken, Optional, SkipSelf} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
Optional,
SkipSelf,
} from '@angular/core';
import {addAriaReferencedId, getAriaReferenceIds, removeAriaReferencedId} from './aria-reference';


/**
* Interface used to register message elements and keep a count of how many registrations have
* the same message and the reference to the message element used for the `aria-describedby`.
Expand DownExpand Up@@ -46,7 +53,7 @@ let messagesContainer: HTMLElement | null = null;
* content.
* @docs-private
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class AriaDescriber {
private _document: Document;

Expand DownExpand Up@@ -204,12 +211,13 @@ export class AriaDescriber {

}

/** @docs-private */

/** @docs-private @deprecated @deletion-target 7.0.0 */
export function ARIA_DESCRIBER_PROVIDER_FACTORY(parentDispatcher: AriaDescriber, _document: any) {
return parentDispatcher || new AriaDescriber(_document);
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const ARIA_DESCRIBER_PROVIDER = {
// If there is already an AriaDescriber available, use that. Otherwise, provide a new one.
provide: AriaDescriber,
Expand Down
7 changes: 4 additions & 3 deletions src/cdk/a11y/focus-monitor/focus-monitor.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {Platform, supportsPassiveEventListeners} from '@angular/cdk/platform';
import {
Directive,
Expand DownExpand Up@@ -39,7 +40,7 @@ type MonitoredElementInfo = {


/** Monitors mouse and keyboard events to determine the cause of focus events. */
@Injectable()
@Injectable({providedIn: 'root'})
export class FocusMonitor implements OnDestroy {
/** The focus origin that the next focus event is a result of. */
private _origin: FocusOrigin = null;
Expand DownExpand Up@@ -380,13 +381,13 @@ export class CdkMonitorFocus implements OnDestroy {
}
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export function FOCUS_MONITOR_PROVIDER_FACTORY(
parentDispatcher: FocusMonitor, ngZone: NgZone, platform: Platform) {
return parentDispatcher || new FocusMonitor(ngZone, platform);
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const FOCUS_MONITOR_PROVIDER = {
// If there is already a FocusMonitor available, use that. Otherwise, provide a new one.
provide: FocusMonitor,
Expand Down
12 changes: 6 additions & 6 deletions src/cdk/a11y/focus-trap/focus-trap.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,20 +6,20 @@
* found in the LICENSE file at https://angular.io/license
*/

import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {DOCUMENT} from '@angular/common';
import {
AfterContentInit,
Directive,
ElementRef,
Inject,
Injectable,
Input,
NgZone,
OnDestroy,
AfterContentInit,
Injectable,
Inject,
} from '@angular/core';
import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {take} from 'rxjs/operators/take';
import {InteractivityChecker} from '../interactivity-checker/interactivity-checker';
import {DOCUMENT} from '@angular/common';


/**
Expand DownExpand Up@@ -278,7 +278,7 @@ export class FocusTrap {


/** Factory that allows easy instantiation of focus traps. */
@Injectable()
@Injectable({providedIn: 'root'})
export class FocusTrapFactory {
private _document: Document;

Expand Down
4 changes: 2 additions & 2 deletions src/cdk/a11y/interactivity-checker/interactivity-checker.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable} from '@angular/core';
import {Platform} from '@angular/cdk/platform';
import {Injectable} from '@angular/core';


// The InteractivityChecker leans heavily on the ally.js accessibility utilities.
Expand All@@ -18,7 +18,7 @@ import {Platform} from '@angular/cdk/platform';
* Utility for checking the interactivity of an element, such as whether is is focusable or
* tabbable.
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class InteractivityChecker {

constructor(private _platform: Platform) {}
Expand Down
18 changes: 18 additions & 0 deletions src/cdk/a11y/live-announcer/live-announcer-token.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {InjectionToken} from '@angular/core';

// The token for the live announcer element is defined in a separate file from LiveAnnouncer
// as a workaround for https://github.com/angular/angular/issues/22559

export const LIVE_ANNOUNCER_ELEMENT_TOKEN =
new InjectionToken<HTMLElement | null>('liveAnnouncerElement', {
providedIn: 'root',
factory: () => null,
});
5 changes: 3 additions & 2 deletions src/cdk/a11y/live-announcer/live-announcer.spec.ts
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
import {inject, fakeAsync, tick, ComponentFixture, TestBed} from '@angular/core/testing';
import {Component} from '@angular/core';
import {ComponentFixture, fakeAsync, inject, TestBed, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {LiveAnnouncer, LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer';
import {A11yModule} from '../index';
import {LiveAnnouncer} from './live-announcer';
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';


describe('LiveAnnouncer', () => {
Expand Down
22 changes: 11 additions & 11 deletions src/cdk/a11y/live-announcer/live-announcer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,25 +6,24 @@
* found in the LICENSE file at https://angular.io/license
*/

import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
OnDestroy,
Optional,
Inject,
Provider,
SkipSelf,
OnDestroy,
} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';


export const LIVE_ANNOUNCER_ELEMENT_TOKEN = new InjectionToken<HTMLElement>('liveAnnouncerElement');

/** Possible politeness levels. */
export type AriaLivePoliteness = 'off' | 'polite' | 'assertive';

@Injectable()
@Injectable({providedIn: 'root'})
export class LiveAnnouncer implements OnDestroy {
private _liveElement: Element;
private readonly _liveElement: Element;

constructor(
@Optional() @Inject(LIVE_ANNOUNCER_ELEMENT_TOKEN) elementToken: any,
Expand DownExpand Up@@ -81,14 +80,15 @@ export class LiveAnnouncer implements OnDestroy {

}

/** @docs-private */

/** @docs-private @deprecated @deletion-target 7.0.0 */
export function LIVE_ANNOUNCER_PROVIDER_FACTORY(
parentDispatcher: LiveAnnouncer, liveElement: any, _document: any) {
return parentDispatcher || new LiveAnnouncer(liveElement, _document);
}

/** @docs-private */
export const LIVE_ANNOUNCER_PROVIDER = {
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const LIVE_ANNOUNCER_PROVIDER: Provider = {
// If there is already a LiveAnnouncer available, use that. Otherwise, provide a new one.
provide: LiveAnnouncer,
deps: [
Expand Down
1 change: 1 addition & 0 deletions src/cdk/a11y/public-api.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@ export * from './key-manager/list-key-manager';
export * from './focus-trap/focus-trap';
export * from './interactivity-checker/interactivity-checker';
export * from './live-announcer/live-announcer';
export * from './live-announcer/live-announcer-token';
export * from './focus-monitor/focus-monitor';
export * from './fake-mousedown';
export * from './a11y-module';
3 changes: 1 addition & 2 deletions src/cdk/accordion/accordion-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,13 +7,12 @@
*/

import {NgModule} from '@angular/core';
import {UNIQUE_SELECTION_DISPATCHER_PROVIDER} from '@angular/cdk/collections';
import {CdkAccordion} from './accordion';
import {CdkAccordionItem} from './accordion-item';


@NgModule({
exports: [CdkAccordion, CdkAccordionItem],
declarations: [CdkAccordion, CdkAccordionItem],
providers: [UNIQUE_SELECTION_DISPATCHER_PROVIDER],
})
export class CdkAccordionModule {}
29 changes: 29 additions & 0 deletions src/cdk/bidi/BUILD.bazel
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")


ng_module(
name = "bidi",
Expand All@@ -8,3 +10,30 @@ ng_module(
deps = ["@rxjs"],
tsconfig = ":tsconfig-build.json",
)

ts_library(
name = "bidi_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":bidi",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)

ts_web_test(
name = "unit_tests",
bootstrap = [
"//:web_test_bootstrap_scripts",
],

# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":bidi_test_sources",
],
)
6 changes: 0 additions & 6 deletions src/cdk/bidi/bidi-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,17 +7,11 @@
*/

import {NgModule} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {Dir} from './dir';
import {DIR_DOCUMENT, Directionality} from './directionality';


@NgModule({
exports: [Dir],
declarations: [Dir],
providers: [
{provide: DIR_DOCUMENT, useExisting: DOCUMENT},
Directionality,
]
})
export class BidiModule { }
31 changes: 31 additions & 0 deletions src/cdk/bidi/dir-document-token.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {DOCUMENT} from '@angular/common';
import {inject, InjectionToken} from '@angular/core';


/**
* Injection token used to inject the document into Directionality.
* This is used so that the value can be faked in tests.
*
* We can't use the real document in tests because changing the real `dir` causes geometry-based
* tests in Safari to fail.
*
* We also can't re-provide the DOCUMENT token from platform-brower because the unit tests
* themselves use things like `querySelector` in test code.
*
* This token is defined in a separate file from Directionality as a workaround for
* https://github.com/angular/angular/issues/22559
*
* @docs-private
*/
export const DIR_DOCUMENT = new InjectionToken<Document>('cdk-dir-doc', {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside, do we really need a separate token for the document here? We can easily stub out the DOCUMENT itself in the tests.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was originally doing this I found that re-providing common's DOCUMENT with something else made Angular not work.

providedIn: 'root',
factory: () => inject(DOCUMENT),
});
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' feat(cdk): switch injectables to new scope API by jelbourn · Pull Request #10301 · angular/components · GitHub
Skip to content
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
7,748 changes: 3,134 additions & 4,614 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,14 +26,14 @@
"node": ">= 5.4.1"
},
"dependencies": {
"@angular/animations": ">=6.0.0-beta.7 <7.0.0",
"@angular/common": ">=6.0.0-beta.7 <7.0.0",
"@angular/compiler": ">=6.0.0-beta.7 <7.0.0",
"@angular/core": ">=6.0.0-beta.7 <7.0.0",
"@angular/forms": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-browser": ">=6.0.0-beta.7 <7.0.0",
"@angular/animations": "6.0.0-beta.8",
"@angular/common": "6.0.0-beta.8",
"@angular/compiler": "6.0.0-beta.8",
"@angular/core": "6.0.0-beta.8",
"@angular/forms": "6.0.0-beta.8",
"@angular/platform-browser": "6.0.0-beta.8",
"core-js": "^2.4.1",
"rxjs": "^5.5.5",
"rxjs": "^5.5.7",
"systemjs": "0.19.43",
"tsickle": "^0.24.x",
"tslib": "^1.7.1",
Expand All@@ -42,11 +42,11 @@
"devDependencies": {
"@angular-devkit/core": "^0.4.5",
"@angular-devkit/schematics": "^0.4.5",
"@angular/bazel": ">=6.0.0-beta.7 <7.0.0",
"@angular/compiler-cli": ">=6.0.0-beta.7 <7.0.0",
"@angular/http": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-browser-dynamic": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-server": ">=6.0.0-beta.7 <7.0.0",
"@angular/bazel": "6.0.0-beta.8",
"@angular/compiler-cli": "6.0.0-beta.8",
"@angular/http": "6.0.0-beta.8",
"@angular/platform-browser-dynamic": "6.0.0-beta.8",
"@angular/platform-server": "6.0.0-beta.8",
"@angular/router": ">=6.0.0-beta.7 <7.0.0",
"@angular/upgrade": "^5.0.1",
"@bazel/ibazel": "0.3.1",
Expand DownExpand Up@@ -126,7 +126,7 @@
"tsconfig-paths": "^2.3.0",
"tslint": "^5.9.1",
"tsutils": "^2.6.0",
"typescript": "~2.6.0",
"typescript": "~2.7.0",
"uglify-js": "^2.8.14",
"web-animations-js": "^2.2.5"
}
Expand Down
15 changes: 2 additions & 13 deletions src/cdk/a11y/a11y-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,23 +9,12 @@
import {PlatformModule} from '@angular/cdk/platform';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {ARIA_DESCRIBER_PROVIDER, AriaDescriber} from './aria-describer/aria-describer';
import {CdkMonitorFocus, FOCUS_MONITOR_PROVIDER} from './focus-monitor/focus-monitor';
import {CdkTrapFocus, FocusTrapFactory} from './focus-trap/focus-trap';
import {InteractivityChecker} from './interactivity-checker/interactivity-checker';
import {LIVE_ANNOUNCER_PROVIDER} from './live-announcer/live-announcer';
import {CdkMonitorFocus} from './focus-monitor/focus-monitor';
import {CdkTrapFocus} from './focus-trap/focus-trap';

@NgModule({
imports: [CommonModule, PlatformModule],
declarations: [CdkTrapFocus, CdkMonitorFocus],
exports: [CdkTrapFocus, CdkMonitorFocus],
providers: [
InteractivityChecker,
FocusTrapFactory,
AriaDescriber,
LIVE_ANNOUNCER_PROVIDER,
ARIA_DESCRIBER_PROVIDER,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with how the app-wide providers work yet, but should the AriaDescriber still be set in the providers in this case? I believe that it's the only reason why, for example, the tooltip imports the A11yModule.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, module imports just for this kind of injectable shouldn't be necessary any more. I'll address those in my next PR that applies this to material.

FOCUS_MONITOR_PROVIDER,
]
})
export class A11yModule {}
16 changes: 12 additions & 4 deletions src/cdk/a11y/aria-describer/aria-describer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,10 +6,17 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable, Inject, InjectionToken, Optional, SkipSelf} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
Optional,
SkipSelf,
} from '@angular/core';
import {addAriaReferencedId, getAriaReferenceIds, removeAriaReferencedId} from './aria-reference';


/**
* Interface used to register message elements and keep a count of how many registrations have
* the same message and the reference to the message element used for the `aria-describedby`.
Expand DownExpand Up@@ -46,7 +53,7 @@ let messagesContainer: HTMLElement | null = null;
* content.
* @docs-private
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class AriaDescriber {
private _document: Document;

Expand DownExpand Up@@ -204,12 +211,13 @@ export class AriaDescriber {

}

/** @docs-private */

/** @docs-private @deprecated @deletion-target 7.0.0 */
export function ARIA_DESCRIBER_PROVIDER_FACTORY(parentDispatcher: AriaDescriber, _document: any) {
return parentDispatcher || new AriaDescriber(_document);
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const ARIA_DESCRIBER_PROVIDER = {
// If there is already an AriaDescriber available, use that. Otherwise, provide a new one.
provide: AriaDescriber,
Expand Down
7 changes: 4 additions & 3 deletions src/cdk/a11y/focus-monitor/focus-monitor.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {Platform, supportsPassiveEventListeners} from '@angular/cdk/platform';
import {
Directive,
Expand DownExpand Up@@ -39,7 +40,7 @@ type MonitoredElementInfo = {


/** Monitors mouse and keyboard events to determine the cause of focus events. */
@Injectable()
@Injectable({providedIn: 'root'})
export class FocusMonitor implements OnDestroy {
/** The focus origin that the next focus event is a result of. */
private _origin: FocusOrigin = null;
Expand DownExpand Up@@ -380,13 +381,13 @@ export class CdkMonitorFocus implements OnDestroy {
}
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export function FOCUS_MONITOR_PROVIDER_FACTORY(
parentDispatcher: FocusMonitor, ngZone: NgZone, platform: Platform) {
return parentDispatcher || new FocusMonitor(ngZone, platform);
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const FOCUS_MONITOR_PROVIDER = {
// If there is already a FocusMonitor available, use that. Otherwise, provide a new one.
provide: FocusMonitor,
Expand Down
12 changes: 6 additions & 6 deletions src/cdk/a11y/focus-trap/focus-trap.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,20 +6,20 @@
* found in the LICENSE file at https://angular.io/license
*/

import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {DOCUMENT} from '@angular/common';
import {
AfterContentInit,
Directive,
ElementRef,
Inject,
Injectable,
Input,
NgZone,
OnDestroy,
AfterContentInit,
Injectable,
Inject,
} from '@angular/core';
import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {take} from 'rxjs/operators/take';
import {InteractivityChecker} from '../interactivity-checker/interactivity-checker';
import {DOCUMENT} from '@angular/common';


/**
Expand DownExpand Up@@ -278,7 +278,7 @@ export class FocusTrap {


/** Factory that allows easy instantiation of focus traps. */
@Injectable()
@Injectable({providedIn: 'root'})
export class FocusTrapFactory {
private _document: Document;

Expand Down
4 changes: 2 additions & 2 deletions src/cdk/a11y/interactivity-checker/interactivity-checker.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable} from '@angular/core';
import {Platform} from '@angular/cdk/platform';
import {Injectable} from '@angular/core';


// The InteractivityChecker leans heavily on the ally.js accessibility utilities.
Expand All@@ -18,7 +18,7 @@ import {Platform} from '@angular/cdk/platform';
* Utility for checking the interactivity of an element, such as whether is is focusable or
* tabbable.
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class InteractivityChecker {

constructor(private _platform: Platform) {}
Expand Down
18 changes: 18 additions & 0 deletions src/cdk/a11y/live-announcer/live-announcer-token.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {InjectionToken} from '@angular/core';

// The token for the live announcer element is defined in a separate file from LiveAnnouncer
// as a workaround for https://github.com/angular/angular/issues/22559

export const LIVE_ANNOUNCER_ELEMENT_TOKEN =
new InjectionToken<HTMLElement | null>('liveAnnouncerElement', {
providedIn: 'root',
factory: () => null,
});
5 changes: 3 additions & 2 deletions src/cdk/a11y/live-announcer/live-announcer.spec.ts
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
import {inject, fakeAsync, tick, ComponentFixture, TestBed} from '@angular/core/testing';
import {Component} from '@angular/core';
import {ComponentFixture, fakeAsync, inject, TestBed, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {LiveAnnouncer, LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer';
import {A11yModule} from '../index';
import {LiveAnnouncer} from './live-announcer';
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';


describe('LiveAnnouncer', () => {
Expand Down
22 changes: 11 additions & 11 deletions src/cdk/a11y/live-announcer/live-announcer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,25 +6,24 @@
* found in the LICENSE file at https://angular.io/license
*/

import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
OnDestroy,
Optional,
Inject,
Provider,
SkipSelf,
OnDestroy,
} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';


export const LIVE_ANNOUNCER_ELEMENT_TOKEN = new InjectionToken<HTMLElement>('liveAnnouncerElement');

/** Possible politeness levels. */
export type AriaLivePoliteness = 'off' | 'polite' | 'assertive';

@Injectable()
@Injectable({providedIn: 'root'})
export class LiveAnnouncer implements OnDestroy {
private _liveElement: Element;
private readonly _liveElement: Element;

constructor(
@Optional() @Inject(LIVE_ANNOUNCER_ELEMENT_TOKEN) elementToken: any,
Expand DownExpand Up@@ -81,14 +80,15 @@ export class LiveAnnouncer implements OnDestroy {

}

/** @docs-private */

/** @docs-private @deprecated @deletion-target 7.0.0 */
export function LIVE_ANNOUNCER_PROVIDER_FACTORY(
parentDispatcher: LiveAnnouncer, liveElement: any, _document: any) {
return parentDispatcher || new LiveAnnouncer(liveElement, _document);
}

/** @docs-private */
export const LIVE_ANNOUNCER_PROVIDER = {
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const LIVE_ANNOUNCER_PROVIDER: Provider = {
// If there is already a LiveAnnouncer available, use that. Otherwise, provide a new one.
provide: LiveAnnouncer,
deps: [
Expand Down
1 change: 1 addition & 0 deletions src/cdk/a11y/public-api.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@ export * from './key-manager/list-key-manager';
export * from './focus-trap/focus-trap';
export * from './interactivity-checker/interactivity-checker';
export * from './live-announcer/live-announcer';
export * from './live-announcer/live-announcer-token';
export * from './focus-monitor/focus-monitor';
export * from './fake-mousedown';
export * from './a11y-module';
3 changes: 1 addition & 2 deletions src/cdk/accordion/accordion-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,13 +7,12 @@
*/

import {NgModule} from '@angular/core';
import {UNIQUE_SELECTION_DISPATCHER_PROVIDER} from '@angular/cdk/collections';
import {CdkAccordion} from './accordion';
import {CdkAccordionItem} from './accordion-item';


@NgModule({
exports: [CdkAccordion, CdkAccordionItem],
declarations: [CdkAccordion, CdkAccordionItem],
providers: [UNIQUE_SELECTION_DISPATCHER_PROVIDER],
})
export class CdkAccordionModule {}
29 changes: 29 additions & 0 deletions src/cdk/bidi/BUILD.bazel
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")


ng_module(
name = "bidi",
Expand All@@ -8,3 +10,30 @@ ng_module(
deps = ["@rxjs"],
tsconfig = ":tsconfig-build.json",
)

ts_library(
name = "bidi_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":bidi",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)

ts_web_test(
name = "unit_tests",
bootstrap = [
"//:web_test_bootstrap_scripts",
],

# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":bidi_test_sources",
],
)
6 changes: 0 additions & 6 deletions src/cdk/bidi/bidi-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,17 +7,11 @@
*/

import {NgModule} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {Dir} from './dir';
import {DIR_DOCUMENT, Directionality} from './directionality';


@NgModule({
exports: [Dir],
declarations: [Dir],
providers: [
{provide: DIR_DOCUMENT, useExisting: DOCUMENT},
Directionality,
]
})
export class BidiModule { }
31 changes: 31 additions & 0 deletions src/cdk/bidi/dir-document-token.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {DOCUMENT} from '@angular/common';
import {inject, InjectionToken} from '@angular/core';


/**
* Injection token used to inject the document into Directionality.
* This is used so that the value can be faked in tests.
*
* We can't use the real document in tests because changing the real `dir` causes geometry-based
* tests in Safari to fail.
*
* We also can't re-provide the DOCUMENT token from platform-brower because the unit tests
* themselves use things like `querySelector` in test code.
*
* This token is defined in a separate file from Directionality as a workaround for
* https://github.com/angular/angular/issues/22559
*
* @docs-private
*/
export const DIR_DOCUMENT = new InjectionToken<Document>('cdk-dir-doc', {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside, do we really need a separate token for the document here? We can easily stub out the DOCUMENT itself in the tests.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was originally doing this I found that re-providing common's DOCUMENT with something else made Angular not work.

providedIn: 'root',
factory: () => inject(DOCUMENT),
});
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); feat(cdk): switch injectables to new scope API by jelbourn · Pull Request #10301 · angular/components · GitHub
Skip to content
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
7,748 changes: 3,134 additions & 4,614 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,14 +26,14 @@
"node": ">= 5.4.1"
},
"dependencies": {
"@angular/animations": ">=6.0.0-beta.7 <7.0.0",
"@angular/common": ">=6.0.0-beta.7 <7.0.0",
"@angular/compiler": ">=6.0.0-beta.7 <7.0.0",
"@angular/core": ">=6.0.0-beta.7 <7.0.0",
"@angular/forms": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-browser": ">=6.0.0-beta.7 <7.0.0",
"@angular/animations": "6.0.0-beta.8",
"@angular/common": "6.0.0-beta.8",
"@angular/compiler": "6.0.0-beta.8",
"@angular/core": "6.0.0-beta.8",
"@angular/forms": "6.0.0-beta.8",
"@angular/platform-browser": "6.0.0-beta.8",
"core-js": "^2.4.1",
"rxjs": "^5.5.5",
"rxjs": "^5.5.7",
"systemjs": "0.19.43",
"tsickle": "^0.24.x",
"tslib": "^1.7.1",
Expand All@@ -42,11 +42,11 @@
"devDependencies": {
"@angular-devkit/core": "^0.4.5",
"@angular-devkit/schematics": "^0.4.5",
"@angular/bazel": ">=6.0.0-beta.7 <7.0.0",
"@angular/compiler-cli": ">=6.0.0-beta.7 <7.0.0",
"@angular/http": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-browser-dynamic": ">=6.0.0-beta.7 <7.0.0",
"@angular/platform-server": ">=6.0.0-beta.7 <7.0.0",
"@angular/bazel": "6.0.0-beta.8",
"@angular/compiler-cli": "6.0.0-beta.8",
"@angular/http": "6.0.0-beta.8",
"@angular/platform-browser-dynamic": "6.0.0-beta.8",
"@angular/platform-server": "6.0.0-beta.8",
"@angular/router": ">=6.0.0-beta.7 <7.0.0",
"@angular/upgrade": "^5.0.1",
"@bazel/ibazel": "0.3.1",
Expand DownExpand Up@@ -126,7 +126,7 @@
"tsconfig-paths": "^2.3.0",
"tslint": "^5.9.1",
"tsutils": "^2.6.0",
"typescript": "~2.6.0",
"typescript": "~2.7.0",
"uglify-js": "^2.8.14",
"web-animations-js": "^2.2.5"
}
Expand Down
15 changes: 2 additions & 13 deletions src/cdk/a11y/a11y-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,23 +9,12 @@
import {PlatformModule} from '@angular/cdk/platform';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {ARIA_DESCRIBER_PROVIDER, AriaDescriber} from './aria-describer/aria-describer';
import {CdkMonitorFocus, FOCUS_MONITOR_PROVIDER} from './focus-monitor/focus-monitor';
import {CdkTrapFocus, FocusTrapFactory} from './focus-trap/focus-trap';
import {InteractivityChecker} from './interactivity-checker/interactivity-checker';
import {LIVE_ANNOUNCER_PROVIDER} from './live-announcer/live-announcer';
import {CdkMonitorFocus} from './focus-monitor/focus-monitor';
import {CdkTrapFocus} from './focus-trap/focus-trap';

@NgModule({
imports: [CommonModule, PlatformModule],
declarations: [CdkTrapFocus, CdkMonitorFocus],
exports: [CdkTrapFocus, CdkMonitorFocus],
providers: [
InteractivityChecker,
FocusTrapFactory,
AriaDescriber,
LIVE_ANNOUNCER_PROVIDER,
ARIA_DESCRIBER_PROVIDER,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with how the app-wide providers work yet, but should the AriaDescriber still be set in the providers in this case? I believe that it's the only reason why, for example, the tooltip imports the A11yModule.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, module imports just for this kind of injectable shouldn't be necessary any more. I'll address those in my next PR that applies this to material.

FOCUS_MONITOR_PROVIDER,
]
})
export class A11yModule {}
16 changes: 12 additions & 4 deletions src/cdk/a11y/aria-describer/aria-describer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,10 +6,17 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable, Inject, InjectionToken, Optional, SkipSelf} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
Optional,
SkipSelf,
} from '@angular/core';
import {addAriaReferencedId, getAriaReferenceIds, removeAriaReferencedId} from './aria-reference';


/**
* Interface used to register message elements and keep a count of how many registrations have
* the same message and the reference to the message element used for the `aria-describedby`.
Expand DownExpand Up@@ -46,7 +53,7 @@ let messagesContainer: HTMLElement | null = null;
* content.
* @docs-private
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class AriaDescriber {
private _document: Document;

Expand DownExpand Up@@ -204,12 +211,13 @@ export class AriaDescriber {

}

/** @docs-private */

/** @docs-private @deprecated @deletion-target 7.0.0 */
export function ARIA_DESCRIBER_PROVIDER_FACTORY(parentDispatcher: AriaDescriber, _document: any) {
return parentDispatcher || new AriaDescriber(_document);
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const ARIA_DESCRIBER_PROVIDER = {
// If there is already an AriaDescriber available, use that. Otherwise, provide a new one.
provide: AriaDescriber,
Expand Down
7 changes: 4 additions & 3 deletions src/cdk/a11y/focus-monitor/focus-monitor.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {Platform, supportsPassiveEventListeners} from '@angular/cdk/platform';
import {
Directive,
Expand DownExpand Up@@ -39,7 +40,7 @@ type MonitoredElementInfo = {


/** Monitors mouse and keyboard events to determine the cause of focus events. */
@Injectable()
@Injectable({providedIn: 'root'})
export class FocusMonitor implements OnDestroy {
/** The focus origin that the next focus event is a result of. */
private _origin: FocusOrigin = null;
Expand DownExpand Up@@ -380,13 +381,13 @@ export class CdkMonitorFocus implements OnDestroy {
}
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export function FOCUS_MONITOR_PROVIDER_FACTORY(
parentDispatcher: FocusMonitor, ngZone: NgZone, platform: Platform) {
return parentDispatcher || new FocusMonitor(ngZone, platform);
}

/** @docs-private */
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const FOCUS_MONITOR_PROVIDER = {
// If there is already a FocusMonitor available, use that. Otherwise, provide a new one.
provide: FocusMonitor,
Expand Down
12 changes: 6 additions & 6 deletions src/cdk/a11y/focus-trap/focus-trap.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,20 +6,20 @@
* found in the LICENSE file at https://angular.io/license
*/

import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {DOCUMENT} from '@angular/common';
import {
AfterContentInit,
Directive,
ElementRef,
Inject,
Injectable,
Input,
NgZone,
OnDestroy,
AfterContentInit,
Injectable,
Inject,
} from '@angular/core';
import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {take} from 'rxjs/operators/take';
import {InteractivityChecker} from '../interactivity-checker/interactivity-checker';
import {DOCUMENT} from '@angular/common';


/**
Expand DownExpand Up@@ -278,7 +278,7 @@ export class FocusTrap {


/** Factory that allows easy instantiation of focus traps. */
@Injectable()
@Injectable({providedIn: 'root'})
export class FocusTrapFactory {
private _document: Document;

Expand Down
4 changes: 2 additions & 2 deletions src/cdk/a11y/interactivity-checker/interactivity-checker.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Injectable} from '@angular/core';
import {Platform} from '@angular/cdk/platform';
import {Injectable} from '@angular/core';


// The InteractivityChecker leans heavily on the ally.js accessibility utilities.
Expand All@@ -18,7 +18,7 @@ import {Platform} from '@angular/cdk/platform';
* Utility for checking the interactivity of an element, such as whether is is focusable or
* tabbable.
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class InteractivityChecker {

constructor(private _platform: Platform) {}
Expand Down
18 changes: 18 additions & 0 deletions src/cdk/a11y/live-announcer/live-announcer-token.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {InjectionToken} from '@angular/core';

// The token for the live announcer element is defined in a separate file from LiveAnnouncer
// as a workaround for https://github.com/angular/angular/issues/22559

export const LIVE_ANNOUNCER_ELEMENT_TOKEN =
new InjectionToken<HTMLElement | null>('liveAnnouncerElement', {
providedIn: 'root',
factory: () => null,
});
5 changes: 3 additions & 2 deletions src/cdk/a11y/live-announcer/live-announcer.spec.ts
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
import {inject, fakeAsync, tick, ComponentFixture, TestBed} from '@angular/core/testing';
import {Component} from '@angular/core';
import {ComponentFixture, fakeAsync, inject, TestBed, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {LiveAnnouncer, LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer';
import {A11yModule} from '../index';
import {LiveAnnouncer} from './live-announcer';
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';


describe('LiveAnnouncer', () => {
Expand Down
22 changes: 11 additions & 11 deletions src/cdk/a11y/live-announcer/live-announcer.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,25 +6,24 @@
* found in the LICENSE file at https://angular.io/license
*/

import {DOCUMENT} from '@angular/common';
import {
Inject,
Injectable,
InjectionToken,
OnDestroy,
Optional,
Inject,
Provider,
SkipSelf,
OnDestroy,
} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';


export const LIVE_ANNOUNCER_ELEMENT_TOKEN = new InjectionToken<HTMLElement>('liveAnnouncerElement');

/** Possible politeness levels. */
export type AriaLivePoliteness = 'off' | 'polite' | 'assertive';

@Injectable()
@Injectable({providedIn: 'root'})
export class LiveAnnouncer implements OnDestroy {
private _liveElement: Element;
private readonly _liveElement: Element;

constructor(
@Optional() @Inject(LIVE_ANNOUNCER_ELEMENT_TOKEN) elementToken: any,
Expand DownExpand Up@@ -81,14 +80,15 @@ export class LiveAnnouncer implements OnDestroy {

}

/** @docs-private */

/** @docs-private @deprecated @deletion-target 7.0.0 */
export function LIVE_ANNOUNCER_PROVIDER_FACTORY(
parentDispatcher: LiveAnnouncer, liveElement: any, _document: any) {
return parentDispatcher || new LiveAnnouncer(liveElement, _document);
}

/** @docs-private */
export const LIVE_ANNOUNCER_PROVIDER = {
/** @docs-private @deprecated @deletion-target 7.0.0 */
export const LIVE_ANNOUNCER_PROVIDER: Provider = {
// If there is already a LiveAnnouncer available, use that. Otherwise, provide a new one.
provide: LiveAnnouncer,
deps: [
Expand Down
1 change: 1 addition & 0 deletions src/cdk/a11y/public-api.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@ export * from './key-manager/list-key-manager';
export * from './focus-trap/focus-trap';
export * from './interactivity-checker/interactivity-checker';
export * from './live-announcer/live-announcer';
export * from './live-announcer/live-announcer-token';
export * from './focus-monitor/focus-monitor';
export * from './fake-mousedown';
export * from './a11y-module';
3 changes: 1 addition & 2 deletions src/cdk/accordion/accordion-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,13 +7,12 @@
*/

import {NgModule} from '@angular/core';
import {UNIQUE_SELECTION_DISPATCHER_PROVIDER} from '@angular/cdk/collections';
import {CdkAccordion} from './accordion';
import {CdkAccordionItem} from './accordion-item';


@NgModule({
exports: [CdkAccordion, CdkAccordionItem],
declarations: [CdkAccordion, CdkAccordionItem],
providers: [UNIQUE_SELECTION_DISPATCHER_PROVIDER],
})
export class CdkAccordionModule {}
29 changes: 29 additions & 0 deletions src/cdk/bidi/BUILD.bazel
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")


ng_module(
name = "bidi",
Expand All@@ -8,3 +10,30 @@ ng_module(
deps = ["@rxjs"],
tsconfig = ":tsconfig-build.json",
)

ts_library(
name = "bidi_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":bidi",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)

ts_web_test(
name = "unit_tests",
bootstrap = [
"//:web_test_bootstrap_scripts",
],

# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":bidi_test_sources",
],
)
6 changes: 0 additions & 6 deletions src/cdk/bidi/bidi-module.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,17 +7,11 @@
*/

import {NgModule} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {Dir} from './dir';
import {DIR_DOCUMENT, Directionality} from './directionality';


@NgModule({
exports: [Dir],
declarations: [Dir],
providers: [
{provide: DIR_DOCUMENT, useExisting: DOCUMENT},
Directionality,
]
})
export class BidiModule { }
31 changes: 31 additions & 0 deletions src/cdk/bidi/dir-document-token.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {DOCUMENT} from '@angular/common';
import {inject, InjectionToken} from '@angular/core';


/**
* Injection token used to inject the document into Directionality.
* This is used so that the value can be faked in tests.
*
* We can't use the real document in tests because changing the real `dir` causes geometry-based
* tests in Safari to fail.
*
* We also can't re-provide the DOCUMENT token from platform-brower because the unit tests
* themselves use things like `querySelector` in test code.
*
* This token is defined in a separate file from Directionality as a workaround for
* https://github.com/angular/angular/issues/22559
*
* @docs-private
*/
export const DIR_DOCUMENT = new InjectionToken<Document>('cdk-dir-doc', {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside, do we really need a separate token for the document here? We can easily stub out the DOCUMENT itself in the tests.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was originally doing this I found that re-providing common's DOCUMENT with something else made Angular not work.

providedIn: 'root',
factory: () => inject(DOCUMENT),
});
Loading