@@ -61,7 +61,7 @@ choices on a temporary surface.
61
61
When opened, menus position themselves to an anchor. Thus, either ` anchor ` or
62
62
` anchorElement ` must be supplied to ` md-menu ` before opening. Additionally, a
63
63
shared parent of ` position:relative ` should be present around the menu and it's
64
- anchor.
64
+ anchor, because the default menu is positioned relative to the anchor element .
65
65
66
66
Menus also render menu items such as ` md-menu-item ` and handle keyboard
67
67
navigation between ` md-menu-item ` s as well as typeahead functionality.
@@ -215,14 +215,14 @@ Granny Smith, and Red Delicious."](images/menu/usage-submenu.webp)
215
215
</script >
216
216
```
217
217
218
- ### Fixed menus
218
+ ### Fixed-positioned menus
219
219
220
220
Internally menu uses ` position: absolute ` by default. Though there are cases
221
221
when the anchor and the node cannot share a common ancestor that is `position:
222
222
relative`, or sometimes, menu will render below another item due to limitations
223
223
with ` position: absolute ` . In most of these cases, you would want to use the
224
224
` positioning="fixed" ` attribute to position the menu relative to the window
225
- instead of relative to the parent .
225
+ instead of relative to the element .
226
226
227
227
> Note: Fixed menu positions are positioned relative to the window and not the
228
228
> document. This means that the menu will not scroll with the anchor as the page
@@ -264,6 +264,64 @@ Cucumber."](images/menu/usage-fixed.webp)
264
264
</script >
265
265
```
266
266
267
+ ### Document-positioned menus
268
+
269
+ When set to ` positioning="document" ` , ` md-menu ` will position itself relative to
270
+ the document as opposed to the element or the window from ` "absolute" ` and
271
+ ` "fixed" ` values respectively.
272
+
273
+ Document level positioning is useful for the following cases:
274
+
275
+ - There are no ancestor elements that produce a ` relative ` positioning
276
+ context.
277
+ - ` position: relative `
278
+ - ` position: absolute `
279
+ - ` position: fixed `
280
+ - ` transform: translate(x, y) `
281
+ - etc.
282
+ - The menu is hoisted to the top of the DOM
283
+ - The last child of ` <body> `
284
+ - [ Top layer] ( https://developer.mozilla.org/en-US/docs/Glossary/Top_layer )
285
+ <!-- {.external} -->
286
+ - The same ` md-menu ` is being reused and the contents and anchors are being
287
+ dynamically changed
288
+
289
+ <!-- no-catalog-start -->
290
+
291
+ ![ "A filled button that says open document menu. There is an open menu anchored
292
+ to the bottom of the button with three items, Apple, Banana, and
293
+ Cucumber."] ( images/menu/usage-document.webp )
294
+
295
+ <!-- no-catalog-end -->
296
+ <!-- catalog-include "figures/menu/usage-document.html" -->
297
+
298
+ ``` html
299
+ <!-- Note the lack of position: relative parent. -->
300
+ <div style =" margin : 16px ;" >
301
+ <md-filled-button id =" usage-document-anchor" >Open document menu</md-filled-button >
302
+ </div >
303
+
304
+ <!-- document menus do not require a common ancestor with the anchor. -->
305
+ <md-menu positioning =" document" id =" usage-document" anchor =" usage-document-anchor" >
306
+ <md-menu-item >
307
+ <div slot =" headline" >Apple</div >
308
+ </md-menu-item >
309
+ <md-menu-item >
310
+ <div slot =" headline" >Banana</div >
311
+ </md-menu-item >
312
+ <md-menu-item >
313
+ <div slot =" headline" >Cucumber</div >
314
+ </md-menu-item >
315
+ </md-menu >
316
+
317
+ <script type =" module" >
318
+ const anchorEl = document .body .querySelector (' #usage-document-anchor' );
319
+ const menuEl = document .body .querySelector (' #usage-document' );
320
+
321
+ anchorEl .addEventListener (' click' , () => { menuEl .open = ! menuEl .open ; });
322
+ </script >
323
+ ```
324
+
267
325
## Accessibility
268
326
269
327
By default Menu is set up to function as a ` role="menu" ` with children as
@@ -395,7 +453,6 @@ a sharp 0px border radius.](images/menu/theming.webp)
395
453
396
454
## API
397
455
398
-
399
456
### MdMenu <code >< ; md-menu> ; </code >
400
457
401
458
#### Properties
0 commit comments