angular - 发生 chrome 自动填充时,Mat-form-field-outline-gap 大小不正确
问题描述
当我们的应用程序最初加载并且由于使用谷歌浏览器保存登录信息而自动填充表单mat-form-field-outline-gap
时,正在使用使用密码自动填充时使用的默认字体进行计算。当字体切换到我们的字体时,间隙不再正确(太短,因为我们的字体比默认字体宽)。
如果字段不自动填充一切正常。
表单元素:
<mat-form-field appearance="outline" class="login-form">
<mat-label>Email Address</mat-label>
<input matInput
formControlName="emailAddress">
</mat-form-field>
styles.scss
包括:
@import url('https://fonts.googleapis.com/css?family=Montserrat:300,400,500,700&display=swap');
.login-form {
font-family: 'Montserrat';
}
它显然与调用间隙的方法何时运行有关,但我不知道如何解决这个问题。我已经尝试了以下猴子补丁,但它仅在初始加载时修复问题并在其他情况下破坏问题!
export function patchMatFormField() {
const patchedFormFieldClass = MatFormField.prototype as any;
patchedFormFieldClass.updateOutlineGapOriginal = MatFormField.prototype.updateOutlineGap;
MatFormField.prototype.updateOutlineGap = function() {
this.updateOutlineGapOriginal();
const container = this._connectionContainerRef.nativeElement;
const gapEls = container.querySelectorAll('.luma-input .mat-form-field-outline-gap');
gapEls.forEach((gp) => {
const calculatedGapWidth = +gp.style.width.replace('px', '');
const gapWidth = calculatedGapWidth / 0.85;
gp.style.width = `${gapWidth}px`;
});
};
}
更新
我可以通过重新运行来让它工作,updateOutlineGap()
如这篇文章所示,但我只能通过将超时设置为来让它工作~500ms
(当被限制时它似乎不起作用......)。我想知道是否有办法判断何时加载/应用字体?
解决方案
推荐阅读
- apache-spark - 使用 jdbc 将数据帧保存到 hive 或从 Hive 查询 spark 数据帧临时视图
- r - 是否可以在 R 中使用 plotly 设置主题?
- excel - 将 Microsoft Office 架构中的 XML 文档批量导入 Excel
- uicollectionviewcell - 如何将渐变层添加到集合视图单元格
- neo4j - 带有 js-neo4j-driver 查询数组的 Neo4j 事务
- amazon-web-services - Elastic Beanstalk 疯狂地终止和重新创建实例
- javascript - 如何按x坐标y坐标对像素进行排序?
- python - 使用 DataArray ax.set_title 绘制问题
- xslt - XSLT 代码根据值选择不同的属性
- azure-devops - 运行 terraform init 步骤时出现 Azure Devops 管道错误