Repository navigation
Dropdown tether - #19692
Dropdown tether#19692719media wants to merge 5 commits into
Conversation
|
@719media You changed the permissions on the files to make them executable, which is nonsensical. Please revert that. |
|
After considering this over the weekend, I addressed a few of the above discussion points:
|
|
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 |
|
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 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! |
|
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. |
|
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? |
|
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. |
|
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. |
|
@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. |
|
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. |
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:
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)
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).
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".
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.
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.
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?
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: