Skip to content

Commit

Permalink
fix: tooltip should work with loading switch
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Mar 17, 2022
1 parent 2b81a72 commit 625efff
Showing 1 changed file with 46 additions and 44 deletions.
90 changes: 46 additions & 44 deletions components/tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,51 +136,53 @@ export default defineComponent({
})
);
});

const isTrueProps = (val: boolean | '') => {
return val || val === '';
};
const getDisabledCompatibleChildren = (ele: any) => {
if (
((typeof ele.type === 'object' &&
(ele.type.__ANT_BUTTON === true ||
ele.type.__ANT_SWITCH === true ||
ele.type.__ANT_CHECKBOX === true)) ||
ele.type === 'button') &&
ele.props &&
(ele.props.disabled || ele.props.disabled === '')
) {
// Pick some layout related style properties up to span
// Prevent layout bugs like https://github.com/ant-design/ant-design/issues/5254
const { picked, omitted } = splitObject(getStyle(ele), [
'position',
'left',
'right',
'top',
'bottom',
'float',
'display',
'zIndex',
]);
const spanStyle = {
display: 'inline-block', // default inline-block is important
...picked,
cursor: 'not-allowed',
width: ele.props && ele.props.block ? '100%' : null,
};
const buttonStyle = {
...omitted,
pointerEvents: 'none',
};
const child = cloneElement(
ele,
{
style: buttonStyle,
},
true,
);
return (
<span style={spanStyle} class={`${prefixCls}-disabled-compatible-wrapper`}>
{child}
</span>
);
const elementType = ele.type as any;
if (typeof elementType === 'object' && ele.props) {
if (
((elementType.__ANT_BUTTON === true || elementType === 'button') &&
isTrueProps(ele.props.disabled)) ||
(elementType.__ANT_SWITCH === true &&
(isTrueProps(ele.props.disabled) || isTrueProps(ele.props.loading)))
) {
// Pick some layout related style properties up to span
// Prevent layout bugs like https://github.com/ant-design/ant-design/issues/5254
const { picked, omitted } = splitObject(getStyle(ele), [
'position',
'left',
'right',
'top',
'bottom',
'float',
'display',
'zIndex',
]);
const spanStyle = {
display: 'inline-block', // default inline-block is important
...picked,
cursor: 'not-allowed',
width: ele.props && ele.props.block ? '100%' : null,
};
const buttonStyle = {
...omitted,
pointerEvents: 'none',
};
const child = cloneElement(
ele,
{
style: buttonStyle,
},
true,
);
return (
<span style={spanStyle} class={`${prefixCls}-disabled-compatible-wrapper`}>
{child}
</span>
);
}
}
return ele;
};
Expand Down

0 comments on commit 625efff

Please sign in to comment.