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

Cannot focus on input element of modal form after using uib-dropdown #6364

Closed
ndrsv opened this issue Dec 13, 2016 · 22 comments
Closed

Cannot focus on input element of modal form after using uib-dropdown #6364

ndrsv opened this issue Dec 13, 2016 · 22 comments
Milestone

Comments

@ndrsv
Copy link

ndrsv commented Dec 13, 2016

Bug description:

In brief, triggering a modal form after using a uib-dropdown on the page makes it impossible to focus on the form input.

Try the following in the provided plunker:

  1. Click button (A) to activate modal form.

  2. Click on the input & it focuses

  3. Click the uib-dropdown button 'Select' (no need to select menu button (B))

  4. Click button (A) again. It is not possible to focus on the input

Link to minimally-working plunker that reproduces the issue:

https://plnkr.co/edit/Aa8zqYgrqd5o0a1yy4EU?p=preview

Version of Angular, UIBS, and Bootstrap

Angular: 1.5.8

UIBS: 2.3.1

Bootstrap: 3.3.7

Other comments

It used to work in UIBS 2.2.0.

@brik
Copy link

brik commented Dec 13, 2016

Also experiencing the same problem in UIBS 2.3.1, works in 2.2.0.

@jacobharasimo
Copy link

jacobharasimo commented Dec 13, 2016

same experience. v2.3.0 works and 2.3.1 breaks.

assume this is related #6295 by @ajpz 8a4f625

@nimamarashi
Copy link

Same here. After opening the uib-dropdown, inputs lose their focus on mouseup. Input does not to be necessarily on a modal. Any input on same page or even after routing to another page does not accept focus after opening the uib-dropdown.
Angular: 1.5.9
angular-bootstrap: 2.3.1

@580
Copy link

580 commented Dec 14, 2016

Same problem. Also happens on Getting Started Page:
https://angular-ui.github.io/bootstrap/#/dropdown

Drop down element always get focused.

@adybionka
Copy link

I had the same problem, and after spending half of my working day I found reason. Please look at the source code of dropdown https://github.com/angular-ui/bootstrap/blob/master/src/dropdown/dropdown.js and you can find focusToggleElement function which is invoked untidy when you use uib-dropdown-toggle directive on <a> tag which has href attribute. To workaround this bug just remove href attriibute from link.

This piece of code works for me:

<div uib-dropdown>
    <a uib-dropdown-toggle>Open menu</a>
    <ul uib-dropdown-menu >
        <li>...</li>
    </ul>
</div>

@jacobharasimo
Copy link

jacobharasimo commented Dec 14, 2016 via email

@adybionka
Copy link

adybionka commented Dec 14, 2016

It is the same reason: focusToggleElement. Just focusToggleElement is invoked in some circumstances but should't. I didn't analyze dropdown menu code deeply, but I found case when focusToggleElement is not invoked when as element with directive uib-dropdown-menu you use <a> tag without href attribute (what of course is invalid html). To test it replace this piece of code:

  <button type="button" class="btn btn-primary dropdown-toggle" uib-dropdown-toggle>
    <span translate>Select</span>
    <span class="caret"></span>
  </button>

by this

  <a class="btn btn-primary dropdown-toggle" uib-dropdown-toggle>
    <span translate>Select</span>
    <span class="caret"></span>
  </a>

here https://plnkr.co/edit/Aa8zqYgrqd5o0a1yy4EU?p=preview

Of course this is only workaround and bug should be fixed by authors of ui-bootstrap.

@StefanAndjelic
Copy link

@adybionka spot on! Looks like the culprit is in dropdown.js on line 108. The closeDropdown is being invoked on document.click so it focuses the toggleElement (if focusable) every time someone clicks.

@alejandroiglesias
Copy link

I confirm this issue happening on 2.3.1 and not on 2.3.0. Also as @adybionka mentioned, removing the href attribute from the a tags stops the issue from happening on 2.3.1.

@StefanAndjelic
Copy link

StefanAndjelic commented Dec 14, 2016

Removing the href attribute only works because then the element cannot be focused. The issue still persists with buttons.

@romanzoller
Copy link

This seems to be a duplicate of #6357

@adybionka
Copy link

Another workaround of this problem is just not use uib-dropdown-toggle to open dropdown menu. focusToggleElement method is only invoked when is a element with uib-dropdown-toggle directive, which is optional. Instead of this, to open dropdown menu just use is-open attribute:

    <div uib-dropdown is-open="isOpenedDropdownMenu">
        <button ng-click="toggleDropdown($event)">Open dropdown</button>
            
        <ul uib-dropdown-menu>
            <li>...</li>
        </ul>
    </div>

And in controller:

   $scope.toggleDropdown = function($event) {
        $event.preventDefault();
        $event.stopPropagation();
        $scope.isOpenedDropdownMenu = !$scope.isOpenedDropdownMenu;
    };

@adgoncal
Copy link

It looks like the root of the problem was identified by @vukers:
c824731#commitcomment-20174042

@vukers
Copy link

vukers commented Dec 14, 2016

@mattlewis92 has a pull request with the fix: #6363

@GAndriyS
Copy link

seems like #6321 related too (text input focus bug)

@codymullins
Copy link

Yeah, we are experiencing the same issue. We were developing on 2.3.0 and our deployment today went out with 2.3.1 causing widespread breakages for our drop downs.

jeff-phillips-18 added a commit to jeff-phillips-18/angular-patternfly that referenced this issue Dec 20, 2016
Downgrading a bit to avoid issue with 2.3.0:

angular-ui/bootstrap#6364
@dougludlow
Copy link
Contributor

e07f9fd appeared to resolve the issue for me.

Looking through the list of issues, these all seem like duplicates:
#6321
#6357
#6372

jeff-phillips-18 added a commit to jeff-phillips-18/angular-patternfly that referenced this issue Dec 21, 2016
Downgrading a bit to avoid issue with 2.3.0:

angular-ui/bootstrap#6364
dgutride pushed a commit to patternfly/angular-patternfly that referenced this issue Dec 21, 2016
)

* Change version of angular-bootstrap to 2.2.x

Downgrading a bit to avoid issue with 2.3.0:

angular-ui/bootstrap#6364

* Convert sort, filter, and toolbar modules directives to components

* Add restrict E to ng-docs, enforce single select on toolbar filtering.
@sashberd
Copy link

Same issue with 2.3.1 and angular 1.5.9. Reversing to 2.3.0 solve issue. Waiting for fix

@mold
Copy link

mold commented Jan 11, 2017

I still have to click input fields twice in order to get the focus to move there, once to close the dropdown and again to shift focus (regardless of whether the input is in a modal or not).

(Angular 1.5.10, UIBS 2.4.0)

@andriy-ml
Copy link

andriy-ml commented Jan 11, 2017

The same behavior as @mold described for Angular 1.5.7 and UIBS 2.3.0

Dropdown always grabs focus for itself when toggle happens.

@mcm-ham
Copy link

mcm-ham commented Jan 17, 2017

I experiencing the problem reported by @mold as well. Created bug #6410 to track this.

@axtscz
Copy link

axtscz commented Jan 18, 2017

Also experiencing this bug. Going back to 2.3.0 did not seem to help

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

Successfully merging a pull request may close this issue.