bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

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

Open ndrsv opened this issue 9 years ago • 22 comments

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.

ndrsv avatar Dec 13 '16 10:12 ndrsv

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

brik avatar Dec 13 '16 13:12 brik

same experience. v2.3.0 works and 2.3.1 breaks.

assume this is related https://github.com/angular-ui/bootstrap/pull/6295 by @ajpz https://github.com/angular-ui/bootstrap/commit/8a4f625

jacobharasimo avatar Dec 13 '16 14:12 jacobharasimo

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

nimamarashi avatar Dec 13 '16 20:12 nimamarashi

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

Drop down element always get focused.

580 avatar Dec 14 '16 08:12 580

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>

adybionka avatar Dec 14 '16 13:12 adybionka

Bug for me happened even when focus on a input inside modal so I think you issue is separate

On Wed, Dec 14, 2016, 8:29 AM Andrzej Dybionka [email protected] wrote:

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 focusToggleElementfunction which is invoked untidy when you use uib-dropdown-toggle directive on tag which has hrefattribute. To workaround this bug just remove href attriibute from link.

This piece of code works for me:

Open menu
  • ...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular-ui/bootstrap/issues/6364#issuecomment-267033714, or mute the thread https://github.com/notifications/unsubscribe-auth/AAh7gl_1Yirym_zoOmbDeUSEz3oEzKNBks5rH-9CgaJpZM4LLljW .

jacobharasimo avatar Dec 14 '16 13:12 jacobharasimo

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.

adybionka avatar Dec 14 '16 14:12 adybionka

@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.

StefanAndjelic avatar Dec 14 '16 14:12 StefanAndjelic

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.

alejandroiglesias avatar Dec 14 '16 14:12 alejandroiglesias

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

StefanAndjelic avatar Dec 14 '16 14:12 StefanAndjelic

This seems to be a duplicate of #6357

romanzoller avatar Dec 14 '16 15:12 romanzoller

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;
    };

adybionka avatar Dec 14 '16 15:12 adybionka

It looks like the root of the problem was identified by @vukers: https://github.com/angular-ui/bootstrap/commit/c824731ae8fed3d56bedaaf88fc8e86a4224e96d#commitcomment-20174042

adgoncal avatar Dec 14 '16 20:12 adgoncal

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

vukers avatar Dec 14 '16 20:12 vukers

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

GAndriyS avatar Dec 16 '16 08:12 GAndriyS

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.

codymullins avatar Dec 20 '16 14:12 codymullins

e07f9fd appeared to resolve the issue for me.

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

dougludlow avatar Dec 20 '16 23:12 dougludlow

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

sashberd avatar Dec 22 '16 07:12 sashberd

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)

mold avatar Jan 11 '17 16:01 mold

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.

andriy-ml avatar Jan 11 '17 19:01 andriy-ml