Skip to content

how to stop the modal from refocusing its trigger button after being hidden? #16688

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

Closed
alexandrejobin opened this issue Jun 23, 2015 · 1 comment
Labels

Comments

@alexandrejobin
Copy link

I need to change the scroll position of the page when i click a button inside a modal. The problem is that on the hide of the modal, it tries to focus the button that showed the modal at the beginning. The line $this.is(':visible') && $this.trigger('focus') is responsable of this behavior. The prevent this, I tried to execute e.preventDefault() on the show event but the modal is not showing at all.

So how can i prevent this to happen?

// MODAL DATA-API
  // ==============

  $(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) {
    var $this   = $(this)
    var href    = $this.attr('href')
    var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7
    var option  = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data())

    if ($this.is('a')) e.preventDefault()

    $target.one('show.bs.modal', function (showEvent) {
      if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown
      $target.one('hidden.bs.modal', function () {
        $this.is(':visible') && $this.trigger('focus')
      })
    })
    Plugin.call($target, option, this)
  })
@cvrebert cvrebert changed the title how can i adjust the scroll position of the page but modal prevent me to do it how to stop the modal from refocusing its trigger button after being hidden? Jun 23, 2015
@cvrebert cvrebert added the js label Jun 23, 2015
@cvrebert
Copy link
Collaborator

Approximate duplicate of #16604.

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

No branches or pull requests

2 participants