Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presssing Esc/Enter in popups closes dialog #316

Open
samueldjack opened this issue Jul 17, 2017 · 3 comments
Open

Presssing Esc/Enter in popups closes dialog #316

samueldjack opened this issue Jul 17, 2017 · 3 comments

Comments

@samueldjack
Copy link

I'm submitting a feature request

  • Library Version:
    1.0.0-rc.1.0.3

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    8.1.2

  • NPM Version:
    5.0.6
  • JSPM OR Webpack AND Version
    webpack 3.0.0
  • Browser:
    Chrome 59

  • Language:
    TypeScript 2.2

Current behavior:
If I have a popup open in my dialog and I press Escape or Enter to close it then the dialog itself gets closed too.

Expected/desired behavior:

  • What is the expected behavior?
    Only the popup should close; the dialog itself should stay open.

I can think of two ways of achieving this:

  1. Handle the event in the popup and use Event.stopPropagation().
  2. Make the dialog respect the built in Event.defaultPrevented() (which appears to be synonymous with Event.Handled from the WPF/Windows Forms world) and call Event.preventDefault in a popup event handler.

Option 1 seems rather heavy handed as elements higher up the tree don't even get to find out that the event has happened. Option 2 requires a more cooperative approach, but wouldn't break any other code expecting to receive events.

@StrahilKazlachev
Copy link
Contributor

I feel somewhat reluctant using .preventDefault as a mechanism to signal the dialog, in particular the Renderer, that it should ignore an event. I'm more for marking such events with our own marker - Symbol.for('ux-ignore-event') or something like that.

@davismj
Copy link
Member

davismj commented Jul 20, 2017

I think you need to go with 1 here. Event.defaultPrevented() is not the same as Event.stopPropagation().

From MDN, preventDefault()

The Event interface's preventDefault() method tells the user agent that if the event goes unhandled, its default action should not be taken as it normally would be. The event continues to propagate as usual with only the exception that the event does nothing if no event listeners call stopPropagation(), which terminates propagation at once.

stopPropagation() on MDN

Prevents further propagation of the current event in the capturing and bubbling phases.

preventDefault is a complementary method that can be used to prevent the default action of the event from happening.

The key word here is "user agent," i.e. the browser. In other words, preventDefault() is a good way to tell the browser not to check a checkbox when a checkbox is clicked. stopPropagation() is a good way of handling logic in your application that says "I've already handled this function and it doesn't need to go any further." Your use case above warrants the latter.

@Alexander-Taran
Copy link
Contributor

Alexander-Taran commented May 26, 2022

@bigopon

async triageQuestion(id) =>{
 respondSameDay()
 let response = await getResponseFromOP( { timeout : fromYears(5) } )
 if(!response) {
    closeQuestion(id,randomReason())
 }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants