瀏覽代碼

fix: fixed Popconfirm promise callback content footer buttons not re-render bug #1489

shijia.me 2 年之前
父節點
當前提交
15ea550495
共有 2 個文件被更改,包括 20 次插入1 次删除
  1. 17 0
      cypress/integration/popconfirm.spec.js
  2. 3 1
      packages/semi-ui/popconfirm/index.tsx

+ 17 - 0
cypress/integration/popconfirm.spec.js

@@ -55,4 +55,21 @@ describe('popConfirm', () => {
         cy.get('.test-text').type('{esc}');
         cy.get('.test-ok').should('not.exist');
     });
+
+    it('onConfirm promise', () => {
+        cy.visit('http://localhost:6006/iframe.html?id=popconfirm--promise-callback&viewMode=story');
+        cy.get('.semi-button').click();
+        cy.get('.semi-button').contains('确定').click();
+        cy.get('.semi-button-loading').contains('确定');
+        cy.wait(2000);
+        cy.get('.semi-button-loading').should('not.exist');
+    });
+
+    it('onCancel promise', () => {
+        cy.visit('http://localhost:6006/iframe.html?id=popconfirm--promise-callback&viewMode=story');
+        cy.get('.semi-button').click();
+        cy.get('.semi-button').contains('取消').click();
+        cy.wait(2000);
+        cy.get('.semi-button-loading').should('not.exist');;
+    });
 });

+ 3 - 1
packages/semi-ui/popconfirm/index.tsx

@@ -272,7 +272,9 @@ export default class Popconfirm extends BaseComponent<PopconfirmProps, Popconfir
             <Popover
                 ref={this.popoverRef}
                 {...attrs}
-                content={this.renderConfirmPopCard}
+                // A arrow function needs to be passed here, otherwise the content will not be updated after the Popconfirm state is updated
+                // Popover is a PureComponent, same props will not trigger update
+                content={({ initialFocusRef }) => this.renderConfirmPopCard({ initialFocusRef })}
                 visible={visible}
                 position={position}
                 {...popProps}