PricingDocsAcademy
Bluesky ...
Fri, Dec 13, 7:51 AM

Any tips on how to get this popover to stay on the screen?

  • /attachments/1292572370241978388/1292572370535714878/mlm_habits_-_colorchange_Toddle_editor_-_Google_Chrome_2024-10-06_at_2.38.59_PM.jpeg

    Darren

    2 months ago

    I have a little pop over box where users can select another color, but if it's on the edge it goes off the screen.
    Any tips to make it more dynamic and adjust it's position if it can't show fully on the screen?
    Here's a demo: https://guides.darrenalderman.com/recordings/F10mlY8Uzz2hIPR7S0a0
    βœ…1
  • Tom Ireland

    2 months ago

    Hey, Darren. I had the same problem myself when working on text highlighting last year. In my case, I was using the Selection API to get the client bounding rect, which returns the x and y position, so used that to calculate where it should be (in a custom action), but you might be able to do something different without a custom action.

    For example, assuming the list of options in your tracker are an array, you could do a check to see if the element clicked is either the first or last one in the array and than have apply a class that shifts it left or right using translate. For example If Last item in array, class evaluates to true, translate by -50% or something like that?
  • Tom Ireland

    2 months ago

    That may not cover all scenarios, but I think you can also get the x and y co-ordinates on a click event, so you could also use that to calculate position of the popover. There's a few ways to skin that cat there I think.
    ❀️1
  • /attachments/1292572370241978388/1292857363245694986/Screen_Recording_2024-10-07_at_09.26.18.31_AM.gif

    Darren

    2 months ago

    @Tom Ireland Perfecto! Thanks for the direction.
    This list will always have 7 items and a fixed width (for now) so I was able to use that to my advantage.
    I used the list position and some logic+math to determine how much to translate and it looks great!
    Solution Walkthrough: https://guides.darrenalderman.com/recordings/4sO3pWFqL8Hxf7sBX7g3
    πŸ‘2
  • Tom Ireland

    2 months ago

    That’s awesome, Darren. πŸ’ͺ It’s all about the math! πŸ˜‚ Looks great! Thanks for taking the time to share the solution as well - it will no doubt help someone.
    πŸ’ͺ1

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code β€” but accessible to your entire team!

Try toddle β€” it's free!

Β© Copyright 2024 toddle. All rights reserved.