]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16826 Modal is closed, focus is not returned to trigger
authorMathieu Suen <mathieu.suen@sonarsource.com>
Mon, 29 Aug 2022 09:08:27 +0000 (11:08 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 30 Aug 2022 20:03:14 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/issues/components/IssuesApp.tsx
server/sonar-web/src/main/js/apps/issues/components/__tests__/__snapshots__/IssuesApp-test.tsx.snap
server/sonar-web/src/main/js/components/controls/buttons.tsx

index e1b7e1caaa5959b12e2d165d99d3864d0d769e15..ec5dce35d597915510857ee4729c0544eb577286 100644 (file)
@@ -148,10 +148,12 @@ const BRANCH_STATUS_REFRESH_INTERVAL = 1000;
 
 export class App extends React.PureComponent<Props, State> {
   mounted = false;
+  bulkButtonRef: React.RefObject<HTMLButtonElement>;
 
   constructor(props: Props) {
     super(props);
     const query = parseQuery(props.location.query);
+    this.bulkButtonRef = React.createRef();
     this.state = {
       bulkChangeModal: false,
       checked: [],
@@ -769,7 +771,11 @@ export class App extends React.PureComponent<Props, State> {
   };
 
   handleCloseBulkChange = () => {
-    this.setState({ bulkChangeModal: false });
+    this.setState({ bulkChangeModal: false }, () => {
+      if (this.bulkButtonRef.current) {
+        this.bulkButtonRef.current.focus();
+      }
+    });
   };
 
   handleBulkChangeDone = () => {
@@ -857,6 +863,7 @@ export class App extends React.PureComponent<Props, State> {
           title={translate('issues.select_all_issues')}
         />
         <Button
+          innerRef={this.bulkButtonRef}
           disabled={checked.length === 0}
           id="issues-bulk-change"
           onClick={this.handleOpenBulkChange}>
index 7bb7a10635016d5ce65536ffd9d9253b72390310..59964536c18c5296ce7b68fba65b9a5e71834bdd 100644 (file)
@@ -4,6 +4,11 @@ exports[`should check all issues, even the ones that are not visible 1`] = `
 <Button
   disabled={false}
   id="issues-bulk-change"
+  innerRef={
+    Object {
+      "current": null,
+    }
+  }
   onClick={[Function]}
 >
   issues.bulk_change_X_issues.250
@@ -14,6 +19,11 @@ exports[`should check max 500 issues 1`] = `
 <Button
   disabled={false}
   id="issues-bulk-change"
+  innerRef={
+    Object {
+      "current": null,
+    }
+  }
   onClick={[Function]}
 >
   issues.bulk_change_X_issues.500
index 67548395ccbd1862e887bf6601a641e41a38ec63..e4cae47e83aa293ce54728098931745574b8e64a 100644 (file)
@@ -36,7 +36,7 @@ type AllowedButtonAttributes = Pick<
 interface ButtonProps extends AllowedButtonAttributes {
   autoFocus?: boolean;
   children?: React.ReactNode;
-  innerRef?: (node: HTMLElement | null) => void;
+  innerRef?: React.Ref<HTMLButtonElement>;
   name?: string;
   onClick?: () => void;
   preventDefault?: boolean;