From bbdd6c885b648a7c09d25efb68eac7ca301dc3e7 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Wed, 11 Oct 2017 10:30:14 +0200 Subject: SONAR-9815 Add focus to the close button of the project creation confirmation dialog --- .../apps/projectsManagement/CreateProjectForm.tsx | 32 ++++++++++++++++---- .../__snapshots__/CreateProjectForm-test.tsx.snap | 35 ++++++++++++---------- .../main/resources/org/sonar/l10n/core.properties | 1 + 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/CreateProjectForm.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/CreateProjectForm.tsx index c32b99adfcb..26c90c857b2 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/CreateProjectForm.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/CreateProjectForm.tsx @@ -20,6 +20,7 @@ import * as React from 'react'; import Modal from 'react-modal'; import { Link } from 'react-router'; +import { FormattedMessage } from 'react-intl'; import { Organization } from '../../app/types'; import UpgradeOrganizationBox from '../../components/common/UpgradeOrganizationBox'; import VisibilitySelector from '../../components/common/VisibilitySelector'; @@ -46,6 +47,7 @@ interface State { } export default class CreateProjectForm extends React.PureComponent { + closeButton: HTMLElement | null; mounted: boolean; constructor(props: Props) { @@ -64,6 +66,15 @@ export default class CreateProjectForm extends React.PureComponent this.mounted = true; } + componentDidUpdate() { + // wrap with `setImmediate` because of https://github.com/reactjs/react-modal/issues/338 + setImmediate(() => { + if (this.closeButton) { + this.closeButton.focus(); + } + }); + } + componentWillUnmount() { this.mounted = false; } @@ -134,15 +145,26 @@ export default class CreateProjectForm extends React.PureComponent
- Project - {createdProject.name} - {' '} - has been successfully created. + {createdProject.name} + ) + }} + />
diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/__snapshots__/CreateProjectForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/__snapshots__/CreateProjectForm-test.tsx.snap index 332863ffafe..7a9c5c62141 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/__snapshots__/CreateProjectForm-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/__snapshots__/CreateProjectForm-test.tsx.snap @@ -415,24 +415,29 @@ exports[`creates project 4`] = `
- Project - + name + , } } - > - name - - - has been successfully created. + />