feat(popconfirm): add disabled in popconfirm

This commit is contained in:
lhyt 2019-06-05 20:33:00 +08:00
parent e55a254589
commit 10d4a9f955
4 changed files with 19 additions and 0 deletions

View File

@ -134,4 +134,15 @@ describe('Popconfirm', () => {
);
expect(popconfirm.instance().getPopupDomNode()).toBeTruthy();
});
it('should not open in disabled', () => {
const popconfirm = mount(
<Popconfirm title="code" disabled>
<button>click me</button>
</Popconfirm>,
);
const triggerNode = popconfirm.find('button').at(0);
triggerNode.simulate('click');
expect(popconfirm.instance().getPopupDomNode()).toBeFalsy();
});
});

View File

@ -23,6 +23,7 @@ The difference with the `confirm` modal dialog is that it's more lightweight tha
| onCancel | callback of cancel | function(e) | - |
| onConfirm | callback of confirmation | function(e) | - |
| icon | customize icon of confirmation | ReactNode | &lt;Icon type="exclamation-circle" /&gt; |
| disabled | is show popconfirm when click its childrenNode | boolean | false |
Consult [Tooltip's documentation](https://ant.design/components/tooltip/#API) to find more APIs.

View File

@ -10,6 +10,7 @@ import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
export interface PopconfirmProps extends AbstractTooltipProps {
title: React.ReactNode;
disabled?: boolean;
onConfirm?: (e?: React.MouseEvent<any>) => void;
onCancel?: (e?: React.MouseEvent<any>) => void;
okText?: React.ReactNode;
@ -37,6 +38,7 @@ class Popconfirm extends React.Component<PopconfirmProps, PopconfirmState> {
trigger: 'click' as PopconfirmProps['trigger'],
okType: 'primary' as PopconfirmProps['okType'],
icon: <Icon type="exclamation-circle" theme="filled" />,
disabled: false,
};
static getDerivedStateFromProps(nextProps: PopconfirmProps) {
@ -81,6 +83,10 @@ class Popconfirm extends React.Component<PopconfirmProps, PopconfirmState> {
};
onVisibleChange = (visible: boolean) => {
const { disabled } = this.props;
if (disabled) {
return;
}
this.setVisible(visible);
};

View File

@ -24,6 +24,7 @@ title: Popconfirm
| onCancel | 点击取消的回调 | function(e) | 无 |
| onConfirm | 点击确认的回调 | function(e) | 无 |
| icon | 自定义弹出气泡 Icon 图标 | ReactNode | &lt;Icon type="exclamation-circle" /&gt; |
| disabled | 点击 Popconfirm 子元素是否弹出气泡确认框 | boolean | false |
更多属性请参考 [Tooltip](/components/tooltip/#API)。