Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element renders off-screen for mobile #170

Open
adiakritos opened this issue Mar 1, 2017 · 4 comments
Open

Element renders off-screen for mobile #170

adiakritos opened this issue Mar 1, 2017 · 4 comments

Comments

@adiakritos
Copy link

When I use the drop as a tooltip in a form, it breaks when the screen is reduced to mobile screen width at 320px.

Please see the screenshot here:

screen shot 2017-03-01 at 11 04 17 am

Shouldn't it move to the left a little to stay within the viewport? It's currently push the page width out:

screen shot 2017-03-01 at 11 09 38 am

How do I fix this?

Here is the code:

<a class="drop-target drop-target-example-drop-theme-arrows-bounce-dark ss-help"></a>

var drop = new Drop({
   target: document.querySelector('.drop-target'),
   classes: 'drop-theme-arrows-bounce-dark',
   openOn: 'click',
   content: this.content,
   position: 'top center',
   constrainToWindow: true,
   constrainToScrollParent: false
});
@jmsfcb
Copy link

jmsfcb commented Mar 10, 2017

Bump

@josephrocca
Copy link

josephrocca commented Mar 14, 2017

It's been nearly a year since #100 and about 3 years since #16. Do you know if hubspot has abandoned this lib @geekjuice?

Edit: In the meantime, @streamside posted this in #16 - I've just tested and it seems to work great (after editing it slightly):

// Create the drop and register subscription to open event
let drop = new Drop(options);
drop.on('open', function() { positionDrop(drop); });

// Ensures drop is horizontally within viewport (vertical is already solved by drop.js).
function positionDrop(drop) {
    var rect = drop.drop.getBoundingClientRect();
    if(rect.left >= 0 && rect.right <= window.innerWidth) { return; }

    var dropWidth = drop.drop.getBoundingClientRect().width,
        left = drop.target.getBoundingClientRect().left,
        right = window.innerWidth - left,
        direction = dropWidth > right ? 'right' : 'left';

    drop.tether.attachment.left = direction;
    drop.tether.targetAttachment.left = direction;
    drop.position();
}

(Edit) Even better:

I just upgraded tether.js to 1.3.3 and drop.js to 1.4.2 and used these options:

      tetherOptions: {
        attachment: 'top center',
        targetAttachment: 'bottom center',
        constraints: [
          {
            to: 'scrollParent',
            pin:true
          }
        ]
      },

And it seems to work really nicely (previous solution was a bit hit and miss).

@ghost
Copy link

ghost commented Mar 16, 2017

@josephrocca seeing the way they're greenkeeping I'd say yes, HubSpot has abandoned this library, at least from an OSS-support perspective.

@awerlang
Copy link

@josephrocca thanks, it worked:

      tetherOptions: {
        attachment: 'top center',
        targetAttachment: 'bottom center',
        constraints: [
          {
            to: 'scrollParent',
          }
        ]
      },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants