-
Notifications
You must be signed in to change notification settings - Fork 6.8k
refactor(cdk-experimental/dialog): rewrite experimental dialog #24759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,29 +5,26 @@ | |
* 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 {Injector, ViewContainerRef} from '@angular/core'; | ||
|
||
import { | ||
ViewContainerRef, | ||
ComponentFactoryResolver, | ||
Injector, | ||
StaticProvider, | ||
Type, | ||
} from '@angular/core'; | ||
import {Direction} from '@angular/cdk/bidi'; | ||
import {ComponentType} from '@angular/cdk/overlay'; | ||
import {CdkDialogContainer} from './dialog-container'; | ||
import {PositionStrategy, ScrollStrategy} from '@angular/cdk/overlay'; | ||
import {BasePortalOutlet} from '@angular/cdk/portal'; | ||
|
||
/** Options for where to set focus to automatically on dialog open */ | ||
export type AutoFocusTarget = 'dialog' | 'first-tabbable' | 'first-heading'; | ||
|
||
/** Valid ARIA roles for a dialog element. */ | ||
/** Valid ARIA roles for a dialog. */ | ||
export type DialogRole = 'dialog' | 'alertdialog'; | ||
|
||
/** Possible overrides for a dialog's position. */ | ||
export interface DialogPosition { | ||
top?: string; | ||
bottom?: string; | ||
left?: string; | ||
right?: string; | ||
} | ||
|
||
export class DialogConfig<D = any> { | ||
/** Component to use as the container for the dialog. */ | ||
containerComponent?: ComponentType<CdkDialogContainer>; | ||
|
||
/** Configuration for opening a modal dialog. */ | ||
export class DialogConfig<D = unknown, R = unknown, C extends BasePortalOutlet = BasePortalOutlet> { | ||
/** | ||
* Where the attached component should live in Angular's *logical* component tree. | ||
* This affects what is available for injection and the change detection order for the | ||
|
@@ -42,67 +39,115 @@ export class DialogConfig<D = any> { | |
*/ | ||
injector?: Injector; | ||
|
||
/** The id of the dialog. */ | ||
/** ID for the dialog. If omitted, a unique one will be generated. */ | ||
id?: string; | ||
|
||
/** The ARIA role of the dialog. */ | ||
/** The ARIA role of the dialog element. */ | ||
role?: DialogRole = 'dialog'; | ||
|
||
/** Custom class(es) for the overlay panel. */ | ||
/** Optional CSS class or classes applied to the overlay panel. */ | ||
panelClass?: string | string[] = ''; | ||
|
||
/** Whether the dialog has a background. */ | ||
/** Whether the dialog has a backdrop. */ | ||
hasBackdrop?: boolean = true; | ||
|
||
/** Custom class(es) for the backdrop. */ | ||
backdropClass?: string | undefined = ''; | ||
/** Optional CSS class or classes applied to the overlay backdrop. */ | ||
backdropClass?: string | string[] = ''; | ||
|
||
/** Whether the dialog can be closed by user interaction. */ | ||
/** Whether the dialog closes with the escape key or pointer events outside the panel element. */ | ||
disableClose?: boolean = false; | ||
|
||
/** The width of the dialog. */ | ||
/** Width of the dialog. */ | ||
width?: string = ''; | ||
|
||
/** The height of the dialog. */ | ||
/** Height of the dialog. */ | ||
height?: string = ''; | ||
|
||
/** The minimum width of the dialog. */ | ||
minWidth?: string | number = ''; | ||
/** Min-width of the dialog. If a number is provided, assumes pixel units. */ | ||
minWidth?: number | string; | ||
|
||
/** The minimum height of the dialog. */ | ||
minHeight?: string | number = ''; | ||
/** Min-height of the dialog. If a number is provided, assumes pixel units. */ | ||
minHeight?: number | string; | ||
|
||
/** The maximum width of the dialog. */ | ||
maxWidth?: string | number = '80vw'; | ||
/** Max-width of the dialog. If a number is provided, assumes pixel units. Defaults to 80vw. */ | ||
maxWidth?: number | string; | ||
|
||
/** The maximum height of the dialog. */ | ||
maxHeight?: string | number = ''; | ||
/** Max-height of the dialog. If a number is provided, assumes pixel units. */ | ||
maxHeight?: number | string; | ||
|
||
/** The position of the dialog. */ | ||
position?: DialogPosition; | ||
/** Strategy to use when positioning the dialog. Defaults to centering it on the page. */ | ||
positionStrategy?: PositionStrategy; | ||
|
||
/** Data to be injected into the dialog content. */ | ||
/** Data being injected into the child component. */ | ||
data?: D | null = null; | ||
|
||
/** The layout direction for the dialog content. */ | ||
/** Layout direction for the dialog's content. */ | ||
direction?: Direction; | ||
|
||
/** ID of the element that describes the dialog. */ | ||
ariaDescribedBy?: string | null = null; | ||
|
||
/** Aria label to assign to the dialog element */ | ||
/** ID of the element that labels the dialog. */ | ||
ariaLabelledBy?: string | null = null; | ||
|
||
/** Dialog label applied via `aria-label` */ | ||
ariaLabel?: string | null = null; | ||
|
||
/** Whether this a modal dialog. Used to set the `aria-modal` attribute. */ | ||
ariaModal?: boolean = true; | ||
|
||
/** | ||
* Where the dialog should focus on open. | ||
* @breaking-change 14.0.0 Remove boolean option from autoFocus. Use string or | ||
* AutoFocusTarget instead. | ||
*/ | ||
autoFocus?: AutoFocusTarget | string | boolean = 'first-tabbable'; | ||
|
||
/** Duration of the enter animation. Has to be a valid CSS value (e.g. 100ms). */ | ||
enterAnimationDuration?: string = '225ms'; | ||
/** | ||
* Whether the dialog should restore focus to the | ||
* previously-focused element upon closing. | ||
*/ | ||
restoreFocus?: boolean = true; | ||
|
||
/** | ||
* Scroll strategy to be used for the dialog. This determines how | ||
* the dialog responds to scrolling underneath the panel element. | ||
*/ | ||
scrollStrategy?: ScrollStrategy; | ||
|
||
/** Duration of the exit animation. Has to be a valid CSS value (e.g. 50ms). */ | ||
exitAnimationDuration?: string = '225ms'; | ||
/** | ||
* Whether the dialog should close when the user navigates backwards or forwards through browser | ||
* history. This does not apply to navigation via anchor element unless using URL-hash based | ||
* routing (`HashLocationStrategy` in the Angular router). | ||
*/ | ||
closeOnNavigation?: boolean = true; | ||
|
||
/** Alternate `ComponentFactoryResolver` to use when resolving the associated component. */ | ||
componentFactoryResolver?: ComponentFactoryResolver; | ||
Comment on lines
+125
to
+126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we drop this from the cdk version? It should be useless now, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the Material one supports it, the CDK has to too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't follow why, though. The Material one can still expose it for backwards compatibility, but I don't think it needs to be here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It gets passed around when creating the portal which happens inside the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does the Material dialog need to pass it through, though? Isn't it the same to use this vs. instantiating the component directly? (which admittedly would require a code change in the portal, but we should probably do that anyway?) |
||
|
||
/** | ||
* Providers that will be exposed to the contents of the dialog. Can also | ||
* be provided as a function in order to generate the providers lazily. | ||
*/ | ||
providers?: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about this more- what's the benefit of specifying container/ref/config as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This allows apps to hook into the DI system. Otherwise these things can't be used in the constructor. |
||
| StaticProvider[] | ||
| ((dialogRef: R, config: DialogConfig<D, R, C>, container: C) => StaticProvider[]); | ||
|
||
/** | ||
* Component into which the dialog content will be rendered. Defaults to `CdkDialogContainer`. | ||
* A configuration object can be passed in to customize the providers that will be exposed | ||
* to the dialog container. | ||
*/ | ||
container?: | ||
| Type<C> | ||
| { | ||
type: Type<C>; | ||
providers: (config: DialogConfig<D, R, C>) => StaticProvider[]; | ||
}; | ||
|
||
/** | ||
* Context that will be passed to template-based dialogs. | ||
* A function can be passed in to resolve the context lazily. | ||
*/ | ||
templateContext?: Record<string, any> | (() => Record<string, any>); | ||
} |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.