Skip to content

Dropdown tether - #19692

Closed
719media wants to merge 5 commits into
twbs:v4-devfrom
719media:dropdown_tether
Closed

719media wants to merge 5 commits into
twbs:v4-devfrom
719media:dropdown_tether

Conversation

@719media

@719media 719media commented Apr 8, 2016

Copy link
Copy Markdown
Contributor

ok, here is my first go at it.

i have not done any documentation since it's too early, but here are the main points/areas of discussion:

  1. i got rid of $dropdown-margin-top so as to use the offset to more correctly position the dropdown (useful for when the dropdown can reposition based on viewport size)

  2. since the dropdown-menu now gets moved out of being a child of .dropdown, it faciliated the need for some minor css changes (most notably .open .dropdown-menu needed to be changed since .dropdown-menu was no longer a child of .dropdown). This means that the "open" class is actually used in two separate elements now: the .dropdown, and the .dropdown-menu. This seems a little wierd to me, but I don't know how else to do it (we could technically probably get rid of the .open on the .dropdown element, but I left it intact for now, partially because there are unit tests around it, but also because there is a css class dealing with getting rid of an outline on focus on the .dropdown if the .dropdown-toggle is an tag).

  3. instead of just using "position" and a map, like the toolip.js does, i just exposed the entire attachment/targetAttachment variables. I felt that more flexibility was better (centering a dropdown on the target, etc.) than creating a simplified map. Otherwise, we could create a map with the four most common: "bottom-left, bottom-right, top-left, top-right".

  4. i still left "dropdown" as available to just instantiate by use of a class (vs. having to instantiate like .tooltip with javascript). this could be changed, but i was not sure what kind of discussions have happened around that, etc.

  5. context.menu is available so that the .dropdown-menu object can always be referenced from the dropdown context, no matter where it may move in the DOM. This is necessary so that the menu can be found again after it has moved in the DOM. I think perhaps it's worth adding data-target (like the modal) so that this can be explicitly set if desired.

  6. i defaulted the constraints to have the dropdown shift into viewport always, but maybe this is not desired to be default. i think normally when the dropdown goes out of viewport horizontally, users would almost always want/expect this. however, the "dropup" behavior for when it goes out of viewport vertically may not be desired as default?

  7. i cleaned out a couple classes, but there are still some .dropup and navbar-fixed-bottom styles that can probably be removed throughout the scss

this is my first time using some of the bootstrap build tools (grunt, ruby, etc.) so my apologies if i did anything wacky.

New options:

attachment       : 'top left',
targetAttachment : 'bottom left',
offset           : '0 0',
constraints      : [
    {
        to: 'window',
        attachment: 'together',
        pin: true
    }
]

@cvrebert

cvrebert commented Apr 8, 2016

Copy link
Copy Markdown
Collaborator

@719media You changed the permissions on the files to make them executable, which is nonsensical. Please revert that.

@cvrebert cvrebert added js JavaScript or TypeScript sources and plugins feature New feature, or a change to how an existing one works v4 v4, the frozen docs on gh-pages labels Apr 8, 2016
@719media

Copy link
Copy Markdown
Contributor Author

After considering this over the weekend, I addressed a few of the above discussion points:

  1. I have the .dropdown-menu being appended back underneath the .dropdown after it is hidden. This should address the issue of having any form inputs inside the dropdown that need to be kept in place in the DOM.

  2. I removed a class affiliated with using the dropdown in a nav-menu that will no longer affect anything as the dropdown-menu is absolutely positioned when shown. I removed .dropup classes as this should now be handled by using the appropriate attachment/targetAttachment variables. From what I can tell, there are no more classes that need to be adjusted/removed as a result of this pull request.

@mdo mdo modified the milestone: v4.1 ideas Dec 21, 2016
@Johann-S

Copy link
Copy Markdown
Member

It's a good idea to use Tether for dropdown but you've conflicts so you've to rebase. But you made good work 👍

With this PR, Bootstrap will depend a lot of Tether for Dropdown, Tooltips and Popover maybe it's too much ?

Any thoughts ? @bardiharborow @mdo

@719media

719media commented Jan 13, 2017 •

Copy link
Copy Markdown
Contributor Author

One of the issues with using these repositioning libraries is that the content that is being displayed is moved in the DOM. For example, when using tether with dropdowns, the dropdown menu is appended to the body tag. This creates a problem with how the dropdown css/focus/hide functionality works because the dropdown menu is no longer in the same DOM position, and some of the selectors no longer match because of this change. Things can be further complicated because, if you are developing admin applications as I do, content in the dropdown-menu may actually contain input elements etc. that were previously part of forms and are no longer part of the forms unless you do some trickery to move the menu back after it is closed. All this moving of the dropdown-menu just seems potentially problematic and unexpected for beginner users.

Personally, I prefer the popper.js library that has been pitched here before (see issue #19673) which doesn't append things to the "body" of the document to achieve this effect necessarily. I don't want to beat a dead horse, but I feel that this library is more polished than tether, primarily for these two reasons the author mentioned in the issue noted above:

  • When you scroll, you don't notice any lag in the popper movement;
  • You can append your tooltip element on any element in the page, not just the body;

When I did this PR, it was on alpha 2. Things have changed a lot, and because of the "body append" methodology of tether, doing dropdown with it requires you to pay attention to where the menu is at in regards to the DOM, which I think leads to some unexpected behavior.

I think a swap for the superior library of popper.js could be done relatively simply for all of bootstrap. I think doing this in the v4 would be less cumbersome than trying to do it in v4.1

Just my two cents. Thanks!

@FezVrasta @Johann-S

@FezVrasta

FezVrasta commented Jan 13, 2017 •

Copy link
Copy Markdown
Contributor

thanks for the mention, I released the stable v1 version a week ago. The migration shouldn't be difficult at all since I already prepared a tooltip library based on popper that mimics the bootstrap API. It could be used as base for the tooltips, or just to understand how to integrate popper in the existing tooltip library.

popper is being used in production by several companies, some of them are pretty big (Microsoft and Atlassian), I'm sure it would work for Bootstrap as well.

@719media

719media commented Jan 13, 2017 •

Copy link
Copy Markdown
Contributor Author

I have used popper in the following example to position dropdowns in bootstrap 4 alpha 6 for what it's worth.

https://jsfiddle.net/13xr2mcd/15/

As an aside, I think that bootstrap v4.0 should at least consider using data-target (like the modals do) for selecting the dropdown-menu as an override. The fallback can be existing bootstrap v3 behavior where .dropdown-menu is just a sibling of .dropdown?

@FezVrasta

FezVrasta commented Jan 13, 2017 •

Copy link
Copy Markdown
Contributor

I'd say that since Popper.js is pretty small, you could directly include it in the bundle. You may even strip out all the modifiers you don't actually use to further reduce the footprint.

This would help with the problem of users that wonder why the tooltips aren't working when they forget Tether.

@eddywashere

Copy link
Copy Markdown

Is there something missing from tether config? I've been using tether optionally for advanced Dropdowns in reactstrap. This is an old demo http://output.jsbin.com/dimive/latest the only issue I've seen is not having the right margin when auto flipping Dropdown based on available screen size.

@719media

719media commented Jan 14, 2017 •

Copy link
Copy Markdown
Contributor Author

@eddywashere The problem with tether is that it does not give you full control over where the attachment is in the DOM. It moves the attachment around in the DOM as it sees fit to try and simplify position relative/absolute/overflow issues. You don't have control over whether it does it or not (there is no "parentElement" option). This means in the current bootstrap alpha 6 version, when using tether on a dropdown, your dropdown will not be able to handle certain mouse events as the dropdown is closed too early due to the dropdown-menu not being "underneath" the dropdown element in the DOM.

Now, you can e.preventDefault() in the hide.bs.dropdown event to stop the hiding, and manage it all yourself, but that is a lot of extra work just to make the dropdown reposition appropriately.

@alecpl

alecpl commented Apr 22, 2017

Copy link
Copy Markdown
Contributor

@719media looks like we'll be using popper.js now. See #22444. Maybe you'd like to review this PR to see if it implements your ideas.

@719media

Copy link
Copy Markdown
Contributor Author

Yes, I prefer Popper over Tether, especially as of late as it has become a superior library. I am closing this pull request as I would prefer a popper implementation anyway.

@719media 719media closed this Apr 22, 2017
@719media 719media mentioned this pull request Apr 22, 2017
12 tasks done
@mdo mdo modified the milestone: v4.1 ideas Jun 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature, or a change to how an existing one works js JavaScript or TypeScript sources and plugins v4 v4, the frozen docs on gh-pages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants