Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button 组件在初始 loading 状态下,样式有误 #5392

Closed
maroon1 opened this issue Jun 8, 2020 · 1 comment · Fixed by #5404
Closed

Button 组件在初始 loading 状态下,样式有误 #5392

maroon1 opened this issue Jun 8, 2020 · 1 comment · Fixed by #5404

Comments

@maroon1
Copy link
Contributor

maroon1 commented Jun 8, 2020

Reproduction link

https://codesandbox.io/s/billowing-waterfall-kzh26?file=/src/app/app.component.ts

Steps to reproduce

设置 Icon Button 的 nzLoading 属性为 true

What is expected?

Icon Button 宽度为正常的 32px

What is actually happening?

Icon Button 宽度为 46px

Environment Info
ng-zorro-antd 9.1.2
Browser Microsoft Edge 83

查看源码发现是 iconCount 计算有误导致 ant-btn-icon-only 的没有应用应用到元素上

assertIconOnly(element: HTMLButtonElement, renderer: Renderer2): void {
const listOfNode = Array.from(element.childNodes);
const iconCount = listOfNode.filter(node => node.nodeName === 'I').length;
const noText = listOfNode.every(node => node.nodeName !== '#text');
const noSpan = listOfNode.every(node => node.nodeName !== 'SPAN');
const isIconOnly = noSpan && noText && iconCount === 1;
if (isIconOnly) {
renderer.addClass(element, 'ant-btn-icon-only');
}
}

当初始 nzLoadingtrue 时,assertIconOnly方法中的 iconCount 变量会包含 Loading 图标节点,导致 iconCount 数量计算有误

可以在 iconCount 的计算中加入 nzLoading 的判断条件来修正计算结果,例如

if (this.nzLoading) {
  iconCount -= 1;
}
@zorro-bot
Copy link

zorro-bot bot commented Jun 8, 2020

Translation of this issue:

Button assembly in the initial loading state, error pattern

Reproduction link

[Https://codesandbox.io/s/billowing-waterfall-kzh26?file=/src/app/app.component.ts](https://codesandbox.io/s/billowing-waterfall-kzh26?file=/ src / app / app.component.ts)

Steps to reproduce

Icon Button set of nzLoading property to true

What is expected?

Icon Button width normal 32px

What is actually happening?

Icon Button width 46px

Environment Info
Ng-zorro-antd 9.1.2
Browser Microsoft Edge 83

View source found to be iconCount arithmetical error led to the ant-btn-icon-only not apply to the application element

assertIconOnly(element: HTMLButtonElement, renderer: Renderer2): void {
const listOfNode = Array.from(element.childNodes);
const iconCount = listOfNode.filter(node => node.nodeName === 'I').length;
const noText = listOfNode.every(node => node.nodeName !== '#text');
const noSpan = listOfNode.every(node => node.nodeName !== 'SPAN');
const isIconOnly = noSpan && noText && iconCount === 1;
if (isIconOnly) {
renderer.addClass(element, 'ant-btn-icon-only');
}
}

When the initial nzLoading as true, assertIconOnly method comprising Loading variables iconCount node icons, resulting in incorrect calculation of the number of iconCount

NzLoading may be added in the calculation of the iconCount judgment condition correction calculation results, e.g.

`Typescript if (this.nzLoading) { iconCount - = 1; } `

vthinkxie pushed a commit to vthinkxie/ng-zorro-antd that referenced this issue Jun 11, 2020
vthinkxie pushed a commit to vthinkxie/ng-zorro-antd that referenced this issue Jun 11, 2020
hsuanxyz pushed a commit to hsuanxyz/ng-zorro-antd that referenced this issue Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants