Skip to content

Commit 625efff

Browse files
committed
fix: tooltip should work with loading switch
1 parent 2b81a72 commit 625efff

File tree

1 file changed

+46
-44
lines changed

1 file changed

+46
-44
lines changed

components/tooltip/Tooltip.tsx

+46-44
Original file line numberDiff line numberDiff line change
@@ -136,51 +136,53 @@ export default defineComponent({
136136
})
137137
);
138138
});
139-
139+
const isTrueProps = (val: boolean | '') => {
140+
return val || val === '';
141+
};
140142
const getDisabledCompatibleChildren = (ele: any) => {
141-
if (
142-
((typeof ele.type === 'object' &&
143-
(ele.type.__ANT_BUTTON === true ||
144-
ele.type.__ANT_SWITCH === true ||
145-
ele.type.__ANT_CHECKBOX === true)) ||
146-
ele.type === 'button') &&
147-
ele.props &&
148-
(ele.props.disabled || ele.props.disabled === '')
149-
) {
150-
// Pick some layout related style properties up to span
151-
// Prevent layout bugs like https://github.com/ant-design/ant-design/issues/5254
152-
const { picked, omitted } = splitObject(getStyle(ele), [
153-
'position',
154-
'left',
155-
'right',
156-
'top',
157-
'bottom',
158-
'float',
159-
'display',
160-
'zIndex',
161-
]);
162-
const spanStyle = {
163-
display: 'inline-block', // default inline-block is important
164-
...picked,
165-
cursor: 'not-allowed',
166-
width: ele.props && ele.props.block ? '100%' : null,
167-
};
168-
const buttonStyle = {
169-
...omitted,
170-
pointerEvents: 'none',
171-
};
172-
const child = cloneElement(
173-
ele,
174-
{
175-
style: buttonStyle,
176-
},
177-
true,
178-
);
179-
return (
180-
<span style={spanStyle} class={`${prefixCls}-disabled-compatible-wrapper`}>
181-
{child}
182-
</span>
183-
);
143+
const elementType = ele.type as any;
144+
if (typeof elementType === 'object' && ele.props) {
145+
if (
146+
((elementType.__ANT_BUTTON === true || elementType === 'button') &&
147+
isTrueProps(ele.props.disabled)) ||
148+
(elementType.__ANT_SWITCH === true &&
149+
(isTrueProps(ele.props.disabled) || isTrueProps(ele.props.loading)))
150+
) {
151+
// Pick some layout related style properties up to span
152+
// Prevent layout bugs like https://github.com/ant-design/ant-design/issues/5254
153+
const { picked, omitted } = splitObject(getStyle(ele), [
154+
'position',
155+
'left',
156+
'right',
157+
'top',
158+
'bottom',
159+
'float',
160+
'display',
161+
'zIndex',
162+
]);
163+
const spanStyle = {
164+
display: 'inline-block', // default inline-block is important
165+
...picked,
166+
cursor: 'not-allowed',
167+
width: ele.props && ele.props.block ? '100%' : null,
168+
};
169+
const buttonStyle = {
170+
...omitted,
171+
pointerEvents: 'none',
172+
};
173+
const child = cloneElement(
174+
ele,
175+
{
176+
style: buttonStyle,
177+
},
178+
true,
179+
);
180+
return (
181+
<span style={spanStyle} class={`${prefixCls}-disabled-compatible-wrapper`}>
182+
{child}
183+
</span>
184+
);
185+
}
184186
}
185187
return ele;
186188
};

0 commit comments

Comments
 (0)