bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

$modal does not stop tabbing on the background

Open chriswu14 opened this issue 13 years ago • 55 comments

This can be reproduced on the sample page on http://angular-ui.github.io/bootstrap/

  • in the Dialog section click 'Open Dialog' button
  • keep hitting tab key

result: tab going through background page and data can also be entered.

Hope someone can advise on this problem. Thanks.

chriswu14 avatar Jul 31 '13 12:07 chriswu14

Yeh, this is a valid point. We should fix this.

pkozlowski-opensource avatar Aug 01 '13 11:08 pkozlowski-opensource

I can see the last Bootstrap version modal dialog was setting the tabindex = -1 to prevent this. But I tried it on the markup it does not fix it.

chriswu14 avatar Aug 03 '13 14:08 chriswu14

Well this is going to be a tough one. I played with it a bit today and here's what I've found:

The tab-index trick Bootstrap is using is quite dependent on careful layout of the page (in fact, all items that can be tabbed to on a page must also have a tab-index).

The only other way to fix this is to bind to the tab keypress event, determine if the event.target is a child of modal and event.preventDefault() if it's not. Unless there's a "better way", I'm not sure how this is fixed.

hallister avatar Aug 25 '13 00:08 hallister

:+1: I would really like to see this one fixed soon! @hall5714 - i wonder if there is a way to wrap it around to the first element on the modal if the target isn't a child of the modal. having it halt on the Cancel button or whatever would be sub-optimal. How long to get this on the roadmap? Shall I have a go and submit a pull?

jmwolfe avatar Sep 09 '13 18:09 jmwolfe

They have a workaround for this problem in Bootbox (http://bootboxjs.com/#examples), which also uses Bootstrap dialogs, except they somehow managed to disable tabbing on the page behind the dialog. Can we maybe look how they got around this issue?

robvdl avatar Sep 14 '13 10:09 robvdl

I also did my own workaround for this problem, but by completely overriding the tab behaviour and taking over from the browser (manually moving focus between fields), and only when a dialog was open. I don't think this is a good solution however, and think it would be better to see how they got around this problem in Bootbox.js first.

robvdl avatar Sep 14 '13 10:09 robvdl

I think the fix is in bootstrap itself, as I don't see any tab handling code in bootbox.js.

I would fork this and work on a fix for this, but I'm having GIT difficulties. Seems I already forked master and made some changes for another defect that were submitted as a pull but weren't needed. Now when I fork master it just goes back to my old fork and it has junk that I don't want. I tried reverting changes, but I just don't know if my current source really reflects the bootstrap master. How can do a completely clean fork? Can I delete the old one? It's not jumping out at me.

jmwolfe avatar Sep 18 '13 17:09 jmwolfe

figured out how to delete my old repo and have reforked it. Will take a go at this issue.

jmwolfe avatar Sep 18 '13 20:09 jmwolfe

yup... bootstrap 3 has this to keep the focus in the modal:

  Modal.prototype.enforceFocus = function () {
    $(document)
      .off('focusin.bs.modal') // guard against infinite focus loop
      .on('focusin.bs.modal', $.proxy(function (e) {
        if (this.$element[0] !== e.target && !this.$element.has(e.target).length) {
          this.$element.focus()
        }
      }, this))
  }

unfortunately, this is using a lot of heavy jquery, like $.proxy to provide context, event namespacing, the .has() function. Let me see what I can do with @hall5714's suggestion above.

jmwolfe avatar Sep 18 '13 21:09 jmwolfe

I have a branch commit in my repo that implements a fix for this issue (https://github.com/jmwolfe/bootstrap/commit/759cddb17be504d9a04cd73a99d4a59e02666aa6). I would appreciate feedback before bothering with a pull request. This uses the same basic approach that bootstrap 3's modals use (without bootstrap of course). I do assume you want to move your focus after the last item to the first INPUT or TEXTAREA tag. We can discuss that as needed.

jmwolfe avatar Sep 22 '13 06:09 jmwolfe

@jmwolfe left some comments in https://github.com/jmwolfe/bootstrap/commit/759cddb17be504d9a04cd73a99d4a59e02666aa6

pkozlowski-opensource avatar Sep 22 '13 10:09 pkozlowski-opensource

I have incorporated Pawel's feedback in the most recent revision in my tab-fix branch, here: https://github.com/jmwolfe/bootstrap/compare/modal_bg_tab_disable. Hope we can get close and I can propose a PR.

jmwolfe avatar Sep 25 '13 20:09 jmwolfe

Hey, I was wondering if there is any eta on when this will be fixed.

kelseyishmael avatar Mar 25 '14 15:03 kelseyishmael

Hi @jmwolfe, any feedback on a PR?

etsuo avatar Apr 19 '14 23:04 etsuo

+1 on having this fixed. @jmwolfe: Have actually propsed a PR yet?

rattermeyer avatar Apr 24 '14 08:04 rattermeyer

+1 Please submit this changes by sending a Pull Request

tlierfeld avatar Apr 28 '14 09:04 tlierfeld

Its been 8 months since that fork was made, can it be assumed that the effort to get them PR'ed into the main repo is pretty much dead?

nwbvt avatar May 28 '14 20:05 nwbvt

Perhaps someone else (you) can create a PR containing those changes and credit the original contributors who weren't able to make a PR.

chrisirhc avatar Jun 09 '14 14:06 chrisirhc

Hey Guys... Sorry I have been delinquent with the PR!

I forked this a while back. I imagine this code base has changed quite a bit since September.

Suggestions on the fastest way to get a useful PR out for you guys? Should I do a new fork from some version (please specify) and re-implement the changes? What about Boostrap 3? I think I did start backing off when I heard 3.0 was coming.. I was not sure a fix based on an earlier version would be useful.

Unfortunately, I took on a more demanding role at my workplace and my time is more limited. I'll try to get a PR together in the next few weeks. If I could get a bit of summary from someone who's had time to follow all the goings on so that the PR would be acceptable, that would be a great contribution.

jmwolfe avatar Jun 10 '14 05:06 jmwolfe

@jmwolfe , no worries, I think that happens to every one of us (or most of us anyway :smile: ), I think the fastest way would be to create your fix on top the current master branch. We're unlikely to maintain older versions of UI Bootstrap due to our lack of resources. Thank you! :+1:

chrisirhc avatar Jun 13 '14 03:06 chrisirhc