Skip to content

Commit

Permalink
chore(menu-surface): Position surface to the right if the anchor is w…
Browse files Browse the repository at this point in the history
…ider than the surface and is flipped horizontally.

PiperOrigin-RevId: 340245340
  • Loading branch information
material-web-copybara authored and copybara-github committed Nov 2, 2020
1 parent 5511c52 commit bd6e302
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/mdc-menu-surface/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ export class MDCMenuSurfaceFoundation extends MDCFoundation<MDCMenuSurfaceAdapte

const isRtl = this.adapter.isRtl();
const isFlipRtl = this.hasBit(this.anchorCorner, CornerBit.FLIP_RTL);
const hasRightBit = this.hasBit(this.anchorCorner, CornerBit.RIGHT);
const hasRightBit = this.hasBit(this.anchorCorner, CornerBit.RIGHT) ||
this.hasBit(corner, CornerBit.RIGHT);

// Whether surface attached to right side of anchor element.
let isAnchoredToRight = false;
Expand Down
11 changes: 11 additions & 0 deletions packages/mdc-menu-surface/test/foundation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,17 @@ describe('MDCMenuSurfaceFoundation', () => {
.toHaveBeenCalledWith({right: 0, top: 0});
});

testFoundation(
'#open Surface is positioned from right side in LTR when corner is flipped horizontally and anchor is wider than menu.',
({foundation, mockAdapter}) => {
initAnchorLayout(mockAdapter, wideTopLeft);
foundation.flipCornerHorizontally();
foundation.open();
jasmine.clock().tick(1); // Run to frame.
expect(mockAdapter.setTransformOrigin).toHaveBeenCalledWith('center top');
expect(mockAdapter.setPosition).toHaveBeenCalledWith({right: 0, top: 0});
});

testFoundation(
'#open Surface is positioned from left side in LTR when corner is flipped horizontally and space is not available on the left side.',
({foundation, mockAdapter}) => {
Expand Down

0 comments on commit bd6e302

Please sign in to comment.