question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scroll Position Getting Reset On Hover with DropButton

See original GitHub issue

https://user-images.githubusercontent.com/60210530/190706941-6ddc8eaf-36d6-4d0f-bc66-f5e95815e67f.mov

When we want specific styles on a row in drop content, we monitor it using useState. When we update the background color for a row based on hover, the component re-renders (as bg color changes) & the scroll position gets reset.

Attached a recording where I reproduced the issue.

We could apply styles via pseudo class :hover but as per our UX requirement we have complex states to maintain which can only be handled using useState & its related hooks. eg., const chooseBackground = () => { if (item.selected && !newOptionSelected && !item.disabled) { return internalColors.lightSlate; } if (selected === index && hover) { return internalColors.solitude; } if (activeIndex === index || (item.active && activeIndex === -1)) { return internalColors.lightSlate; } return 'none'; };

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jcfilbencommented, Nov 9, 2022

Above the place function there is a comment that makes me think that place should only be called onMount and when the window is resized. If you add a console.log within place you can see that with DropButton it is getting called more frequently. If we can ensure that the function is really only called onMount and onResize then I think that will solve our problem. Another potential route is calling place(true) only when using Drop within a DropButton. However the first option seems to better align with the original intent of the code and may be a better solution.

1reaction
Isaac-alencarcommented, Nov 2, 2022

Yup, I was just finishing a issue on FileInput haha, now I’ll grab to this one!

Read more comments on GitHub >

github_iconTop Results From Across the Web

In Safari, hovering over SVG elements causes a scrolled ...
In Safari, hovering over SVG elements causes a scrolled element to reset its scroll position? Ask Question. Asked 3 years, 9 months ago....
Read more >
.hover() | TestController | Test API | API | Docs - TestCafe
Use this action to invoke popup elements such as hint windows, popup menus or dropdown lists that appear when hovering over other elements....
Read more >
Dropdown - Ant Design
By hovering or clicking on the trigger, a dropdown menu will appear, ... but you can reset it to the scrolling area and...
Read more >
Scrolling a CSS-driven dropdown menu and overflow:hidden?
The main #menubar > li will scroll and hide when scrolled to the left of #menubar's border, but the dropdown menus .aMenu remain...
Read more >
Element.scrollLeft - Web APIs | MDN
... then scrollLeft is 0 when the scrollbar is at its rightmost position ... and then increasingly negative as you scroll towards the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found