Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Escape key not closing add funds dialog #6248

Closed
wants to merge 1 commit into from
Closed

Conversation

jkup
Copy link
Contributor

@jkup jkup commented Dec 16, 2016

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).

Will fix #3800

Auditors @bbondy @bsclifton

I'm not sure that code in preferences.js was necessary because as far as I can tell there is no way to close a parent modal when a child modal is open (which is how other sites do it!).

This approach has each component store the previouslyFocused element before it mounts and then restores focus to it before it unmounts. This lets us easily return focus back to a parent modal so you can hit escape multiple times to close multiple modals.

This also has the nice added benefit of restoring keyboard only users to their previously focused item after closing a modal.

@jkup jkup added this to the 0.13.2 milestone Dec 16, 2016
@luixxiul
Copy link
Contributor

@jkup Sweet! Would you please consider to add a function to close the modal by clicking outside the modal dialog?

@jkup
Copy link
Contributor Author

jkup commented Dec 16, 2016

@luixxiul yesss! definitely.. I'll add that as soon as I can figure out why my code isn't working!

@bsclifton
Copy link
Member

bsclifton commented Dec 20, 2016

@jkup here's a patch which solves the issue (although, it's a sloppy fix):

diff --git a/js/about/preferences.js b/js/about/preferences.js
index aa3ff31..6ffb1a0 100644
--- a/js/about/preferences.js
+++ b/js/about/preferences.js
@@ -1891,12 +1891,15 @@ class AboutPreferences extends React.Component {

   setOverlayVisible (isVisible, overlayName) {
     let stateDiff = {}
-    stateDiff[`${overlayName}OverlayVisible`] = isVisible
-    if (overlayName === 'addFunds' && isVisible === false) {
+    const childVisible = this.state.bitcoinOverlayVisible || this.state.qrcodeOverlayVisible
+    if (childVisible && overlayName === 'addFunds' && isVisible === false) {
       // Hide the child overlays when the parent is closed
       stateDiff['bitcoinOverlayVisible'] = false
       stateDiff['qrcodeOverlayVisible'] = false
+    } else {
+      stateDiff[`${overlayName}OverlayVisible`] = isVisible
     }
+
     this.setState(stateDiff)
     // Tell ledger when Add Funds overlay is closed
     if (isVisible === false && overlayName === 'addFunds') {

The problem is: stateDiff[${overlayName}OverlayVisible] = isVisible was always being set to false, since it's being called with false. So the child modals and the parent are hidden.

When states need to be nested (which are most UIs), having a datastructure that you can use like a stack to record per-state information is ideal. You should be able to use an array with push/pop to record the parent/child relationships. What would you push? One quick example would be: when showing the overlay, push an onClose handler.

class AboutPreferences extends React.Component {
  constructor () {
    super()
    //..
    this.state = {
      stateStack = []

  //..

  // the call which shows the QR code
  // it passes in the handler which should fire when it's closed
  setOverlayVisible('qrcode', true, () => {
    this.setState({bitcoinOverlayVisible: false, qrcodeOverlayVisible: false})
    ipc.send(messages.ADD_FUNDS_CLOSED)
  })

  //..

  // the actual implementation for setOverlayVisible
  setOverlayVisible (isVisible, overlayName, onCloseHandler) {
    const stateStack = this.state.stateStack
    if (isVisible === false) {
      const onClose = this.stateStack.pop()
      if (onClose) onClose()
    } else {
      this.state.stateStack.push(onCloseHandler)
    }
    this.setState({stateStack: stateStack)
  }

@bsclifton
Copy link
Member

@jkup any update on this one?

@jkup
Copy link
Contributor Author

jkup commented Jan 6, 2017

sorry this one slipped... I'll work on it now!

@jkup jkup force-pushed the escape-for-modals branch 2 times, most recently from d9725f3 to a577ea2 Compare January 11, 2017 18:21
@jkup jkup changed the title [WiP] Escape key not closing add funds dialog Escape key not closing add funds dialog Jan 12, 2017
@luixxiul luixxiul modified the milestones: 0.13.1, 0.13.2 Jan 13, 2017
@mrose17 mrose17 modified the milestones: 0.13.2, 0.13.1 Jan 20, 2017
@bsclifton bsclifton changed the base branch from master to 0.13.1-branch January 23, 2017 22:41
@bsclifton bsclifton self-assigned this Jan 23, 2017
@bsclifton bsclifton self-requested a review January 23, 2017 22:41
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works as-is... but if the focus changes it breaks. I'm going to have to reject this one for now

@bsclifton bsclifton closed this Jan 23, 2017
@bsclifton bsclifton removed this from the 0.13.1 milestone Jan 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants