From cb338a2c614ae83d53db2eadec13f2d3c6ae9530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=8B?= <94534613+BoyYangzai@users.noreply.github.com> Date: Fri, 30 Jun 2023 14:19:06 +0800 Subject: [PATCH] fix: Button disabled style with link or href case (#43091) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Button disabled style with link or href case * chore: update * fix: update link disable logic * test: update snapshot * chore: update * chore: update code Co-authored-by: wxh16144 * Update components/button/style/index.ts Co-authored-by: Wuxh --------- Co-authored-by: 洋 Co-authored-by: wuxh Co-authored-by: wxh16144 Co-authored-by: MadCcc <1075746765@qq.com> Co-authored-by: Wuxh --- components/button/button.tsx | 7 +++---- components/button/style/index.ts | 32 ++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/components/button/button.tsx b/components/button/button.tsx index c3072af7e4..868b60186e 100644 --- a/components/button/button.tsx +++ b/components/button/button.tsx @@ -216,8 +216,6 @@ const InternalButton: React.ForwardRefRenderFunction< const linkButtonRestProps = omit(rest as ButtonProps & { navigate: any }, ['navigate']); - const hrefAndDisabled = linkButtonRestProps.href !== undefined && mergedDisabled; - const classes = classNames( prefixCls, hashId, @@ -232,7 +230,6 @@ const InternalButton: React.ForwardRefRenderFunction< [`${prefixCls}-block`]: block, [`${prefixCls}-dangerous`]: !!danger, [`${prefixCls}-rtl`]: direction === 'rtl', - [`${prefixCls}-disabled`]: hrefAndDisabled, }, compactItemClassnames, className, @@ -261,7 +258,9 @@ const InternalButton: React.ForwardRefRenderFunction< return wrapSSR( } diff --git a/components/button/style/index.ts b/components/button/style/index.ts index 23df848cad..3737efe86c 100644 --- a/components/button/style/index.ts +++ b/components/button/style/index.ts @@ -115,8 +115,12 @@ const genSharedButtonStyle: GenerateStyle = (token): CSS }; }; -const genHoverActiveButtonStyle = (hoverStyle: CSSObject, activeStyle: CSSObject): CSSObject => ({ - '&:not(:disabled)': { +const genHoverActiveButtonStyle = ( + btnCls: string, + hoverStyle: CSSObject, + activeStyle: CSSObject, +): CSSObject => ({ + [`&:not(:disabled):not(${btnCls}-disabled)`]: { '&:hover': hoverStyle, '&:active': activeStyle, }, @@ -161,6 +165,7 @@ const genGhostButtonStyle = ( boxShadow: 'none', ...genHoverActiveButtonStyle( + btnCls, { backgroundColor: 'transparent', ...hoverStyle, @@ -180,7 +185,7 @@ const genGhostButtonStyle = ( }); const genSolidDisabledButtonStyle: GenerateStyle = (token) => ({ - '&:disabled': { + [`&:disabled, &${token.componentCls}-disabled`]: { ...genDisabledStyle(token), }, }); @@ -190,7 +195,7 @@ const genSolidButtonStyle: GenerateStyle = (token) => ({ }); const genPureDisabledButtonStyle: GenerateStyle = (token) => ({ - '&:disabled': { + [`&:disabled, &${token.componentCls}-disabled`]: { cursor: 'not-allowed', color: token.colorTextDisabled, }, @@ -206,6 +211,7 @@ const genDefaultButtonStyle: GenerateStyle = (token) => boxShadow: `0 ${token.controlOutlineWidth}px 0 ${token.controlTmpOutline}`, ...genHoverActiveButtonStyle( + token.componentCls, { color: token.colorPrimaryHover, borderColor: token.colorPrimaryHover, @@ -229,6 +235,7 @@ const genDefaultButtonStyle: GenerateStyle = (token) => borderColor: token.colorError, ...genHoverActiveButtonStyle( + token.componentCls, { color: token.colorErrorHover, borderColor: token.colorErrorBorderHover, @@ -260,6 +267,7 @@ const genPrimaryButtonStyle: GenerateStyle = (token) => boxShadow: `0 ${token.controlOutlineWidth}px 0 ${token.controlOutline}`, ...genHoverActiveButtonStyle( + token.componentCls, { color: token.colorTextLightSolid, backgroundColor: token.colorPrimaryHover, @@ -291,6 +299,7 @@ const genPrimaryButtonStyle: GenerateStyle = (token) => boxShadow: `0 ${token.controlOutlineWidth}px 0 ${token.colorErrorOutline}`, ...genHoverActiveButtonStyle( + token.componentCls, { backgroundColor: token.colorErrorHover, }, @@ -329,6 +338,7 @@ const genLinkButtonStyle: GenerateStyle = (token) => ({ color: token.colorLink, ...genHoverActiveButtonStyle( + token.componentCls, { color: token.colorLinkHover, }, @@ -343,6 +353,7 @@ const genLinkButtonStyle: GenerateStyle = (token) => ({ color: token.colorError, ...genHoverActiveButtonStyle( + token.componentCls, { color: token.colorErrorHover, }, @@ -358,6 +369,7 @@ const genLinkButtonStyle: GenerateStyle = (token) => ({ // Type: Text const genTextButtonStyle: GenerateStyle = (token) => ({ ...genHoverActiveButtonStyle( + token.componentCls, { color: token.colorText, backgroundColor: token.colorBgTextHover, @@ -375,6 +387,7 @@ const genTextButtonStyle: GenerateStyle = (token) => ({ ...genPureDisabledButtonStyle(token), ...genHoverActiveButtonStyle( + token.componentCls, { color: token.colorErrorHover, backgroundColor: token.colorErrorBg, @@ -387,14 +400,6 @@ const genTextButtonStyle: GenerateStyle = (token) => ({ }, }); -// Href and Disabled -const genDisabledButtonStyle: GenerateStyle = (token) => ({ - ...genDisabledStyle(token), - [`&${token.componentCls}:hover`]: { - ...genDisabledStyle(token), - }, -}); - const genTypeButtonStyle: GenerateStyle = (token) => { const { componentCls } = token; @@ -404,7 +409,6 @@ const genTypeButtonStyle: GenerateStyle = (token) => { [`${componentCls}-dashed`]: genDashedButtonStyle(token), [`${componentCls}-link`]: genLinkButtonStyle(token), [`${componentCls}-text`]: genTextButtonStyle(token), - [`${componentCls}-disabled`]: genDisabledButtonStyle(token), }; }; @@ -528,7 +532,7 @@ export default genComponentStyleHook('Button', (token) => { // Block genBlockButtonStyle(buttonToken), - // Group (type, ghost, danger, disabled, loading) + // Group (type, ghost, danger, loading) genTypeButtonStyle(buttonToken), // Button Group