Parcourir la source

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

shijia.me il y a 2 ans
Parent
commit
15ea550495
2 fichiers modifiés avec 20 ajouts et 1 suppressions
  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-text').type('{esc}');
         cy.get('.test-ok').should('not.exist');
         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
             <Popover
                 ref={this.popoverRef}
                 ref={this.popoverRef}
                 {...attrs}
                 {...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}
                 visible={visible}
                 position={position}
                 position={position}
                 {...popProps}
                 {...popProps}