Skip to content

Option to not append to the body #189

Closed

Description

@jpnelson

Would a PR be accepted for behaviour which didn't move an element to the bottom of the body?

This would be a feature request.

To elaborate on this:

We need it for compatibility with React, and particular for our usage of web components in our shadow DOM polyfill.

We've looked at https://github.com/souporserious/react-tether/blob/master/src/TetherComponent.jsx as a solution, but we are trying to write web components that have this type of API:

<x-tethered-element>
    <div>My stuff</div>
</x-tethered-element>

where <x-tethered-element> may have any content inside it.

The problem we run into is that we want to move the <div> on the inside that a consumer gives us, and put render it inside our shadow DOM / shadow DOM polyfill.

Tether attempts to move this to the end of the body, for CSS reasons. I understand that that's important in most use cases, but we'd be willing to accept the additional burden of positioning the element in the correct place in the DOM. For that reason, we'd like an option.

@nadiam84 has made a PR for it below. We'd love to use and support the main line of tether without forking, so please have a look if you have a minute. Thanks a lot!

-Josh

Activity

  1. adevnadia commented on Jul 11, 2016

    @adevnadia

    I created a pull-request with possible solution: #192

    @TrevorBurnham @geekjuice Could you maybe have a look at this? We really need this feature, to make Tether work well with web components.

  2. TrevorBurnham commented on Jul 14, 2016

    @TrevorBurnham
    Contributor

    I'm not sure about this. I suspect that if you enabled this doNotMoveInDOM flag in #192, you would break several of Tether's positioning assumptions, which would require us to add more special-casing to the already complex core code. Is there no other possible solution here?

  3. adevnadia commented on Jul 14, 2016

    @adevnadia

    It doesn't interfere with the existing positioning assumptions. Without this flag, everything is staying as it was before.
    I checked the behavior with the simple positioning (where in normal situation there would be position: absolute), with the positioning inside a parent with the position: relative (in normal situation it would be moved to the bottom of the body). Also it works inside scrollable parent.

    Could you maybe tell me where I can get a list of all this 'positioning assumptions'? I'm happy to check all possible situations, I don't want to break anything either.

  4. FezVrasta commented on Aug 8, 2016

    @FezVrasta

    Honestly I doubt that your PR will be enough to properly position the tooltips in all the edge cases, with my library there are a lot of lines to make sure that everything works in such conditions, Tether assumes that the tooltip is always on body so their computations are much less flexible. More work is needed.

  5. pzuraq commented on Aug 26, 2016

    @pzuraq

    I had this problem a while back when trying to integrate Tether.js with Ember, specifically with regards to animations. Tether.js currently makes the assumption that all of its calculations must be relative to the body, so warping it up to the body makes sense.

    However, with Ember and React and other JS frameworks, there are times when we will have elements which are known to be the exact same size and position of the document (e.g. because they are attached to the root without any styles, or because they are an animation container which purposefully has the same sizing as the body). So, maybe the best option would be to remove the logic introduced in my earlier PR (#98) and introduce an option to specify what the "body" element should be for this tether. That way the element that it is warped to can be in the control of the user.

    It would be the user's responsibility to determine that the element in question does have the exact same constraints as the body, and any element positioned in it would line up as if it were positioned relative to the body. This would just give users the ability to manage which element that is, exactly.

  6. pzuraq commented on Aug 29, 2016

    @pzuraq

    I made #204 to implement my suggestion, comments welcome!

  7. jrmyio commented on Sep 29, 2016

    @jrmyio

    You might want to add a way to support a string as the bodyElement.

      let bodyElement = this.options.bodyElement;
      if (typeof bodyElement == "string") bodyElement = document.querySelector(bodyElement);
      bodyElement.appendChild(this.element);
    
  8. pzuraq commented on Sep 30, 2016

    @pzuraq

    Good idea! If this PR gets sanctioned I'll do that

  9. RobbieTheWagner commented on Sep 18, 2019

    @RobbieTheWagner
    Member

    I believe this is possible using the bodyElement option. We do probably need to document it, but we'll have to look through all the code and ensure we update docs soon anyway.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions