Skip to content

Commit 18947a5

Browse files
committed
fix(cdk/a11y): breaking changes for v22
Removes deprecated APIs for v22 in the `cdk/a11y` package. BREAKING CHANGES: * `CDK_DESCRIBEDBY_HOST_ATTRIBUTE` has been removed. * `CDK_DESCRIBEDBY_ID_PREFIX` has been removed. * The `injector` parameter of the `ConfigurableFocusTrap` and `FocusTrap` constructors is now required. * The boolean parameter of `ConfigurableFocusTrapFactory.create` has been replaced with a config object. * `MESSAGES_CONTAINER_ID` has been removed.
1 parent fccc2ef commit 18947a5

8 files changed

Lines changed: 16 additions & 62 deletions

File tree

goldens/cdk/a11y/index.api.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ export class AriaDescriber implements OnDestroy {
6161
// @public
6262
export type AriaLivePoliteness = 'off' | 'polite' | 'assertive';
6363

64-
// @public @deprecated
65-
export const CDK_DESCRIBEDBY_HOST_ATTRIBUTE = "cdk-describedby-host";
66-
67-
// @public @deprecated
68-
export const CDK_DESCRIBEDBY_ID_PREFIX = "cdk-describedby-message";
69-
7064
// @public
7165
export class CdkAriaLive implements OnDestroy {
7266
constructor();
@@ -124,7 +118,7 @@ export class CdkTrapFocus implements OnDestroy, AfterContentInit, OnChanges, DoC
124118

125119
// @public
126120
export class ConfigurableFocusTrap extends FocusTrap implements ManagedFocusTrap {
127-
constructor(_element: HTMLElement, _checker: InteractivityChecker, _ngZone: NgZone, _document: Document, _focusTrapManager: FocusTrapManager, _inertStrategy: FocusTrapInertStrategy, config: ConfigurableFocusTrapConfig, injector?: Injector);
121+
constructor(_element: HTMLElement, _checker: InteractivityChecker, _ngZone: NgZone, _document: Document, _focusTrapManager: FocusTrapManager, _inertStrategy: FocusTrapInertStrategy, config: ConfigurableFocusTrapConfig, injector: Injector);
128122
destroy(): void;
129123
_disable(): void;
130124
_enable(): void;
@@ -141,8 +135,6 @@ export interface ConfigurableFocusTrapConfig {
141135
export class ConfigurableFocusTrapFactory {
142136
constructor();
143137
create(element: HTMLElement, config?: ConfigurableFocusTrapConfig): ConfigurableFocusTrap;
144-
// @deprecated (undocumented)
145-
create(element: HTMLElement, deferCaptureElements: boolean): ConfigurableFocusTrap;
146138
// (undocumented)
147139
static ɵfac: i0.ɵɵFactoryDeclaration<ConfigurableFocusTrapFactory, never>;
148140
// (undocumented)
@@ -216,8 +208,7 @@ export type FocusOrigin = 'touch' | 'mouse' | 'keyboard' | 'program' | null;
216208

217209
// @public
218210
export class FocusTrap {
219-
constructor(_element: HTMLElement, _checker: InteractivityChecker, _ngZone: NgZone, _document: Document, deferAnchors?: boolean,
220-
_injector?: Injector | undefined);
211+
constructor(_element: HTMLElement, _checker: InteractivityChecker, _ngZone: NgZone, _document: Document, deferAnchors: boolean | undefined, _injector: Injector);
221212
attachAnchors(): boolean;
222213
destroy(): void;
223214
// (undocumented)
@@ -237,7 +228,8 @@ export class FocusTrap {
237228
focusLastTabbableElement(options?: FocusOptions): boolean;
238229
focusLastTabbableElementWhenReady(options?: FocusOptions): Promise<boolean>;
239230
hasAttached(): boolean;
240-
readonly _injector?: Injector | undefined;
231+
// (undocumented)
232+
readonly _injector: Injector;
241233
// (undocumented)
242234
readonly _ngZone: NgZone;
243235
// (undocumented)
@@ -425,9 +417,6 @@ export interface LiveAnnouncerDefaultOptions {
425417
// @public
426418
export type LiveAnnouncerMessage = string | SafeHtml;
427419

428-
// @public @deprecated
429-
export const MESSAGES_CONTAINER_ID = "cdk-describedby-message-container";
430-
431420
// @public @deprecated
432421
export const NOOP_TREE_KEY_MANAGER_FACTORY_PROVIDER: Provider;
433422

src/cdk-experimental/popover-edit/focus-escape-notifier.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {Service, NgZone, inject, DOCUMENT} from '@angular/core';
9+
import {Service, NgZone, inject, DOCUMENT, Injector} from '@angular/core';
1010

1111
import {FocusTrap, InteractivityChecker} from '@angular/cdk/a11y';
1212
import {Observable, Subject} from 'rxjs';
@@ -30,7 +30,7 @@ export class FocusEscapeNotifier extends FocusTrap {
3030
ngZone: NgZone,
3131
document: Document,
3232
) {
33-
super(element, checker, ngZone, document, true /* deferAnchors */);
33+
super(element, checker, ngZone, document, true /* deferAnchors */, inject(Injector));
3434

3535
// The focus trap adds "anchors" at the beginning and end of a trapped region that redirect
3636
// focus. We override that redirect behavior here with simply emitting on a stream.

src/cdk/a11y/aria-describer/aria-describer.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import {A11yModule, CDK_DESCRIBEDBY_HOST_ATTRIBUTE} from '../index';
2-
import {AriaDescriber} from './aria-describer';
1+
import {AriaDescriber, CDK_DESCRIBEDBY_HOST_ATTRIBUTE} from './aria-describer';
32
import {ComponentFixture, TestBed} from '@angular/core/testing';
43
import {Component, ElementRef, ViewChild, inject, ChangeDetectionStrategy} from '@angular/core';
54

@@ -395,7 +394,6 @@ function expectMessage(el: Element, message: string) {
395394
<div id="description-with-existing-id">Hello</div>
396395
<div description-without-id>Hey</div>
397396
`,
398-
imports: [A11yModule],
399397
changeDetection: ChangeDetectionStrategy.Eager,
400398
})
401399
class TestApp {

src/cdk/a11y/aria-describer/aria-describer.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,10 @@ export interface RegisteredMessage {
2323
referenceCount: number;
2424
}
2525

26-
/**
27-
* ID used for the body container where all messages are appended.
28-
* @deprecated No longer being used. To be removed.
29-
* @breaking-change 14.0.0
30-
*/
31-
export const MESSAGES_CONTAINER_ID = 'cdk-describedby-message-container';
26+
/** ID prefix used for each created message element. */
27+
const CDK_DESCRIBEDBY_ID_PREFIX = 'cdk-describedby-message';
3228

33-
/**
34-
* ID prefix used for each created message element.
35-
* @deprecated To be turned into a private variable.
36-
* @breaking-change 14.0.0
37-
*/
38-
export const CDK_DESCRIBEDBY_ID_PREFIX = 'cdk-describedby-message';
39-
40-
/**
41-
* Attribute given to each host element that is described by a message element.
42-
* @deprecated To be turned into a private variable.
43-
* @breaking-change 14.0.0
44-
*/
29+
/** Attribute given to each host element that is described by a message element. */
4530
export const CDK_DESCRIBEDBY_HOST_ATTRIBUTE = 'cdk-describedby-host';
4631

4732
/** Global incremental identifier for each registered message element. */

src/cdk/a11y/focus-trap/configurable-focus-trap-factory.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,18 @@ export class ConfigurableFocusTrapFactory {
4141
*/
4242
create(element: HTMLElement, config?: ConfigurableFocusTrapConfig): ConfigurableFocusTrap;
4343

44-
/**
45-
* @deprecated Pass a config object instead of the `deferCaptureElements` flag.
46-
* @breaking-change 11.0.0
47-
*/
48-
create(element: HTMLElement, deferCaptureElements: boolean): ConfigurableFocusTrap;
49-
5044
create(
5145
element: HTMLElement,
52-
config: ConfigurableFocusTrapConfig | boolean = {defer: false},
46+
config: ConfigurableFocusTrapConfig = {defer: false},
5347
): ConfigurableFocusTrap {
54-
let configObject: ConfigurableFocusTrapConfig;
55-
if (typeof config === 'boolean') {
56-
configObject = {defer: config};
57-
} else {
58-
configObject = config;
59-
}
6048
return new ConfigurableFocusTrap(
6149
element,
6250
this._checker,
6351
this._ngZone,
6452
this._document,
6553
this._focusTrapManager,
6654
this._inertStrategy,
67-
configObject,
55+
config,
6856
this._injector,
6957
);
7058
}

src/cdk/a11y/focus-trap/configurable-focus-trap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class ConfigurableFocusTrap extends FocusTrap implements ManagedFocusTrap
4141
private _focusTrapManager: FocusTrapManager,
4242
private _inertStrategy: FocusTrapInertStrategy,
4343
config: ConfigurableFocusTrapConfig,
44-
injector?: Injector,
44+
injector: Injector,
4545
) {
4646
super(_element, _checker, _ngZone, _document, config.defer, injector);
4747
this._focusTrapManager.register(this);

src/cdk/a11y/focus-trap/focus-trap.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ export class FocusTrap {
6464
readonly _ngZone: NgZone,
6565
readonly _document: Document,
6666
deferAnchors = false,
67-
/** @breaking-change 20.0.0 param to become required */
68-
readonly _injector?: Injector,
67+
readonly _injector: Injector,
6968
) {
7069
if (!deferAnchors) {
7170
this.attachAnchors();
@@ -359,12 +358,7 @@ export class FocusTrap {
359358

360359
/** Executes a function when the zone is stable. */
361360
private _executeOnStable(fn: () => any): void {
362-
// TODO: remove this conditional when injector is required in the constructor.
363-
if (this._injector) {
364-
afterNextRender(fn, {injector: this._injector});
365-
} else {
366-
setTimeout(fn);
367-
}
361+
afterNextRender(fn, {injector: this._injector});
368362
}
369363
}
370364

src/cdk/a11y/public-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.dev/license
77
*/
8-
export * from './aria-describer/aria-describer';
8+
export {AriaDescriber, RegisteredMessage} from './aria-describer/aria-describer';
99
export * from './aria-describer/aria-reference';
1010
export * from './key-manager/activedescendant-key-manager';
1111
export * from './key-manager/focus-key-manager';

0 commit comments

Comments
 (0)