From 02b9414e0f0169c99044ad96456290766ffcd585 Mon Sep 17 00:00:00 2001
From: hmhealey <harrisonmhealey@gmail.com>
Date: Fri, 30 Oct 2015 17:26:39 -0400
Subject: Added handling of keyboard focus to UserSettingsModal and its
 children

---
 .../user_settings/user_settings_modal.jsx          | 23 +++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

(limited to 'web/react/components/user_settings/user_settings_modal.jsx')

diff --git a/web/react/components/user_settings/user_settings_modal.jsx b/web/react/components/user_settings/user_settings_modal.jsx
index 4cfc2b3d4..94b07f3a5 100644
--- a/web/react/components/user_settings/user_settings_modal.jsx
+++ b/web/react/components/user_settings/user_settings_modal.jsx
@@ -13,6 +13,7 @@ export default class UserSettingsModal extends React.Component {
         this.handleHide = this.handleHide.bind(this);
         this.handleHidden = this.handleHidden.bind(this);
         this.handleConfirm = this.handleConfirm.bind(this);
+        this.handleCancelConfirmation = this.handleCancelConfirmation.bind(this);
 
         this.updateTab = this.updateTab.bind(this);
         this.updateSection = this.updateSection.bind(this);
@@ -20,7 +21,8 @@ export default class UserSettingsModal extends React.Component {
         this.state = {
             active_tab: 'general',
             active_section: '',
-            showConfirmModal: false
+            showConfirmModal: false,
+            enforceFocus: true
         };
 
         this.requireConfirm = false;
@@ -78,7 +80,8 @@ export default class UserSettingsModal extends React.Component {
 
     handleConfirm() {
         this.setState({
-            showConfirmModal: false
+            showConfirmModal: false,
+            enforceFocus: true
         });
 
         this.requireConfirm = false;
@@ -89,9 +92,17 @@ export default class UserSettingsModal extends React.Component {
         }
     }
 
+    handleCancelConfirmation() {
+        this.setState({
+            showConfirmModal: false,
+            enforceFocus: true
+        });
+    }
+
     showConfirmModal() {
         this.setState({
-            showConfirmModal: true
+            showConfirmModal: true,
+            enforceFocus: false
         });
     }
 
@@ -136,8 +147,9 @@ export default class UserSettingsModal extends React.Component {
             <Modal
                 dialogClassName='settings-modal'
                 show={this.props.show}
-                onHide={() => this.handleHide()}
+                onHide={this.handleHide}
                 onExited={this.handleHidden}
+                enforceFocus={this.state.enforceFocus}
             >
                 <Modal.Header closeButton={true}>
                     <Modal.Title>{'Account Settings'}</Modal.Title>
@@ -158,6 +170,7 @@ export default class UserSettingsModal extends React.Component {
                                 activeSection={this.state.active_section}
                                 updateSection={this.updateSection}
                                 updateTab={this.updateTab}
+                                setEnforceFocus={(enforceFocus) => this.setState({enforceFocus})}
                                 setRequireConfirm={(requireConfirm) => this.requireConfirm = requireConfirm}
                             />
                         </div>
@@ -169,7 +182,7 @@ export default class UserSettingsModal extends React.Component {
                     confirm_button='Yes, Discard'
                     show={this.state.showConfirmModal}
                     onConfirm={this.handleConfirm}
-                    onCancel={() => this.setState({showConfirmModal: false})}
+                    onCancel={this.handleCancelConfirmation}
                 />
             </Modal>
         );
-- 
cgit v1.2.3-1-g7c22

