Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #208 from alexwhin/master
Fix #198 pressing enter key on modal
- Loading branch information
Fix #198 pressing enter key on modal
78434a6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can revert, if @kylefox doesn't like this approach. But I like this approach. It has no ill side effects and the naming is also good.
anchor
is correct when usinga
tags, but also works for every other tag that fires up a jquery modal. Seems pretty good to me 👍78434a6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a problem with this approach: not all modal are opened via an
<a>
tag, i.e. when manually opening a modal. In this case,this.anchor
isundefined
and an error is thrown:TypeError: Cannot read property 'blur' of undefined
Have a look at the second example in Example 4 — you'll see this error logged to the console.
To complicate things further (😂) I don't think we can fix by simply wrapping
this.anchor.blur();
in a conditional, like this:because we're back to square one — hitting enter re-triggers the open event (albeit for manually-opened modals only).
I think we may need a solution that is independent of links/clicking and instead prevents a modal from being re-opened if that modal is already open. But I'm not entirely sure how to do that, would need to think about it more.
Either that, or we simply use the wrapped approach above, and require users to solve the problem for manually-opened modals themselves. However, I do think it should just work out of the box.
Any ideas?
78434a6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, snap!
I reverted the master branch back to the last working commit which is 706cb74.
I also added a
workaround-keypress-enter
branch, which is now 2 commits behind the current branch (because I reverted the master branch). Once we got the new (temporary) branch working, and 6 eyes didn't catch any ill side effects, we merge it back to master (if @kylefox signs it off). I will try to fix it this evening or tomorrow morning (GMT +0200).