Skip to content

Conversation

MuxinFeng
Copy link
Contributor

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

related issue

💡 Background and solution

目前按钮的 disabled 状态是通过属性选择器来匹配的,当 typelink,并且添加 href 属性时,button 会变成 a 标签,而 a 标签没有 disabled 属性。
解决方法是为 a 标签单独写一套 disabled 样式。

📝 Changelog

Language Changelog
🇺🇸 English -
🇨🇳 Chinese -

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

@github-actions
Copy link
Contributor

github-actions bot commented Jun 8, 2022

Prepare preview

@@ -385,6 +385,24 @@
}
.button-disabled(@disabled-color; transparent; transparent);
}
// link button disabled style
.btn-link-disabled() {
Copy link
Member

@MadCcc MadCcc Jun 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉不用再写一套 mixin,直接在原来的 选择器上加一个 &-disabled 就行。
另外和 4.21.0 之前一样的话就是想办法把 disabled 给 a 标签就行了,这样我觉得更合理一些,不用加多余的 css。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前从master切的分支,然后我发现button的样式在这期间重构过,所以又提了一份新的,求再看看。新的实现思路就跟您说的一样了。

@MadCcc
Copy link
Member

MadCcc commented Jun 8, 2022

需要添加 test case

@MuxinFeng
Copy link
Contributor Author

测试代码之前没写过,我稍微研究下~

@afc163
Copy link
Member

afc163 commented Jun 9, 2022

master 先修吧。

@codecov
Copy link

codecov bot commented Jun 9, 2022

Codecov Report

Merging #35957 (551da7d) into next (771836c) will not change coverage.
The diff coverage is 100.00%.

❗ Current head 551da7d differs from pull request most recent head a12219f. Consider uploading reports for the commit a12219f to get more accurate results

@@            Coverage Diff             @@
##              next    #35957    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          430       491    +61     
  Lines         7995      8601   +606     
  Branches      2402      2429    +27     
==========================================
+ Hits          7995      8601   +606     
Impacted Files Coverage Δ
components/_util/motion.tsx 100.00% <ø> (ø)
components/form/FormList.tsx 100.00% <ø> (ø)
components/image/PreviewGroup.tsx 100.00% <ø> (ø)
components/image/index.tsx 100.00% <ø> (ø)
components/input-number/index.tsx 100.00% <ø> (ø)
components/input/ClearableLabeledInput.tsx 100.00% <ø> (ø)
components/input/Group.tsx 100.00% <ø> (ø)
components/input/Input.tsx 100.00% <ø> (ø)
components/input/TextArea.tsx 100.00% <ø> (ø)
components/layout/layout.tsx 100.00% <ø> (ø)
... and 158 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 771836c...a12219f. Read the comment docs.

@MuxinFeng
Copy link
Contributor Author

test 已添加~

@MadCcc
Copy link
Member

MadCcc commented Jun 9, 2022

要在 master 上修

@@ -268,6 +270,7 @@ const InternalButton: React.ForwardRefRenderFunction<unknown, ButtonProps> = (pr
[`${prefixCls}-block`]: block,
[`${prefixCls}-dangerous`]: !!danger,
[`${prefixCls}-rtl`]: direction === 'rtl',
[`${prefixCls}-href-disabled`]: linkButtonRestProps.href !== undefined && mergedDisabled,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

试试看绕过 ts 检查直接把 disabled 加到 a 标签上

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,我试试

@@ -328,6 +328,15 @@ describe('Button', () => {
expect(onClick).not.toHaveBeenCalled();
});

it('should match class .ant-btn-href-disabled when button is disabled and href is not undefined', () => {
const wrapper = mount(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用 testing-library 吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好滴

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里能多给一点关键词吗

@MuxinFeng MuxinFeng changed the base branch from next to master June 9, 2022 12:15
@MuxinFeng
Copy link
Contributor Author

已经提到 master 啦,然后 test case 我有点拿不准,感觉没啥测试的必要,就没提了

className={classes}
onClick={handleClick}
// @ts-ignore
disabled={mergedDisabled}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a 上有 disabled 属性?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以看下上面,大佬给了个建议。要是给 a 加 disabled 属性不推荐的话,我再换回原来的

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样 React 有 warning 的吧。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#35975 大佬要不再看看这种解法,比较朴实😂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

回头可以关掉一个

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其实我更倾向于另一种方法,因为目前 button 的 disabled 状态都是通过属性选择器来匹配的,但是 a 标签没有该属性。

所以我打算额外为 a 标签添加一个类,虽然看上去代码多了点,但考虑到 button 和 a 实现 disabled 的方式南辕北辙,分开写其实更清楚。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以前的实现就是直接添加的 disabled 属性,考虑 css 覆盖直接还原是最稳的

@MuxinFeng MuxinFeng changed the title fix: Button has no disabled style when link type fix: Button has no disabled style when link type,add disabled to <a> Jun 9, 2022
@MadCcc
Copy link
Member

MadCcc commented Jun 10, 2022

添加新的 class 吧,确实该去掉一点不常规的用法了

@MadCcc MadCcc closed this Jun 10, 2022
@MuxinFeng MuxinFeng deleted the fix-button-style branch March 15, 2023 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants