MCPcopy Create free account
hub / github.com/angular/components / _setPosition

Function _setPosition

src/material/menu/menu-trigger-base.ts:403–451  ·  view source on GitHub ↗

* Sets the appropriate positions on a position strategy * so the overlay connects with the trigger correctly. * @param positionStrategy Strategy whose position to update.

(menu: MatMenuPanel, positionStrategy: FlexibleConnectedPositionStrategy)

Source from the content-addressed store, hash-verified

401 * @param positionStrategy Strategy whose position to update.
402 */
403 private _setPosition(menu: MatMenuPanel, positionStrategy: FlexibleConnectedPositionStrategy) {
404 let [originX, originFallbackX]: HorizontalConnectionPos[] =
405 menu.xPosition === 'before' ? ['end', 'start'] : ['start', 'end'];
406
407 let [overlayY, overlayFallbackY]: VerticalConnectionPos[] =
408 menu.yPosition === 'above' ? ['bottom', 'top'] : ['top', 'bottom'];
409
410 let [originY, originFallbackY] = [overlayY, overlayFallbackY];
411 let [overlayX, overlayFallbackX] = [originX, originFallbackX];
412 let offsetY = 0;
413
414 if (this._triggersSubmenu()) {
415 // When the menu is a sub-menu, it should always align itself
416 // to the edges of the trigger, instead of overlapping it.
417 overlayFallbackX = originX = menu.xPosition === 'before' ? 'start' : 'end';
418 originFallbackX = overlayX = originX === 'end' ? 'start' : 'end';
419
420 if (this._parentMaterialMenu) {
421 if (this._parentInnerPadding == null) {
422 const firstItem = this._parentMaterialMenu.items.first;
423 this._parentInnerPadding = firstItem ? firstItem._getHostElement().offsetTop : 0;
424 }
425
426 offsetY = overlayY === 'bottom' ? this._parentInnerPadding : -this._parentInnerPadding;
427 }
428 } else if (!menu.overlapTrigger) {
429 originY = overlayY === 'top' ? 'bottom' : 'top';
430 originFallbackY = overlayFallbackY === 'top' ? 'bottom' : 'top';
431 }
432
433 positionStrategy.withPositions([
434 {originX, originY, overlayX, overlayY, offsetY},
435 {originX: originFallbackX, originY, overlayX: overlayFallbackX, overlayY, offsetY},
436 {
437 originX,
438 originY: originFallbackY,
439 overlayX,
440 overlayY: overlayFallbackY,
441 offsetY: -offsetY,
442 },
443 {
444 originX: originFallbackX,
445 originY: originFallbackY,
446 overlayX: overlayFallbackX,
447 overlayY: overlayFallbackY,
448 offsetY: -offsetY,
449 },
450 ]);
451 }
452
453 /** Returns a stream that emits whenever an action that should close the menu occurs. */
454 private _menuClosingActions() {

Callers

nothing calls this directly

Calls 2

withPositionsMethod · 0.80
_getHostElementMethod · 0.45

Tested by

no test coverage detected