Settings

Theme

Show HN: Popper.js, a 3KB library to manage tooltips and popovers

github.com

169 points by AndreaScn 10 years ago · 61 comments

Reader

23andwalnut 10 years ago

Perhaps I'm an idiot, but it wasn't immediately clear to me that the examples were actually examples. They looked like images. I only discovered that they were interactive after I got frustrated that I couldn't find the 'examples' section. Here's the page I'm referring to: http://fezvrasta.github.io/popper.js/

Anway, looks like a great project :)

  • FezVrasta 10 years ago

    Oh... Any idea to make them look more like examples?

    • timlyo 10 years ago

      Make a button that says "click me" that displays the first one. Then people know what they're looking for and have their attention drawn to it.

    • chipperyman573 10 years ago

      In my opinion the only one that wasn't immediately obviously an example was the scroll one, due to the lack of scrollbars (I thought "scroll" was referring to the page and was confused about why it wasn't moving when I scrolled the page).

      • FezVrasta 10 years ago

        Stupid mac scrollbars :P I'll do something to increase the visibility of the examples then. Thanks again!

        • developer2 10 years ago

          I wouldn't recommend the CSS route as you'd be working against a core OS feature. On OS X: System Prefs > General > Show scroll bars > "Automatically based on mouse or trackpad"; "When scrolling"; "Always".

          It's possible via something like [1], but the problem is you are hardcoding colors for a specific OS version. The example given in the link is a much darker scrollbar than is present in Yosemite.

          I'd just go the route of labeling the example more explicitly. By the way, nice job on the site. Very snazzy, and you didn't make the mistake a lot of people make which is to hijack the native scrolling.

          [1] http://stackoverflow.com/a/10100209/2609094

        • alanh 10 years ago

          I think there is CSS that can make your scrollbars actually visible

gizmo 10 years ago

This is not a 3kb library for popups, given that the main source file popper.js is 44.6kb and the minimized version is 13.5kb large. I'm assuming 3kb refers to the gzipped size, but this isn't so meaningful because parsing and loading the javascript is more significant than reading a few extra kilobytes from a socket.

That said, this looks like a very nice library.

  • FezVrasta 10 years ago

    Yes I refer to the gzipped size as usually the other libraries do. I don't think that gzipping is so heavy on system resources considering that most of the websites are gzipped nowadays

    • gizmo 10 years ago

      gzipping is cheap, but it's not a very meaningful indicator of anything. It only refers to bandwidth and only for the first site visit. Even for js-heavy sites all the minimized and gzipped javascript put together will be smaller than a single png file.

      That the library doesn't have dependencies is much more important, because then it can be loaded in parallel with other libraries. That matters a lot for performance.

      • Can_Not 10 years ago

        Labeling everything in their gzip size (without the real size) is a bad new trend in my opinion. It feels like an unfair marketing practice since older projects won't mention gzip at all. I use gzip, but I don't think of my project in gzip numbers. The biggest issue I have with it is that now if somebody explicitly does not state whether or not they are talking about real size or gzip size, is likely that both of us don't know which size is being talked about. It feels like Fahrenheit and Celsius both being used unlabeled. I still think in real size, so it's an extra conversion for me when people use gzip only.

tyingq 10 years ago

I've heard, secondhand, from disabled people that tooltips are particularly troublesome for screen readers, keyboard traversal, etc. Might be worth looking into things that would reduce the pain, like associating the tooltips with their "parent" element via <label> or aria tags, etc.

  • FezVrasta 10 years ago

    Surely must be done something for this problem. But Popper.js wants just to position your popper in the page. The rest is up to the developer.

    • tyingq 10 years ago

      Well, given that the api does this:

        var popper = new Popper(referenceElement, onBottomPopper, {
          placement: 'bottom'
        });
      
      Popper.js already knows that referenceElement is the association, so it seems reasonable to consider if it should (maybe optionally) create the <label> or aria association between the two.

      Similar for default keybindings that make sense.

imaginamundo 10 years ago

The is the CSS only option from Primer (GitHub design guideline). If you use in your project is the tiniest that i've ever seen and it's easy to customize via SASS. (the time that is default it's not good in my opinion, but you can change, it's a SASS variable.

http://primercss.io/tooltips/

rootlocus 10 years ago

  > GPU ACCELERATION

  > If supported by browser, poppers will be positioned using CSS translate3d, making your poppers even faster!
How is a transformation accelerated by the GPU? I'm pretty sure translations are done on the CPU before sending the final transformation matrix to the GPU.
yuribit 10 years ago

I wonder what the difference is with Tether

  • FezVrasta 10 years ago

    Hi! Popper.js dev here.

    There are several advantages:

    - The size is half of Tether (3.5 vs 7);

    - Popper.js doesn't need any additional CSS in your page;

    - It works even with elements not placed as direct children of body;

    - It's much much faster (compare both on mobile, you'll see Tether lagging a lot!);

    - It automatically detects the size of the tooltip arrow;

    - Inside Popper.js you already have a way to create tooltip elements automatically, with Tether you need an additional library;

    - Popper.js supports particular "flip" behaviors, you can decide that if there's not space on the left, the tooltip must move on the bottom (for example);

    - The whole code is fully documented with JSDoc!

    I hope this answers your question

    • andrewingram 10 years ago

      I've actually been looking for something that goes the other way. The main issue i've had with Tether and React is that Tether does too much. I don't want a lib that manipulates the DOM itself, I want a overlay positioning engine that I can use to position an element (much like Popper and Tether), but that leaves the positioning up to me (ie let React keep full control of the DOM). Obviously i'd need to subscribe to position updates too, for scroll and resize (and any other) events. I tried to do this using Tether as a starting point, but it was a painful experience trying to to untangle its code.

      When I talk about engines, I mean things like Zynga's Scroller (https://github.com/zynga/scroller), essentially a purely logical set of functionality that doesn't assume a particular view-level implementation.

      • FezVrasta 10 years ago

        This is exactly the direction I want to take with Popper.js!! The part that sets the style to the DOM will soon be moved to a modifier/plugin so that it can be disabled and replaced with a modifier which just exports the coordinates.

      • FezVrasta 10 years ago

        Please checkout this PR for React support https://github.com/FezVrasta/popper.js/pull/11

      • huula 10 years ago

        Totally understand your pain. Did you try https://huu.la? It never messes up with the user's page DOMs and you don't even need to write code to use it.

        • FezVrasta 10 years ago

          May you avoid spam please?

          • huula 10 years ago

            Hey man, take it easy ;)

            Huula does solve the problem the user is facing, so by any means, this is not spam at all.

            And BTW, we are targeting different segments. You want to serve developers, I want to serve non-tech person, like HRs, Operations, etc. So technically, we are not competitors!

    • mountaineer22 10 years ago

      What minimum browsers does this support? I glanced through the documentation, but did not notice it.

      Awesome work, by the way.

      • chipperyman573 10 years ago

        Tested it in browserstack, works in IE10+. IE9 is close but doesn't work when the browser is small. IE8 doesn't work at all (go figure)

      • FezVrasta 10 years ago

        I've tested it on Chrome, Firefox, Edge, Safari, Safari Mobile and Chrome Mobile (latest versions) but I suspect it works on older versions as well.

    • yuribit 10 years ago

      Awesome!

kleampa 10 years ago

If you want to segment a guide for just certain users (based on what properties you send to platform), you can try http://onboardx.com

jazoom 10 years ago

Looks great. FYI, I can see the border between the rectangle and the triangle on all the poppers. I think it'd look better if it wasn't there.

  • FezVrasta 10 years ago

    May you open an issue giving more details about this problem? Browser, OS, screen res etc? Thanks!

paradite 10 years ago

I am wondering how well does this work on svg?

Also, I couldn't find the option to choose tooltip or popover, what's the default and how do I specify tooltip/popover?

  • FezVrasta 10 years ago

    The library just positions poppers, it doesn't decide about the behavior.

    I've tested popper.js on svg and it seems to work well but I need to write some test for them.

    • paradite 10 years ago

      Ah, I see. I was wondering for a long time why the "poppers" in the examples are static.

      Maybe coding the animation requires more JavaScript and increase the code base? Seems to me that some basic animation as popover/tooltip would be nice to have.

      • FezVrasta 10 years ago

        I'm trying to keep the library as specialized as possible. Nothing prevent you/someone to write a plugin to add more behaviors tho

ciokan 10 years ago

Has anyone tested it with react? It messes with my routes for some reason.

Warning: [react-router] You cannot change <Router routes>; it will be ignored

  • FezVrasta 10 years ago

    I've not yet tested it with React but I hardly believe that it can break the react-router... If you can reproduce it on the codepen boilerplate you find in CONTRIBUTING.md and post an issue I can give it a look!

technological 10 years ago

May be i did not look at right place. There seems to be no accessibility support ? Is it something that is planned for the future release ?

TheGuyWhoCodes 10 years ago

Maybe it's just me but the text inside the tooltip looks fuzzy, rest of the text looks crisp. On chrome 49, windows 7.

dreamlayers 10 years ago

Popovers are the worst feature of the modern web. They're usually a very aggressive way of drawing attention to something I don't care about. Even when they're supposed to be a useful part of a web page interface, it's an obsolete modal dialog paradigm.

Should I block popper.js via an ad blocking filter?

  • andrewingram 10 years ago

    I'm not sure I understand your comment, perhaps we have different understanding of what a popover is?

    For me a popover is essentially a small overlay of additional contextual information, visually attached to whatever it's providing additional context for. Historically triggered by hover, but increasingly triggered by click/touch. A drop-down menu in a navigation bar is a popover.

huula 10 years ago

[Shameless Self-Promotion] For guys who don't want to write code to create smart popovers/tours in rich text, video, image, etc. I created a free online service https://huu.la .

p.s. It doesn't mess up with the DOM element you are creating for.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection