Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(portal): add new portal that projects DOM nodes#16101
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -153,6 +153,21 @@ export class TemplatePortal<C = any> extends Portal<EmbeddedViewRef<C>> { | ||
| } | ||
| } | ||
| /** | ||
| * A `DomPortal` is a portal whose DOM element will be taken from its current position | ||
| * in the DOM and moved into a portal outlet, when it is attached. On detach, the content | ||
| * will be restored to its original position. | ||
| */ | ||
| export class DomPortal<T = HTMLElement> extends Portal<T> { | ||
| /** DOM node hosting the portal's content. */ | ||
| readonly element: T; | ||
| constructor(element: T | ElementRef<T>) { | ||
| super(); | ||
| this.element = element instanceof ElementRef ? element.nativeElement : element; | ||
| } | ||
| } | ||
| /** A `PortalOutlet` is an space that can contain a single `Portal`. */ | ||
| export interface PortalOutlet { | ||
| @@ -218,6 +233,10 @@ export abstract class BasePortalOutlet implements PortalOutlet { | ||
| } else if (portal instanceof TemplatePortal) { | ||
| this._attachedPortal = portal; | ||
| return this.attachTemplatePortal(portal); | ||
| // @breaking-change 10.0.0 remove null check for `this.attachDomPortal`. | ||
| } else if (this.attachDomPortal && portal instanceof DomPortal) { | ||
| this._attachedPortal = portal; | ||
| return this.attachDomPortal(portal); | ||
crisbeto marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| throwUnknownPortalTypeError(); | ||
| @@ -227,6 +246,9 @@ export abstract class BasePortalOutlet implements PortalOutlet { | ||
| abstract attachTemplatePortal<C>(portal: TemplatePortal<C>): EmbeddedViewRef<C>; | ||
| // @breaking-change 10.0.0 `attachDomPortal` to become a required abstract method. | ||
| readonly attachDomPortal: null | ((portal: DomPortal) => any) = null; | ||
| /** Detaches a previously attached portal. */ | ||
| detach(): void { | ||
| if (this._attachedPortal) { | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -5,3 +5,7 @@ | ||
| width: 500px; | ||
| height: 100px; | ||
| } | ||
| .demo-dad-joke { | ||
| opacity: 0.25; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.