chore: Not preventEvent btn loading (#32158)

* chore: Not preventEvent btn loading

* test: Update snapshot
This commit is contained in:
二货机器人 2021-09-14 15:31:42 +08:00 committed by GitHub
parent 0e3171cc52
commit 9324e953e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 214 additions and 168 deletions

View File

@ -24,7 +24,12 @@ function isNotGrey(color: string) {
return true; return true;
} }
export default class Wave extends React.Component<{ insertExtraNode?: boolean }> { export interface WaveProps {
insertExtraNode?: boolean;
disabled?: boolean;
}
export default class Wave extends React.Component<WaveProps> {
static contextType = ConfigContext; static contextType = ConfigContext;
private instance?: { private instance?: {
@ -67,10 +72,12 @@ export default class Wave extends React.Component<{ insertExtraNode?: boolean }>
} }
onClick = (node: HTMLElement, waveColor: string) => { onClick = (node: HTMLElement, waveColor: string) => {
if (!node || isHidden(node) || node.className.indexOf('-leave') >= 0) { const { insertExtraNode, disabled } = this.props;
if (disabled || !node || isHidden(node) || node.className.indexOf('-leave') >= 0) {
return; return;
} }
const { insertExtraNode } = this.props;
this.extraNode = document.createElement('div'); this.extraNode = document.createElement('div');
const { extraNode } = this; const { extraNode } = this;
const { getPrefixCls } = this.context; const { getPrefixCls } = this.context;

View File

@ -1009,6 +1009,14 @@ Array [
exports[`renders ./components/button/demo/loading.md correctly 1`] = ` exports[`renders ./components/button/demo/loading.md correctly 1`] = `
Array [ Array [
<div
class="ant-space ant-space-horizontal ant-space-align-center"
style="width:100%"
>
<div
class="ant-space-item"
style="margin-right:8px"
>
<button <button
class="ant-btn ant-btn-primary ant-btn-loading" class="ant-btn ant-btn-primary ant-btn-loading"
type="button" type="button"
@ -1039,7 +1047,12 @@ Array [
<span> <span>
Loading Loading
</span> </span>
</button>, </button>
</div>
<div
class="ant-space-item"
style="margin-right:8px"
>
<button <button
class="ant-btn ant-btn-primary ant-btn-sm ant-btn-loading" class="ant-btn ant-btn-primary ant-btn-sm ant-btn-loading"
type="button" type="button"
@ -1070,7 +1083,11 @@ Array [
<span> <span>
Loading Loading
</span> </span>
</button>, </button>
</div>
<div
class="ant-space-item"
>
<button <button
class="ant-btn ant-btn-primary ant-btn-icon-only ant-btn-loading" class="ant-btn ant-btn-primary ant-btn-icon-only ant-btn-loading"
type="button" type="button"
@ -1098,8 +1115,17 @@ Array [
</svg> </svg>
</span> </span>
</span> </span>
</button>, </button>
<br />, </div>
</div>,
<div
class="ant-space ant-space-horizontal ant-space-align-center"
style="width:100%"
>
<div
class="ant-space-item"
style="margin-right:8px"
>
<button <button
class="ant-btn ant-btn-primary" class="ant-btn ant-btn-primary"
type="button" type="button"
@ -1107,7 +1133,12 @@ Array [
<span> <span>
Click me! Click me!
</span> </span>
</button>, </button>
</div>
<div
class="ant-space-item"
style="margin-right:8px"
>
<button <button
class="ant-btn ant-btn-primary" class="ant-btn ant-btn-primary"
type="button" type="button"
@ -1134,7 +1165,11 @@ Array [
<span> <span>
Click me! Click me!
</span> </span>
</button>, </button>
</div>
<div
class="ant-space-item"
>
<button <button
class="ant-btn ant-btn-primary ant-btn-icon-only" class="ant-btn ant-btn-primary ant-btn-icon-only"
type="button" type="button"
@ -1158,7 +1193,9 @@ Array [
/> />
</svg> </svg>
</span> </span>
</button>, </button>
</div>
</div>,
] ]
`; `;

View File

@ -294,7 +294,7 @@ const InternalButton: React.ForwardRefRenderFunction<unknown, ButtonProps> = (pr
return buttonNode; return buttonNode;
} }
return <Wave>{buttonNode}</Wave>; return <Wave disabled={!!innerLoading}>{buttonNode}</Wave>;
}; };
const Button = React.forwardRef<unknown, ButtonProps>(InternalButton) as CompoundedComponent; const Button = React.forwardRef<unknown, ButtonProps>(InternalButton) as CompoundedComponent;

View File

@ -14,7 +14,7 @@ title:
A loading indicator can be added to a button by setting the `loading` property on the `Button`. A loading indicator can be added to a button by setting the `loading` property on the `Button`.
```jsx ```jsx
import { Button } from 'antd'; import { Button, Space } from 'antd';
import { PoweroffOutlined } from '@ant-design/icons'; import { PoweroffOutlined } from '@ant-design/icons';
class App extends React.Component { class App extends React.Component {
@ -47,6 +47,7 @@ class App extends React.Component {
const { loadings } = this.state; const { loadings } = this.state;
return ( return (
<> <>
<Space style={{ width: '100%' }}>
<Button type="primary" loading> <Button type="primary" loading>
Loading Loading
</Button> </Button>
@ -54,7 +55,9 @@ class App extends React.Component {
Loading Loading
</Button> </Button>
<Button type="primary" icon={<PoweroffOutlined />} loading /> <Button type="primary" icon={<PoweroffOutlined />} loading />
<br /> </Space>
<Space style={{ width: '100%' }}>
<Button type="primary" loading={loadings[0]} onClick={() => this.enterLoading(0)}> <Button type="primary" loading={loadings[0]} onClick={() => this.enterLoading(0)}>
Click me! Click me!
</Button> </Button>
@ -72,6 +75,7 @@ class App extends React.Component {
loading={loadings[2]} loading={loadings[2]}
onClick={() => this.enterLoading(2)} onClick={() => this.enterLoading(2)}
/> />
</Space>
</> </>
); );
} }

View File

@ -151,9 +151,7 @@
&&-loading { &&-loading {
position: relative; position: relative;
&:not([disabled]) { cursor: default;
pointer-events: none;
}
&::before { &::before {
display: block; display: block;