-
-
Notifications
You must be signed in to change notification settings - Fork 53.5k
fix: Button has no disabled style when link type,add disabled to <a> #35957
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
Conversation
1449f42
to
2aa3402
Compare
components/button/_style/mixin.less
Outdated
@@ -385,6 +385,24 @@ | |||
} | |||
.button-disabled(@disabled-color; transparent; transparent); | |||
} | |||
// link button disabled style | |||
.btn-link-disabled() { |
There was a problem hiding this comment.
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。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
之前从master切的分支,然后我发现button的样式在这期间重构过,所以又提了一份新的,求再看看。新的实现思路就跟您说的一样了。
需要添加 test case |
2aa3402
to
a384298
Compare
测试代码之前没写过,我稍微研究下~ |
master 先修吧。 |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
a384298
to
f1088ec
Compare
test 已添加~ |
要在 master 上修 |
components/button/button.tsx
Outdated
@@ -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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
试试看绕过 ts 检查直接把 disabled 加到 a 标签上
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用 testing-library 吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好滴
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里能多给一点关键词吗
551da7d
to
a12219f
Compare
已经提到 master 啦,然后 test case 我有点拿不准,感觉没啥测试的必要,就没提了 |
className={classes} | ||
onClick={handleClick} | ||
// @ts-ignore | ||
disabled={mergedDisabled} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a 上有 disabled 属性?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以看下上面,大佬给了个建议。要是给 a 加 disabled 属性不推荐的话,我再换回原来的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这样 React 有 warning 的吧。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#35975 大佬要不再看看这种解法,比较朴实😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
回头可以关掉一个
There was a problem hiding this comment.
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 的方式南辕北辙,分开写其实更清楚。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以前的实现就是直接添加的 disabled 属性,考虑 css 覆盖直接还原是最稳的
添加新的 class 吧,确实该去掉一点不常规的用法了 |
[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
related issue
💡 Background and solution
目前按钮的
disabled
状态是通过属性选择器来匹配的,当type
为link
,并且添加href
属性时,button
会变成a
标签,而a
标签没有disabled
属性。解决方法是为
a
标签单独写一套disabled
样式。📝 Changelog
☑️ Self Check before Merge