Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 1631198

Browse files
EstebanG23copybara-github
authored andcommitted
fix(menu): Remove anchorSize height from calculations when anchored to bottom
PiperOrigin-RevId: 350849236
1 parent 089de51 commit 1631198

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

packages/mdc-menu-surface/foundation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ export class MDCMenuSurfaceFoundation extends MDCFoundation<MDCMenuSurfaceAdapte
381381
let availableTop;
382382
let availableBottom;
383383
if (isAnchoredToBottom) {
384-
availableTop = viewportDistance.top - MARGIN_TO_EDGE + anchorSize.height +
385-
this.anchorMargin.bottom;
384+
availableTop =
385+
viewportDistance.top - MARGIN_TO_EDGE + this.anchorMargin.bottom;
386386
availableBottom =
387387
viewportDistance.bottom - MARGIN_TO_EDGE - this.anchorMargin.bottom;
388388
} else {
@@ -393,7 +393,7 @@ export class MDCMenuSurfaceFoundation extends MDCFoundation<MDCMenuSurfaceAdapte
393393
}
394394

395395
const isAvailableBottom = availableBottom - surfaceSize.height > 0;
396-
if (!isAvailableBottom && availableTop >= availableBottom) {
396+
if (!isAvailableBottom && availableTop > availableBottom) {
397397
// Attach bottom side of surface to the anchor.
398398
corner = this.setBit(corner, CornerBit.BOTTOM);
399399
}

packages/mdc-menu-surface/test/foundation.test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,20 @@ describe('MDCMenuSurfaceFoundation', () => {
674674
.toHaveBeenCalledWith({right: 0, top: 20});
675675
});
676676

677+
testFoundation(
678+
'#open from anchor center of viewport with large menu surface height, ' +
679+
'BOTTOM_START anchor corner',
680+
({foundation, mockAdapter}) => {
681+
initAnchorLayout(mockAdapter, wideCenter, true, 500);
682+
foundation.setAnchorCorner(Corner.BOTTOM_START);
683+
foundation.open();
684+
jasmine.clock().tick(1); // Run to frame.
685+
expect(mockAdapter.setTransformOrigin)
686+
.toHaveBeenCalledWith('center top');
687+
expect(mockAdapter.setPosition)
688+
.toHaveBeenCalledWith({right: 0, top: 20});
689+
});
690+
677691
testFoundation(
678692
'#open from wide anchor center of viewport, BOTTOM_END anchor corner, RTL',
679693
({foundation, mockAdapter}) => {
@@ -849,8 +863,10 @@ describe('MDCMenuSurfaceFoundation', () => {
849863
foundation.flipCornerHorizontally();
850864
foundation.open();
851865
jasmine.clock().tick(1); // Run to frame.
852-
expect(mockAdapter.setTransformOrigin).toHaveBeenCalledWith('center top');
853-
expect(mockAdapter.setPosition).toHaveBeenCalledWith({right: 0, top: 0});
866+
expect(mockAdapter.setTransformOrigin)
867+
.toHaveBeenCalledWith('center top');
868+
expect(mockAdapter.setPosition)
869+
.toHaveBeenCalledWith({right: 0, top: 0});
854870
});
855871

856872
testFoundation(

0 commit comments

Comments
 (0)