Skip to content

Commit

Permalink
fix: switch checkedChildren no height (#48513)
Browse files Browse the repository at this point in the history
Co-authored-by: 二货机器人 <smith3816@gmail.com>
  • Loading branch information
wanpan11 and zombieJ committed Apr 17, 2024
1 parent d524a4c commit 273104c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions components/switch/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,12 @@ describe('Switch', () => {
it('have static property for type detecting', () => {
expect(Switch.__ANT_SWITCH).toBeTruthy();
});

it('inner element have min-height', () => {
const { container, rerender } = render(<Switch unCheckedChildren="0" size="small" />);
expect(container.querySelector('.ant-switch-inner-unchecked')).toHaveStyle('min-height: 16px');

rerender(<Switch unCheckedChildren="0" />);
expect(container.querySelector('.ant-switch-inner-unchecked')).toHaveStyle('min-height: 22px');
});
});
6 changes: 6 additions & 0 deletions components/switch/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ const genSwitchSmallStyle: GenerateStyle<SwitchToken, CSSObject> = (token) => {
[`${componentCls}-inner`]: {
paddingInlineStart: innerMaxMarginSM,
paddingInlineEnd: innerMinMarginSM,

[`${switchInnerCls}-checked, ${switchInnerCls}-unchecked`]: {
minHeight: trackHeightSM,
},

[`${switchInnerCls}-checked`]: {
marginInlineStart: `calc(-100% + ${trackPaddingCalc} - ${innerMaxMarginCalc})`,
marginInlineEnd: `calc(100% - ${trackPaddingCalc} + ${innerMaxMarginCalc})`,
Expand Down Expand Up @@ -269,6 +274,7 @@ const genSwitchInnerStyle: GenerateStyle<SwitchToken, CSSObject> = (token) => {
fontSize: token.fontSizeSM,
transition: `margin-inline-start ${token.switchDuration} ease-in-out, margin-inline-end ${token.switchDuration} ease-in-out`,
pointerEvents: 'none',
minHeight: trackHeight,
},

[`${switchInnerCls}-checked`]: {
Expand Down

0 comments on commit 273104c

Please sign in to comment.