Skip to content

bug(Menu): Menu overlay panel position error when set value to viewportMargin #23127

Open
@HengNN

Description

@HengNN

Reproduction

Steps to reproduce:

  1. In the menu trigger source code, add viewport margin to overlay position strategy.
private _getOverlayConfig(): OverlayConfig {
    return new OverlayConfig({
      positionStrategy: this._overlay.position()
          .flexibleConnectedTo(this._element)
          .withLockedPosition()
          .withGrowAfterOpen()
          .withViewportMargin(10) // add view port margin to avoid form covering scroll bar
          .withTransformOriginOn('.mat-menu-panel, .mat-mdc-menu-panel'),
      backdropClass: this.menu.backdropClass || 'cdk-overlay-transparent-backdrop',
      panelClass: this.menu.overlayPanelClass,
      scrollStrategy: this._scrollStrategy(),
      direction: this._dir
    });
  1. Set menu position: xPosition="before", yPosition="below".
  2. Click the menu trigger button, the menu overlay panel is not right-aligned.

no margin
image

has margin 10
image

Expected Behavior

What behavior were you expecting to see?

The menu overlay panel should right align with the trigger button.

Actual Behavior

What behavior did you actually see?

The menu overlay panel's right position is wrong.

Environment

  • Angular:
  • CDK/Material:
  • Browser(s):
  • Operating System (e.g. Windows, macOS, Ubuntu):

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/overlay

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions