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

Add add-to-body option for dropdown #1030

Closed
KrisBraun opened this issue Sep 17, 2013 · 21 comments
Closed

Add add-to-body option for dropdown #1030

KrisBraun opened this issue Sep 17, 2013 · 21 comments

Comments

@KrisBraun
Copy link

Just as tooltip (and now datepicker via #998) support an add-to-body option, it would be handy to have it for dropdown-toggle.

@caitp
Copy link
Contributor

caitp commented Sep 17, 2013

@hall5714 your'e on a closing spree today, is it worth submitting another patch for this? I can see how it's useful in cases where designs are sort of constrained, so it might solve a real UX problem for some users.

@hallister
Copy link

@caitp I'd say this is worth while. Any time we have a absolutely positioned element in a overflow: none this is going to be an issue. I wish we could do this more globally, but individual is going to have to do for now.

@caitp
Copy link
Contributor

caitp commented Sep 17, 2013

Hmm, I agree that it might be worth having, but I'm not actually seeing how the infrastructure would work. TWBS doesn't seem to offer anything like this (from a quick glance at the dropdown module), and it seems like it would require removing a child element and re-adding it to <body>. And unfortunately, to my knowledge there's no great way to do this, at least without having more directives for dropdowns.

What if we had like a <dropdown-menu> directive which, in pre-link, appended an empty container to body (if appendToBody is true), and child directives for like <dropdown-header> and <dropdown-item> or whatever, appended to the already added container? Then in dropdownMenu's post-link, it could throw away the original copy of the element (if it had one).

I dunno, it seems much more convoluted in this case. But it might enable more elegant definitions of dropdowns, and also support that use-case. And also break the existing API :D I'm not sure, throw ideas at me.


In any case, I'm not sure that this can be done in a small 3-line-patch sort of way :\

@beardedlinuxgeek
Copy link

The $modal service takes the parameters templateUrl and template. If you have a list of 30 items and they each have a dropdown menu with roughly the same stuff, it would be good if you could supply a template instead of creating redundant DOM elements.

@amcdnl
Copy link

amcdnl commented Sep 25, 2014

Issue also exists when you have the dropdown in a container that has overflow set.

@AndrewEastwood
Copy link

I'd be nice to have this

@ppollono
Copy link

ppollono commented Oct 2, 2014

Yes I'd like to have this feature!!!

@pjfsilva
Copy link

+1 Any recent updates on this?

This is a really useful feature when you combine modals and stuff with position relative (bootstrap grid)

@onemenny
Copy link

onemenny commented Dec 3, 2014

+1

@seiyria
Copy link

seiyria commented Dec 15, 2014

Gotta say, I just ran into this issue today and I'm glad we have an issue open for it. +1

@LeleDev
Copy link

LeleDev commented Dec 19, 2014

+1

After the last bootstrap update, this became really necessary when using dropdown in tables...

@sepatel
Copy link

sepatel commented Dec 22, 2014

+1

This issue is actually biting me pretty hard. Would really love for some sort of append-to-body equivalent on this.

@ghost
Copy link

ghost commented Jan 18, 2015

Would be really handy to have, has saved me a number of times with tooltips and popovers so I was expecting this for dropdowns.

@verbumfeit
Copy link

+1

Just ran into this issue and would love an append-to-body option.

@amcdnl
Copy link

amcdnl commented Feb 10, 2015

Open to PRs for this, I don't think this is in the immediate roadmap

@karianna karianna added this to the Backlog milestone Feb 10, 2015
@brafkind
Copy link

brafkind commented Mar 4, 2015

+1

@rysilva
Copy link
Contributor

rysilva commented Mar 5, 2015

I have something working locally, I'll create a PR once I give it a once-over.

@rysilva
Copy link
Contributor

rysilva commented Mar 5, 2015

@caitp To your concerns, is it against protocol do element.find('.dropdown-menu').appendTo('body');? Since we're depending on bootstrap, and this is the way to specify the dropdown menu, it should probably work although less clean. Alternatively I could specify a directive on the menu.

@sheymann
Copy link

+1

@dzwillia
Copy link

This issue plagued me for awhile as well.

The code below is a bit of a kludge, but it works. It clones the dropdown and marshals the click events back to the items in the original dropdown (in case you've been good about event delegation). Hook the following code up to shown.bs.dropdown. If you'd prefer, you can take a look at the fix on JsFiddle: http://jsfiddle.net/8rr0xsy8/

    this.onFixedDropdownShown = function(evt)
    {
        // store the dropdown menu for later use
        var $dropdown = $(this),
            $dropdown_menu = $dropdown.find('.dropdown-menu');

        var off = $dropdown_menu.offset();

        // clone this dropdown menu
        var $fixed_dropdown_menu = $dropdown_menu.clone(true);

        // hide this dropdown menu
        $dropdown_menu.addClass('invisible');

        // position the cloned dropdown menu relative to the document body and show it
        $fixed_dropdown_menu.css({
                'display': 'block',
                'position': 'fixed',
                'top': off.top+'px',
                'left': off.left+'px'
            })
            .appendTo('body');

        // pass-through click events to original dropdown menu
        var i = 0;
        $fixed_dropdown_menu.find('a').each(function() {
            var $related_anchor = $dropdown_menu.find('a').eq(i);

            $(this).on('click', function() {
                $dropdown_menu.removeClass('invisible');
                $related_anchor.click();
            });

            i++;
        });

        // remove the cloned dropdown
        $dropdown.on('hidden.bs.dropdown', function() {
            $dropdown_menu.removeClass('invisible');
            $fixed_dropdown_menu.remove();
        });
    }

Again, it works, but It's not really optimized -- if anyone cares to do so, feel free... :-)

fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this issue Jul 9, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this issue Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this issue Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this issue Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this issue Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this issue Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this issue Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this issue Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this issue Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this issue Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this issue Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this issue Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this issue Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this issue Jul 16, 2015
@amcdnl
Copy link

amcdnl commented Aug 17, 2015

Federnando's solution does not work if you scroll

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.