angular / angular/components

bug(Overlay): FlexibleConnectedPositionStrategy withViewportMargin not working

未关闭
#24,259 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
area: cdk/overlay P3
主要语言
TypeScript
星标
25k
派生
6.8k
平均合并
1 天 8 小时
30 天内合并 PR
91

描述

### Is this a regression?

- [ ] Yes, this behavior used to work in the previous version

### The previous version in which this bug was not present was

_No response_

### Description

When using overlay with `FlexibleConnectedPositionStrategy` and `withViewportMargin()`, overlay ignores provided margin value and still opens in first preffered position, when it should move to second one. Overlay cant be pushed and has no flexible dimmensions set.
![image](https://user-images.githubusercontent.com/17365268/150674093-04daf594-9194-47fb-ac60-98b1464d8502.png)

### Reproduction

https://stackblitz.com/edit/viewport-margin-bug?file=src%2Fapp%2Fapp.component.ts
(Red line shows 100px margin edge)

Steps to reproduce:
1. Create overlay with popup 100px x 100px
2. Locate its origin point 150px from top edge of viewport.
3. Add two positions to FlexibleConnectedPositionStrategy:
```
{
originX: 'end',
originY: 'top',
overlayX: 'start',
overlayY: 'bottom',
},
{
originX: 'end',
originY: 'bottom',
overlayX: 'start',
overlayY: 'top',
},
```
4. Use `withViewportMargin(100)`.
5. Use `withFlexibleDimensions(false)`
6. Use `withPush(false)`

### Expected Behavior

Since `withViewPortMargin(100)` was set, and overlay cannot be pushed or shrinked, then it should fallback to second preffered position in which popup opens downwards.
```
{
originX: 'end',
originY: 'bottom',
overlayX: 'start',
overlayY: 'top',
},
```

### Actual Behavior

Overlay still opens according to first position which is upward, ignoring viewport margin

### Environment

- Angular: 13.1.3
- CDK/Material: 13.1.3
- Browser(s): Chrome 97
- Operating System (e.g. Windows, macOS, Ubuntu): macOS

贡献指南

打开贡献指南

调研方向

从链接的 StackBlitz 复现开始,检查 FlexibleConnectedPositionStrategy,重点关注 withViewportMargin 如何与禁用的弹性尺寸和 push 行为交互。当第一个位置违反 100px 的 viewport 边距时 overlay 回退到第二个位置,并且为报告的配置提供覆盖测试,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript
领域
frontend
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。