Skip to content

Commit 5daf7ff

Browse files
jelbournmmalerba
authored andcommitted
docs(overlay): expand overview for overlay (#6976)
1 parent 5e02aef commit 5daf7ff

File tree

1 file changed

+86
-1
lines changed

1 file changed

+86
-1
lines changed

src/cdk/overlay/overlay.md

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,88 @@
11
### Overlay
22

3-
A service used to manage overlays.
3+
The `Overlay` service provides a way to open floating panels on the screen.
4+
5+
### Creating overlays
6+
Calling `overlay.create()` will return an `OverlayRef` instance. This instance is a handle for
7+
managing that specific overlay.
8+
9+
The `OverlayRef` _is_ a `PortalHost`- once created, content can be added by attaching a `Portal`.
10+
See the documentation on portals for further information.
11+
```ts
12+
const overlayRef = overlay.create();
13+
const userProfilePortal = new ComponentPortal(UserProfile);
14+
overlayRef.attach(userProfilePortal);
15+
```
16+
17+
### Configuring an overlay
18+
When creating an overlay, an optional configuration object can be provided.
19+
```ts
20+
const overlayRef = overlay.create({
21+
height: '400px',
22+
width: '600px',
23+
});
24+
```
25+
26+
The full set of configuration options can be found in the API documentation.
27+
28+
#### Position strategies
29+
The `positionStrategy` configuration option determines how the overlay will be positioned on-screen.
30+
There are two position strategies available as part of the library: `GlobalPositionStrategy` and
31+
`ConnectedPositionStrategy`.
32+
33+
`GlobalPositionStrategy` is used for overlays that require a specific position in the viewport,
34+
unrelated to other elements. This is commonly used for modal dialogs and application-level
35+
notifications.
36+
37+
`ConnectedPositionStrategy` is used for overlays that are positioned relative to some other "origin"
38+
element on the page. This is commonly used for menus, pickers, and tooltips. When using the
39+
connected strategy, a set of preferred positions is provided; the "best" position will be selected
40+
based on how well the overlay would fit within the viewport.
41+
42+
A custom position strategy can be created by implementing the `PositionStrategy` interface.
43+
Each `PositionStrategy` defines an `apply` method that is called whenever the overlay's position
44+
should be updated. A custom position strategy can additionally expose any other APIs necessary as
45+
related to the positioning of the overlay element.
46+
47+
48+
#### Scroll strategies
49+
The `scrollStrategy` configuration option determines how the overlay will react to scrolling outside
50+
the overlay element. There are four scroll strategies available as part of the library.
51+
52+
`NoopScrollStrategy` is the default option. This strategy does nothing.
53+
54+
`CloseScrollStrategy` will automatically close the overlay when scrolling occurs.
55+
56+
`BlockScrollStrategy` will block page scrolling while the overlay is open. Note that some
57+
applications may implement special or customized page scrolling; if the `BlockScrollStrategy`
58+
conflicts with this kind of situation, it can be overriden by re-providing `BlockScrollStrategy`
59+
with a custom implementation.
60+
61+
`RepositionScrollStrategy` will re-position the overlay element on scroll. Note that this will have
62+
some performance impact on scrolling- users should weigh this cost in the context of each specific
63+
application.
64+
65+
66+
A custom scroll strategy can be created by implementing the `ScrollStrategy` interface. Each
67+
strategy will typically inject `ScrollDispatcher` (from `@angular/cdk/scrolling`) to be notified
68+
of when scrolling takes place. See the documentation for `ScrollDispatcher` for more information
69+
on how scroll events are detected and dispatched.
70+
71+
### The overlay container
72+
The `OverlayContainer` provides a handle to the container element in which all individual overlay
73+
elements are rendered. By default, the overlay container is appended directly to the document body
74+
so that an overlay is never clipped by an `overflow: hidden` parent.
75+
76+
#### Full-screen overlays
77+
The `FullscreenOverlayContainer` is an alternative to `OverlayContainer` that supports correct
78+
displaying of overlay elements in
79+
[fullscreen mode](https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen).
80+
81+
`FullscreenOverlayContainer` can be enabled by providing it in your `NgModule`:
82+
```ts
83+
@NgModule({
84+
providers: [{provide: OverlayContainer, useClass: FullscreenOverlayContainer}],
85+
// ...
86+
})
87+
export class MyModule { }
88+
```

0 commit comments

Comments
 (0)