fix: tooltip should work with loading switch

pull/5361/head
tangjinzhou 2022-03-17 15:10:28 +08:00
parent 2b81a7213b
commit 625efff1fa
1 changed files with 46 additions and 44 deletions

View File

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