Fix the issue where the clear icon does not show when hovering over the Select series component under the Space component. (#39468)

* fix: Fix the problem that the clear icon is not displayed when the Select series component hovers under the Space component

* refactor: 修改 Space.Compact css 优先级以及简化调用

* refactor: 修改 Space.Compact 垂直方向 css 优先级以及简化调用

* docs: 添加注释

* fix: lint

* test: update snapshot

* test: update snapshot
This commit is contained in:
Yuki Zhang 2022-12-12 16:36:46 +08:00 committed by GitHub
parent ad7501ccf8
commit 977a9a92ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 164 additions and 39 deletions

View File

@ -50,9 +50,6 @@ const genSharedButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token): CSS
...genFocusStyle(token), ...genFocusStyle(token),
}, },
...genCompactItemStyle(token, componentCls, { focus: false }),
...genCompactItemVerticalStyle(token, componentCls),
// make `btn-icon-only` not too narrow // make `btn-icon-only` not too narrow
'&-icon-only&-compact-item': { '&-icon-only&-compact-item': {
flex: 'none', flex: 'none',
@ -496,5 +493,9 @@ export default genComponentStyleHook('Button', (token) => {
// Button Group // Button Group
genGroupStyle(buttonToken), genGroupStyle(buttonToken),
// Space Compact
genCompactItemStyle(token, { focus: false }),
genCompactItemVerticalStyle(token),
]; ];
}); });

View File

@ -32,7 +32,6 @@ const genBaseStyle: GenerateStyle<CascaderToken> = (token) => {
{ {
[componentCls]: { [componentCls]: {
width: token.controlWidth, width: token.controlWidth,
...genCompactItemStyle(token, componentCls),
}, },
}, },
// ===================================================== // =====================================================
@ -153,6 +152,10 @@ const genBaseStyle: GenerateStyle<CascaderToken> = (token) => {
direction: 'rtl', direction: 'rtl',
}, },
}, },
// =====================================================
// == Space Compact ==
// =====================================================
genCompactItemStyle(token),
]; ];
}; };

View File

@ -973,11 +973,6 @@ const genPickerStyle: GenerateStyle<PickerToken> = (token) => {
borderRadius, borderRadius,
transition: `border ${motionDurationMid}, box-shadow ${motionDurationMid}`, transition: `border ${motionDurationMid}, box-shadow ${motionDurationMid}`,
// Space.Compact
...genCompactItemStyle(token, componentCls, {
focusElCls: `${componentCls}-focused`,
}),
'&:hover, &-focused': { '&:hover, &-focused': {
...genHoverStyle(token), ...genHoverStyle(token),
}, },
@ -1426,7 +1421,16 @@ export default genComponentStyleHook(
initInputToken<FullToken<'DatePicker'>>(token), initInputToken<FullToken<'DatePicker'>>(token),
initPickerPanelToken(token), initPickerPanelToken(token),
); );
return [genPickerStyle(pickerToken), genPickerStatusStyle(pickerToken)]; return [
genPickerStyle(pickerToken),
genPickerStatusStyle(pickerToken),
// =====================================================
// == Space Compact ==
// =====================================================
genCompactItemStyle(token, {
focusElCls: `${token.componentCls}-focused`,
}),
];
}, },
(token) => ({ (token) => ({
presetsWidth: 120, presetsWidth: 120,

View File

@ -63,8 +63,6 @@ const genInputNumberStyles: GenerateStyle<InputNumberToken> = (token: InputNumbe
border: `${lineWidth}px ${lineType} ${colorBorder}`, border: `${lineWidth}px ${lineType} ${colorBorder}`,
borderRadius, borderRadius,
...genCompactItemStyle(token, componentCls),
'&-rtl': { '&-rtl': {
direction: 'rtl', direction: 'rtl',
@ -396,7 +394,14 @@ export default genComponentStyleHook(
'InputNumber', 'InputNumber',
(token) => { (token) => {
const inputNumberToken = initInputToken<FullToken<'InputNumber'>>(token); const inputNumberToken = initInputToken<FullToken<'InputNumber'>>(token);
return [genInputNumberStyles(inputNumberToken), genAffixWrapperStyles(inputNumberToken)]; return [
genInputNumberStyles(inputNumberToken),
genAffixWrapperStyles(inputNumberToken),
// =====================================================
// == Space Compact ==
// =====================================================
genCompactItemStyle(inputNumberToken),
];
}, },
(token) => ({ (token) => ({
controlWidth: 90, controlWidth: 90,

View File

@ -504,7 +504,7 @@ export const genInputGroupStyle = (token: InputToken): CSSObject => {
}; };
const genInputStyle: GenerateStyle<InputToken> = (token: InputToken) => { const genInputStyle: GenerateStyle<InputToken> = (token: InputToken) => {
const { prefixCls, componentCls, controlHeightSM, lineWidth } = token; const { componentCls, controlHeightSM, lineWidth } = token;
const FIXED_CHROME_COLOR_HEIGHT = 16; const FIXED_CHROME_COLOR_HEIGHT = 16;
const colorSmallPadding = (controlHeightSM - lineWidth * 2 - FIXED_CHROME_COLOR_HEIGHT) / 2; const colorSmallPadding = (controlHeightSM - lineWidth * 2 - FIXED_CHROME_COLOR_HEIGHT) / 2;
@ -514,7 +514,6 @@ const genInputStyle: GenerateStyle<InputToken> = (token: InputToken) => {
...resetComponent(token), ...resetComponent(token),
...genBasicInputStyle(token), ...genBasicInputStyle(token),
...genStatusStyle(token), ...genStatusStyle(token),
...genCompactItemStyle(token, prefixCls),
'&[type="color"]': { '&[type="color"]': {
height: token.controlHeight, height: token.controlHeight,
@ -933,5 +932,9 @@ export default genComponentStyleHook('Input', (token) => {
genAffixStyle(inputToken), genAffixStyle(inputToken),
genGroupStyle(inputToken), genGroupStyle(inputToken),
genSearchInputStyle(inputToken), genSearchInputStyle(inputToken),
// =====================================================
// == Space Compact ==
// =====================================================
genCompactItemStyle(inputToken),
]; ];
}); });

View File

@ -262,11 +262,6 @@ const genSelectStyle: GenerateStyle<SelectToken> = (token) => {
'&&-in-form-item': { '&&-in-form-item': {
width: '100%', width: '100%',
}, },
// Space.Compact
...genCompactItemStyle(token, componentCls, {
borderElCls: `${componentCls}-selector`,
focusElCls: `${componentCls}-focused`,
}),
}, },
}, },
@ -320,6 +315,13 @@ const genSelectStyle: GenerateStyle<SelectToken> = (token) => {
}), }),
true, true,
), ),
// =====================================================
// == Space Compact ==
// =====================================================
genCompactItemStyle(token, {
borderElCls: `${componentCls}-selector`,
focusElCls: `${componentCls}-focused`,
}),
]; ];
}; };

View File

@ -448,7 +448,7 @@ exports[`renders ./components/space/demo/compact.tsx extend context correctly 1`
class="ant-space-compact ant-space-compact-block" class="ant-space-compact ant-space-compact-block"
> >
<div <div
class="ant-select ant-select-compact-item ant-select-compact-first-item ant-select-single ant-select-show-arrow" class="ant-select ant-select-compact-item ant-select-compact-first-item ant-select-single ant-select-allow-clear ant-select-show-arrow"
> >
<div <div
class="ant-select-selector" class="ant-select-selector"
@ -587,6 +587,32 @@ exports[`renders ./components/space/demo/compact.tsx extend context correctly 1`
</svg> </svg>
</span> </span>
</span> </span>
<span
aria-hidden="true"
class="ant-select-clear"
style="user-select:none;-webkit-user-select:none"
unselectable="on"
>
<span
aria-label="close-circle"
class="anticon anticon-close-circle"
role="img"
>
<svg
aria-hidden="true"
data-icon="close-circle"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm165.4 618.2l-66-.3L512 563.4l-99.3 118.4-66.1.3c-4.4 0-8-3.5-8-8 0-1.9.7-3.7 1.9-5.2l130.1-155L340.5 359a8.32 8.32 0 01-1.9-5.2c0-4.4 3.6-8 8-8l66.1.3L512 464.6l99.3-118.4 66-.3c4.4 0 8 3.5 8 8 0 1.9-.7 3.7-1.9 5.2L553.5 514l130 155c1.2 1.5 1.9 3.3 1.9 5.2 0 4.4-3.6 8-8 8z"
/>
</svg>
</span>
</span>
</div> </div>
<input <input
class="ant-input ant-input-compact-item ant-input-compact-last-item" class="ant-input ant-input-compact-item ant-input-compact-last-item"
@ -600,7 +626,7 @@ exports[`renders ./components/space/demo/compact.tsx extend context correctly 1`
class="ant-space-compact ant-space-compact-block" class="ant-space-compact ant-space-compact-block"
> >
<div <div
class="ant-select ant-select-compact-item ant-select-compact-first-item ant-select-multiple ant-select-show-search" class="ant-select ant-select-compact-item ant-select-compact-first-item ant-select-multiple ant-select-allow-clear ant-select-show-search"
style="width:50%" style="width:50%"
> >
<div <div
@ -778,6 +804,32 @@ exports[`renders ./components/space/demo/compact.tsx extend context correctly 1`
</div> </div>
</div> </div>
</div> </div>
<span
aria-hidden="true"
class="ant-select-clear"
style="user-select:none;-webkit-user-select:none"
unselectable="on"
>
<span
aria-label="close-circle"
class="anticon anticon-close-circle"
role="img"
>
<svg
aria-hidden="true"
data-icon="close-circle"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm165.4 618.2l-66-.3L512 563.4l-99.3 118.4-66.1.3c-4.4 0-8-3.5-8-8 0-1.9.7-3.7 1.9-5.2l130.1-155L340.5 359a8.32 8.32 0 01-1.9-5.2c0-4.4 3.6-8 8-8l66.1.3L512 464.6l99.3-118.4 66-.3c4.4 0 8 3.5 8 8 0 1.9-.7 3.7-1.9 5.2L553.5 514l130 155c1.2 1.5 1.9 3.3 1.9 5.2 0 4.4-3.6 8-8 8z"
/>
</svg>
</span>
</span>
</div> </div>
<input <input
class="ant-input ant-input-compact-item ant-input-compact-last-item" class="ant-input ant-input-compact-item ant-input-compact-last-item"

View File

@ -341,7 +341,7 @@ exports[`renders ./components/space/demo/compact.tsx correctly 1`] = `
class="ant-space-compact ant-space-compact-block" class="ant-space-compact ant-space-compact-block"
> >
<div <div
class="ant-select ant-select-compact-item ant-select-compact-first-item ant-select-single ant-select-show-arrow" class="ant-select ant-select-compact-item ant-select-compact-first-item ant-select-single ant-select-allow-clear ant-select-show-arrow"
> >
<div <div
class="ant-select-selector" class="ant-select-selector"
@ -398,6 +398,32 @@ exports[`renders ./components/space/demo/compact.tsx correctly 1`] = `
</svg> </svg>
</span> </span>
</span> </span>
<span
aria-hidden="true"
class="ant-select-clear"
style="user-select:none;-webkit-user-select:none"
unselectable="on"
>
<span
aria-label="close-circle"
class="anticon anticon-close-circle"
role="img"
>
<svg
aria-hidden="true"
data-icon="close-circle"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm165.4 618.2l-66-.3L512 563.4l-99.3 118.4-66.1.3c-4.4 0-8-3.5-8-8 0-1.9.7-3.7 1.9-5.2l130.1-155L340.5 359a8.32 8.32 0 01-1.9-5.2c0-4.4 3.6-8 8-8l66.1.3L512 464.6l99.3-118.4 66-.3c4.4 0 8 3.5 8 8 0 1.9-.7 3.7-1.9 5.2L553.5 514l130 155c1.2 1.5 1.9 3.3 1.9 5.2 0 4.4-3.6 8-8 8z"
/>
</svg>
</span>
</span>
</div> </div>
<input <input
class="ant-input ant-input-compact-item ant-input-compact-last-item" class="ant-input ant-input-compact-item ant-input-compact-last-item"
@ -411,7 +437,7 @@ exports[`renders ./components/space/demo/compact.tsx correctly 1`] = `
class="ant-space-compact ant-space-compact-block" class="ant-space-compact ant-space-compact-block"
> >
<div <div
class="ant-select ant-select-compact-item ant-select-compact-first-item ant-select-multiple ant-select-show-search" class="ant-select ant-select-compact-item ant-select-compact-first-item ant-select-multiple ant-select-allow-clear ant-select-show-search"
style="width:50%" style="width:50%"
> >
<div <div
@ -493,6 +519,32 @@ exports[`renders ./components/space/demo/compact.tsx correctly 1`] = `
</div> </div>
</div> </div>
</div> </div>
<span
aria-hidden="true"
class="ant-select-clear"
style="user-select:none;-webkit-user-select:none"
unselectable="on"
>
<span
aria-label="close-circle"
class="anticon anticon-close-circle"
role="img"
>
<svg
aria-hidden="true"
data-icon="close-circle"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm165.4 618.2l-66-.3L512 563.4l-99.3 118.4-66.1.3c-4.4 0-8-3.5-8-8 0-1.9.7-3.7 1.9-5.2l130.1-155L340.5 359a8.32 8.32 0 01-1.9-5.2c0-4.4 3.6-8 8-8l66.1.3L512 464.6l99.3-118.4 66-.3c4.4 0 8 3.5 8 8 0 1.9-.7 3.7-1.9 5.2L553.5 514l130 155c1.2 1.5 1.9 3.3 1.9 5.2 0 4.4-3.6 8-8 8z"
/>
</svg>
</span>
</span>
</div> </div>
<input <input
class="ant-input ant-input-compact-item ant-input-compact-last-item" class="ant-input ant-input-compact-item ant-input-compact-last-item"

View File

@ -45,7 +45,7 @@ const App: React.FC = () => (
</Space.Compact> </Space.Compact>
<br /> <br />
<Space.Compact block> <Space.Compact block>
<Select defaultValue="Zhejiang"> <Select defaultValue="Zhejiang" allowClear>
<Option value="Zhejiang">Zhejiang</Option> <Option value="Zhejiang">Zhejiang</Option>
<Option value="Jiangsu">Jiangsu</Option> <Option value="Jiangsu">Jiangsu</Option>
</Select> </Select>
@ -53,7 +53,7 @@ const App: React.FC = () => (
</Space.Compact> </Space.Compact>
<br /> <br />
<Space.Compact block> <Space.Compact block>
<Select mode="multiple" defaultValue="Zhejianggggg" style={{ width: '50%' }}> <Select allowClear mode="multiple" defaultValue="Zhejianggggg" style={{ width: '50%' }}>
<Option value="Zhejianggggg">Zhejianggggg</Option> <Option value="Zhejianggggg">Zhejianggggg</Option>
<Option value="Jiangsu">Jiangsu</Option> <Option value="Jiangsu">Jiangsu</Option>
</Select> </Select>

View File

@ -1,6 +1,7 @@
/* eslint-disable import/prefer-default-export */ /* eslint-disable import/prefer-default-export */
import type { CSSObject } from '@ant-design/cssinjs'; import type { CSSInterpolation, CSSObject } from '@ant-design/cssinjs';
import type { DerivativeToken } from '../theme/internal'; import type { DerivativeToken, FullToken } from '../theme/internal';
import type { OverrideComponent } from '../theme/util/genComponentStyleHook';
function compactItemVerticalBorder(token: DerivativeToken): CSSObject { function compactItemVerticalBorder(token: DerivativeToken): CSSObject {
return { return {
@ -43,11 +44,13 @@ function compactItemBorderVerticalRadius(prefixCls: string): CSSObject {
}; };
} }
export function genCompactItemVerticalStyle(token: DerivativeToken, prefixCls: string): CSSObject { export function genCompactItemVerticalStyle<T extends OverrideComponent>(
token: FullToken<T>,
): CSSInterpolation {
return { return {
'&-compact-vertical': { [`${token.componentCls}-compact-vertical`]: {
...compactItemVerticalBorder(token), ...compactItemVerticalBorder(token),
...compactItemBorderVerticalRadius(prefixCls), ...compactItemBorderVerticalRadius(token.componentCls),
}, },
}; };
} }

View File

@ -1,6 +1,7 @@
/* eslint-disable import/prefer-default-export */ /* eslint-disable import/prefer-default-export */
import type { CSSObject } from '@ant-design/cssinjs'; import type { CSSInterpolation, CSSObject } from '@ant-design/cssinjs';
import type { DerivativeToken } from '../theme/internal'; import type { DerivativeToken, FullToken } from '../theme/internal';
import type { OverrideComponent } from '../theme/util/genComponentStyleHook';
interface CompactItemOptions { interface CompactItemOptions {
focus?: boolean; focus?: boolean;
@ -75,15 +76,14 @@ function compactItemBorderRadius(prefixCls: string, options: CompactItemOptions)
}; };
} }
export function genCompactItemStyle( export function genCompactItemStyle<T extends OverrideComponent>(
token: DerivativeToken, token: FullToken<T>,
prefixCls: string,
options: CompactItemOptions = { focus: true }, options: CompactItemOptions = { focus: true },
): CSSObject { ): CSSInterpolation {
return { return {
'&-compact': { [`${token.componentCls}-compact`]: {
...compactItemBorder(token, options), ...compactItemBorder(token, options),
...compactItemBorderRadius(prefixCls, options), ...compactItemBorderRadius(token.componentCls, options),
}, },
}; };
} }