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

fix: dropdown menu item #39368

Closed
wants to merge 6 commits into from
Closed

fix: dropdown menu item #39368

wants to merge 6 commits into from

Conversation

samyarkd
Copy link
Contributor

@samyarkd samyarkd commented Dec 7, 2022

Disable dropdown menu item when type is equal to danger.

[中文版模板 / 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

💡 Background and solution

Problem: When we set the dropdown menu item properties danger and disabled to true, the disabled styling doesn't apply. As shown in below code sandbox 👇
https://codesandbox.io/embed/antd-reproduction-template-forked-ip8ypb?fontsize=14&hidenavigation=1&theme=dark

Solution: check if dropdown menu item is disabled or not
If yes -> we are not going to apply danger staying, same as how button handles it (shown in code sandbox).

📝 Changelog

This file "components/menu/MenuItem.tsx" is updated.

Language Changelog
🇺🇸 English fix: apply disabled style to dropdown menu item when type is danger : #39322

☑️ Self-Check before Merge

⚠️ Please check all items below before requesting a reviewing. ⚠️

  • 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

Disable dropdown menu item when type is equal to danger
@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2022

@codecov
Copy link

codecov bot commented Dec 7, 2022

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage 👍

Coverage data is based on head (b9e5c30) compared to base (fc3c2f1).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff            @@
##            master    #39368   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          556       556           
  Lines         9602      9624   +22     
  Branches      2714      2722    +8     
=========================================
+ Hits          9602      9624   +22     
Impacted Files Coverage Δ
components/dropdown/dropdown-button.tsx 100.00% <ø> (ø)
components/modal/Modal.tsx 100.00% <ø> (ø)
components/modal/PurePanel.tsx 100.00% <ø> (ø)
components/popconfirm/PurePanel.tsx 100.00% <ø> (ø)
components/transfer/operation.tsx 100.00% <ø> (ø)
components/_util/ActionButton.tsx 100.00% <100.00%> (ø)
components/button/button.tsx 100.00% <100.00%> (ø)
components/grid/row.tsx 100.00% <0.00%> (ø)
components/spin/index.tsx 100.00% <0.00%> (ø)
components/tour/index.tsx 100.00% <0.00%> (ø)
... and 9 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -66,7 +66,7 @@ export default class MenuItem extends React.Component<MenuItemProps> {
{...rest}
className={classNames(
{
[`${prefixCls}-item-danger`]: danger,
[`${prefixCls}-item-danger`]: this.props.disabled ? false : danger,
[`${prefixCls}-item-only-child`]: (icon ? childrenLength + 1 : childrenLength) === 1,
Copy link
Member

@Wxh16144 Wxh16144 Dec 7, 2022

Choose a reason for hiding this comment

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

I think we can solve the problem here by increasing the css selector weights.

v4.x

&-disabled {
color: @disabled-color;
cursor: not-allowed;

v5.x

'&-disabled': {
color: colorTextDisabled,
cursor: 'not-allowed',

what do you think?

-      &-disabled {
+      &&-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.

Thank you

I tried this out in version 5x, but it didn't work out.
It will break the disable option as shown in below (Image-1). But yes this is much cleaner and better i guess but i couldn't make it i tried a few more ways of increasing the CSS specificity, but they didn't work.

Image-1

code-1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about adding !important statement to color and background-color ?

Copy link
Member

Choose a reason for hiding this comment

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

The use of !important is bad, in 5.x it can be changed to this

 
-            '&-disabled': {
+            [`&${menuCls}-item-disabled`]: {
               color: colorTextDisabled,

and switch the order of returns

     return [
+      genStatusStyle(dropdownToken),
       genBaseStyle(dropdownToken),
       genButtonStyle(dropdownToken),
-      genStatusStyle(dropdownToken),
     ];

Copy link
Member

Choose a reason for hiding this comment

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

this is just my suggestion, still need official help to review @afc163

Copy link
Member

Choose a reason for hiding this comment

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

@Wxh16144's suggestion is what I think too.

@yoyo837
Copy link
Contributor

yoyo837 commented Dec 8, 2022

Fix for v4? Please send PR to branch v4-stable

@Wxh16144

This comment was marked as resolved.

@@ -456,9 +456,9 @@ export default genComponentStyleHook(
dropdownEdgeChildPadding: paddingXXS,
});
return [
genStatusStyle(dropdownToken),
Copy link
Member

@MadCcc MadCcc Dec 9, 2022

Choose a reason for hiding this comment

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

I prefer to remain the order because genBaseStyle should be at first.
Maybe problem is solved without changing order since the priority has been raised?

Copy link
Member

Choose a reason for hiding this comment

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

I prefer to remain the order because genBaseStyle should be at first. Maybe problem is solved without changing order since the priority has been raised?

I've also tested this and it still doesn't fix the problem without reordering

Copy link
Member

@MadCcc MadCcc Dec 12, 2022

Choose a reason for hiding this comment

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

Should provide higher priority instead of reordering, since it may cause other issue related with order.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made some changes without reordering the functions

Remove reordering functions by increasing `disable` class on line 350 CSS specificity
@samyarkd samyarkd requested review from MadCcc and Wxh16144 and removed request for MadCcc and Wxh16144 December 15, 2022 14:02
@@ -347,7 +347,7 @@ const genBaseStyle: GenerateStyle<DropdownToken> = (token) => {
},
},

'&-disabled': {
[`&${menuCls}-item-disabled${menuCls}-item-disabled`]: {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
[`&${menuCls}-item-disabled${menuCls}-item-disabled`]: {
[`&-disabled, &-disabled${menuCls}-item-danger`]: {

How about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested it and it didn't work

@afc163
Copy link
Member

afc163 commented Dec 23, 2022

Fixed in #39434

@afc163 afc163 closed this Dec 23, 2022
@Wxh16144
Copy link
Member

Fixed in #39434

#39434 修复的是 4.x 的,这个 PR 修复的是 5.x

@yoyo837 yoyo837 reopened this Dec 23, 2022
@yoyo837
Copy link
Contributor

yoyo837 commented Dec 23, 2022

@Wxh16144 你改过V4, 把把关

@Wxh16144

This comment was marked as outdated.

@afc163
Copy link
Member

afc163 commented Dec 29, 2022

@Wxh16144 进展如何

@Wxh16144
Copy link
Member

Wxh16144 commented Dec 29, 2022

进展如何

我认为还是最开始的解决方案 OK 一些, 查看了 <Menu /> 组件的 disabled 样式,也是通过 !important 来增加权中来实现的

[`${componentCls}-item-disabled, ${componentCls}-submenu-disabled`]: {
color: `${colorItemTextDisabled} !important`,
},


重新提交了一个 PR #39904

@Wxh16144 Wxh16144 mentioned this pull request Dec 29, 2022
20 tasks
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.

None yet

5 participants