Skip to content

Commit f7da3f2

Browse files
authored
docs(cdk/overlay): add popover to docs (#33434)
Updates the overlay docs to mention our usage of the popover API. Fixes #32729.
1 parent 6accbf3 commit f7da3f2

3 files changed

Lines changed: 52 additions & 3 deletions

File tree

goldens/cdk/overlay/index.api.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ export class OverlayContainer implements OnDestroy {
437437

438438
// @public
439439
export interface OverlayDefaultConfig {
440-
// (undocumented)
441440
usePopover?: boolean;
442441
}
443442

src/cdk/overlay/overlay.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,57 @@ on how scroll events are detected and dispatched.
8989

9090
### The overlay container
9191
The `OverlayContainer` provides a handle to the container element in which all individual overlay
92-
elements are rendered. By default, the overlay container is appended directly to the document body
93-
so that an overlay is never clipped by an `overflow: hidden` parent.
92+
elements are rendered. By default, the overlay container is appended directly to the document body.
93+
94+
In supported browsers, the CDK renders overlays as native
95+
[Popover](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API) elements.
96+
The `OverlayContainer` acts as the default insertion point for these elements, but because they are
97+
rendered as popovers, the browser automatically promotes them to the top layer. This natively
98+
bypasses `z-index` and `overflow: hidden` clipping issues without needing complex DOM stacking
99+
workarounds.
100+
101+
If a browser does not support the Popover API, the CDK falls back to the traditional
102+
behavior where appending to the `OverlayContainer` is the only way to avoid clipping.
103+
104+
You can explicitly configure the popover behavior using the `usePopover` option when creating an
105+
overlay. If you need to globally disable the popover behavior, you can provide the
106+
`OVERLAY_DEFAULT_CONFIG` injection token:
107+
108+
```ts
109+
import {OVERLAY_DEFAULT_CONFIG} from '@angular/cdk/overlay';
110+
111+
bootstrapApplication(MyApp, {
112+
providers: [
113+
{provide: OVERLAY_DEFAULT_CONFIG, useValue: {usePopover: false}}
114+
]
115+
});
116+
```
117+
118+
#### Popover DOM location
119+
When an overlay is rendered as a native popover, it doesn't strictly need to be placed inside the
120+
`OverlayContainer` to escape `overflow: hidden` containers. The `FlexibleConnectedPositionStrategy`
121+
allows you to change where the popover is inserted in the DOM via the `withPopoverLocation()` method.
122+
123+
This is particularly beneficial for accessibility. By injecting the popover directly next to its
124+
trigger element in the DOM structure, the DOM sequence naturally follows the visual logical order,
125+
while the browser continues to render the popover on top of everything.
126+
127+
If you are using the `cdkConnectedOverlay` directive, you can configure this using the
128+
`cdkConnectedOverlayUsePopover` input. The supported locations are:
129+
- `'global'` (default): Inserts the popover inside the `OverlayContainer`.
130+
- `'inline'`: Inserts the popover in the DOM immediately following its trigger element.
131+
- `{type: 'parent', element: HTMLElement}`: Inserts the popover as a child of a specific custom element.
132+
133+
```html
134+
<!-- Inserts the overlay popover right next to the trigger button in the DOM -->
135+
<button cdkOverlayOrigin #trigger="cdkOverlayOrigin">Open Menu</button>
136+
<ng-template cdkConnectedOverlay
137+
[cdkConnectedOverlayOrigin]="trigger"
138+
[cdkConnectedOverlayOpen]="isOpen"
139+
cdkConnectedOverlayUsePopover="inline">
140+
<div class="menu-panel">Menu content</div>
141+
</ng-template>
142+
```
94143

95144
#### Full-screen overlays
96145
The `FullscreenOverlayContainer` is an alternative to `OverlayContainer` that supports correct

src/cdk/overlay/overlay.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {ScrollStrategyOptions} from './scroll/index';
3434

3535
/** Object used to configure the default options for overlays. */
3636
export interface OverlayDefaultConfig {
37+
/** Whether overlays should be rendered inside popovers by default. */
3738
usePopover?: boolean;
3839
}
3940

0 commit comments

Comments
 (0)