Giter Site home page Giter Site logo

Comments (7)

gabrieljablonski avatar gabrieljablonski commented on June 3, 2024 1

That's good to know. I'm considering adding a section on our documentation covering more clearly (and with examples like this) how to use different middlewares.

Though this isn't a huge issue, since most users are completely fine with just the default behavior, so something to get to eventually.

from react-tooltip.

gabrieljablonski avatar gabrieljablonski commented on June 3, 2024

The most "natural" way to do this in V5 would be to use floating-ui's middlewares options to achieve your second suggestion.

have the tooltip ignore its place directive, e.g. if I set place="left" and it doesn't fit on the left or right, have it go to top/bottom if one of those would fit it on screen

As you've pointed out, it already does it for same-axis overflow (left switches to right if no space left, top to bottom, and so on) with the flip() middleware, but it indeed doesn't happen cross-axis (e.g. left to bottom).

This is kind of a weird situation to "fix", since different use-cases would call for different solutions (for example, your "squish" suggestion is totally valid in some cases), but since we already do the left<->right/top<->bottom flip, I don't see why not do this one as well.

See fallbackAxisSideDirection if you're interested in the details (here's also how you'd go about it using the middlewares tooltip prop), but [email protected] offers the cross-axis flip behavior by default.

from react-tooltip.

dylemma avatar dylemma commented on June 3, 2024

Thanks for your reply, this looks very helpful. I'll give this a try and report back (and close the issue) once I figure out what middleware fits my use case.

from react-tooltip.

gabrieljablonski avatar gabrieljablonski commented on June 3, 2024

We'll close the issue once #1140 gets merged. Just let us know if it works properly, or if you have other suggestions about this.

from react-tooltip.

dylemma avatar dylemma commented on June 3, 2024

Hm okay. I think I still want the "squish" behavior even with the fallbackAxisSideDirection setting, so I arrived at a hybrid that uses flip() plus size with a minimum width to accomplish a best-fit "squish", then a flip with the fallback axis to have it as a fallback when the best-fit doesn't do the trick. https://codesandbox.io/p/sandbox/react-tooltip-overflow-forked-pjz72c

middlewares={[
  offset(10),
  flip(),
  size({
    apply: ({ availableWidth, availableHeight, elements }) => {
      Object.assign(elements.floating.style, {
        maxWidth: `${Math.max(200, availableWidth - 50)}px`,
      });
    },
  }),
  shift({ padding: 5 }),
  flip({
    fallbackAxisSideDirection: "start",
  }),
]}

(I'm not sure why the -50 in the maxWidth expression was so important. At first, my goal was to set a margin away from the edge of the window, but small values like -10 or even -30 didn't seem to have an effect.)

from react-tooltip.

gabrieljablonski avatar gabrieljablonski commented on June 3, 2024

Official release [email protected] fixes this and some other stuff.

from react-tooltip.

andreimatei avatar andreimatei commented on June 3, 2024

Some of tooltips are too large to fit on a single line, so I want them wrapped (instead of clipped). @dylemma's snippet helped me, thanks!
I understand that 5.25.1 improved something in the area, but it didn't seem to help with the wrapping. Perhaps that too could be added to the default behavior?

from react-tooltip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.