Skip to content

Commit 17c19cc

Browse files
committed
fix(multiple): expand type for restoreFocus (#32877)
Fixes that the dialog and bottom sheet didn't expose all the possible values for the `restoreValue` option from the CDK dialog, even though they pass the value straight through to it. Fixes #32875. (cherry picked from commit f6b7739)
1 parent 1f66af8 commit 17c19cc

File tree

7 files changed

+27
-23
lines changed

7 files changed

+27
-23
lines changed

goldens/cdk/dialog/index.api.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class DialogConfig<D = unknown, R = unknown, C extends DialogContainer =
144144
panelClass?: string | string[];
145145
positionStrategy?: PositionStrategy;
146146
providers?: StaticProvider[] | ((dialogRef: R, config: DialogConfig<D, R, C>, container: C) => StaticProvider[]);
147-
restoreFocus?: boolean | string | HTMLElement;
147+
restoreFocus?: RestoreFocusValue;
148148
role?: DialogRole;
149149
scrollStrategy?: ScrollStrategy;
150150
templateContext?: Record<string, any> | (() => Record<string, any>);
@@ -195,6 +195,9 @@ export class DialogRef<R = unknown, C = unknown> {
195195
// @public
196196
export type DialogRole = 'dialog' | 'alertdialog';
197197

198+
// @public
199+
export type RestoreFocusValue = boolean | string | HTMLElement;
200+
198201
// @public (undocumented)
199202
export function throwDialogContentAlreadyAttachedError(): void;
200203

goldens/material/bottom-sheet/index.api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { InjectionToken } from '@angular/core';
1818
import { Injector } from '@angular/core';
1919
import { Observable } from 'rxjs';
2020
import { OnDestroy } from '@angular/core';
21+
import { RestoreFocusValue } from '@angular/cdk/dialog';
2122
import { ScrollStrategy } from '@angular/cdk/overlay';
2223
import { TemplateRef } from '@angular/core';
2324
import { ViewContainerRef } from '@angular/core';
@@ -63,7 +64,7 @@ export class MatBottomSheetConfig<D = any> {
6364
maxHeight?: number | string;
6465
minHeight?: number | string;
6566
panelClass?: string | string[];
66-
restoreFocus?: boolean;
67+
restoreFocus?: RestoreFocusValue;
6768
scrollStrategy?: ScrollStrategy;
6869
viewContainerRef?: ViewContainerRef;
6970
}

goldens/material/dialog/index.api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { Observable } from 'rxjs';
2626
import { OnChanges } from '@angular/core';
2727
import { OnDestroy } from '@angular/core';
2828
import { OnInit } from '@angular/core';
29+
import { RestoreFocusValue } from '@angular/cdk/dialog';
2930
import { ScrollStrategy } from '@angular/cdk/overlay';
3031
import { SimpleChanges } from '@angular/core';
3132
import { Subject } from 'rxjs';
@@ -143,7 +144,7 @@ export class MatDialogConfig<D = any> {
143144
minWidth?: number | string;
144145
panelClass?: string | string[];
145146
position?: DialogPosition;
146-
restoreFocus?: boolean;
147+
restoreFocus?: RestoreFocusValue;
147148
role?: DialogRole;
148149
scrollStrategy?: ScrollStrategy;
149150
viewContainerRef?: ViewContainerRef;

goldens/material/dialog/testing/index.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import * as i0 from '@angular/core';
2222
import { Injector } from '@angular/core';
2323
import { Observable } from 'rxjs';
2424
import { OnDestroy } from '@angular/core';
25+
import { RestoreFocusValue } from '@angular/cdk/dialog';
2526
import { ScrollStrategy } from '@angular/cdk/overlay';
2627
import { Subject } from 'rxjs';
2728
import { TemplateRef } from '@angular/core';

src/cdk/dialog/dialog-config.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ import {FocusOrigin} from '../a11y';
1616
/** Options for where to set focus to automatically on dialog open */
1717
export type AutoFocusTarget = 'dialog' | 'first-tabbable' | 'first-heading';
1818

19+
/**
20+
* Value that determines the focus restoration behavior for a dialog.
21+
* The values represent the following behaviors:
22+
* - `boolean` - when true, will return focus to the element that was focused before the dialog
23+
* was opened, otherwise won't restore focus at all.
24+
* - `string` - focus will be restored to the first element that matches the CSS selector.
25+
* - `HTMLElement` - focus will be restored to the specific element.
26+
*/
27+
export type RestoreFocusValue = boolean | string | HTMLElement;
28+
1929
/** Valid ARIA roles for a dialog. */
2030
export type DialogRole = 'dialog' | 'alertdialog';
2131

@@ -121,15 +131,8 @@ export class DialogConfig<D = unknown, R = unknown, C extends DialogContainer =
121131
*/
122132
autoFocus?: AutoFocusTarget | string | boolean = 'first-tabbable';
123133

124-
/**
125-
* Whether the dialog should restore focus to the previously-focused element upon closing.
126-
* Has the following behavior based on the type that is passed in:
127-
* - `boolean` - when true, will return focus to the element that was focused before the dialog
128-
* was opened, otherwise won't restore focus at all.
129-
* - `string` - focus will be restored to the first element that matches the CSS selector.
130-
* - `HTMLElement` - focus will be restored to the specific element.
131-
*/
132-
restoreFocus?: boolean | string | HTMLElement = true;
134+
/** Configures the focus restoration behavior. See `RestoreFocusValue` for more information. */
135+
restoreFocus?: RestoreFocusValue = true;
133136

134137
/**
135138
* Scroll strategy to be used for the dialog. This determines how

src/material/bottom-sheet/bottom-sheet-config.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import {InjectionToken, Injector, ViewContainerRef} from '@angular/core';
1010
import {Direction} from '@angular/cdk/bidi';
1111
import {ScrollStrategy} from '@angular/cdk/overlay';
12+
import {RestoreFocusValue} from '@angular/cdk/dialog';
1213

1314
/** Options for where to set focus to automatically on dialog open */
1415
export type AutoFocusTarget = 'dialog' | 'first-tabbable' | 'first-heading';
@@ -71,11 +72,8 @@ export class MatBottomSheetConfig<D = any> {
7172
*/
7273
autoFocus?: AutoFocusTarget | string | boolean = 'first-tabbable';
7374

74-
/**
75-
* Whether the bottom sheet should restore focus to the
76-
* previously-focused element, after it's closed.
77-
*/
78-
restoreFocus?: boolean = true;
75+
/** Configures the focus restoration behavior. See `RestoreFocusValue` for more information. */
76+
restoreFocus?: RestoreFocusValue = true;
7977

8078
/** Scroll strategy to be used for the bottom sheet. */
8179
scrollStrategy?: ScrollStrategy;

src/material/dialog/dialog-config.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import {ViewContainerRef, Injector} from '@angular/core';
1010
import {Direction} from '@angular/cdk/bidi';
1111
import {ScrollStrategy} from '@angular/cdk/overlay';
12-
import {DialogConfig} from '@angular/cdk/dialog';
12+
import {DialogConfig, RestoreFocusValue} from '@angular/cdk/dialog';
1313

1414
/** Options for where to set focus to automatically on dialog open */
1515
export type AutoFocusTarget = 'dialog' | 'first-tabbable' | 'first-heading';
@@ -129,11 +129,8 @@ export class MatDialogConfig<D = any> {
129129
*/
130130
autoFocus?: AutoFocusTarget | string | boolean = 'first-tabbable';
131131

132-
/**
133-
* Whether the dialog should restore focus to the
134-
* previously-focused element, after it's closed.
135-
*/
136-
restoreFocus?: boolean = true;
132+
/** Configures the focus restoration behavior. See `RestoreFocusValue` for more information. */
133+
restoreFocus?: RestoreFocusValue = true;
137134

138135
/** Whether to wait for the opening animation to finish before trapping focus. */
139136
delayFocusTrap?: boolean = true;

0 commit comments

Comments
 (0)