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.

Menu should scroll to defaultValue upon opening

See original GitHub issue

Request

When opening the menu, if the option represented by defaultValue is not visible, the menu container should scroll such that the option is in view.

Use case

When there is a dropdown contains many values (birth year, countries, states) and the pre-selected option is not near the top it takes a lot of scrolling to find. Also, the use of arrow keys is a bit wonky since they still work (e.g. up/down selects the previous/next option) but you cannot see the selection moving so it appears that the keystrokes don’t work.

Demo

This should select 2002 by default but does not: https://codesandbox.io/s/32pwzwxom (Note that if you manually select a value the menu will open to that value next time, but it does not work that way on the initial render.)

Here is a modified version, thanks to @cdoshi on Stack Overflow, which demonstrates the requested behavior (again, it should open with 2002 selected): https://codesandbox.io/s/kkw5r17ry5

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
naffiqcommented, Oct 8, 2018

For anyone who don’t want to follow a link, this is what you should do to fix this behavior:

Instead of passing new value object, pass the one from your options array:

<Select 
  options={options}
  value={options.find(({value}) => this.state.currentValue === value)}
/>

Hope this helps.

0reactions
ebonowcommented, Apr 21, 2021

Greetings @AndresHMosqueda,

I am not able to replicate the issue. Please verify that this works for you.

https://codesandbox.io/s/immutable-rgb-s945p?file=/src/App.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

Opening the menu to the default value in react-select
Once you select a value (2002 or otherwise) it works fine, but when the page first loads you have to scroll down within...
Read more >
overflow - CSS: Cascading Style Sheets - MDN Web Docs
No scrollbars are provided, and no support for allowing the user to scroll (such as by dragging or using a scroll wheel) is...
Read more >
Prevent Scroll Chaining With Overscroll Behavior
The default value is auto , which allows scroll chaining. When we have a scrolling element and we reach the boundary of it,...
Read more >
Menu - Ant Design
A versatile menu for navigation. ... Menu needs to collect its node structure, so its children should be Menu. ... Open current submenu...
Read more >
User interface options | Docs - TinyMCE
Default Value : 'link linkchecker image imagetools table spellchecker configurepermanentpen'. Note: When the TinyMCE context menu is enabled, users can still ...
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