everweij / react-laag

Hooks to build things like tooltips, dropdown menu's and popovers in React
https://www.react-laag.com
MIT License
907 stars 47 forks source link

auto prop not acting as expected #55

Open rijk opened 3 years ago

rijk commented 3 years ago

Take the following config:

useLayer({
  placement: 'right-center',
  possiblePlacements: [
    'right-center',
    'left-center',
    'bottom-center',
    'top-center',
  ],
  auto: false,
})

Expected result:

image

Actual result:

image

The possiblePlacements are only used when auto is set to true. This does not make sense to me, also when reading the definition of auto:

should we switch automatically to a placement that is more visible on the screen?

What I want to happen here is for useLayer to find the best position when opening the layer, but not reposition it afterwards. This way, there is no possibility to do that, because you'd always need to set auto to true.

Suggested change: make auto only control repositioning of an open layer, and initial placement always take possiblePlacements into account. If you'd not want any other positions to be selected, you just leave possiblePlacements empty right?