-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not scrolling to the selected group option on menu open #3648
Comments
solved bb9c1d7 |
Same issue as #3656 |
Hey @csantos1113 I see this issue as still an open one, any idea by when this will be fixed ? I am using [email protected] and still get same error |
Really waiting for this fix |
Scrolling to the selected option is broken in v3 only (tested on 3.0.4 and 3.0.8), v2 seems to be working correctly. The patch suggested by @ankush29 fixes the problem. But there can be another type of problem I ran into. I'm posting it here in case it might help someone: The problem turned out to be that the option object passed to
|
This issue is introduced in 3.0.4 release, probably #3569 caused it. |
I am having the same issue |
Yes. I also have the same issue. I'm using objects with same reference as value but it doesn't seem to be working. When is this going to be fixed? |
any expected date for a fix for this looking back at 3.0.3 bug still seems to be present for me. |
We are on version 3.0.8 and this bug is still occurring. Would be much appreciated if this could be solved as quickly as possible since it is quite an obvious front facing issue. |
Please, any updates on this? |
Guys, any updates ? + |
Is this going to be fixed in the next release? |
I tried my self to fix issue.
in src/select.js
}` getNextFocusedOption functionality:
|
Worked for me pretty well with defining custom import React, { useCallback, useRef } from 'react'
import Select from 'react-select'
const MySelect = ({ isMulti, onMenuOpen: onMenuOpenProp, ...props }) => {
const selectRef = useRef(null)
// Feature of focusing selected option when menu is getting opened
const onMenuOpen = useCallback(() => {
// Calling an initial prop if it has been passed
onMenuOpenProp?.()
if (!isMulti) {
// Getting a selected option
const option = selectRef.current?.select?.state?.selectValue?.[0]
if (option) {
setTimeout(() => {
// Setting a focused value as a selected one
// References:
// - https://github.com/JedWatson/react-select/blob/master/packages/react-select/src/Select.js#L503
// - https://github.com/JedWatson/react-select/blob/master/packages/react-select/src/Select.js#L802
if (selectRef.current?.select) {
const selectedIndex = selectRef.current.select.state.menuOptions.focusable.indexOf(option)
if (selectedIndex >= 0) {
// Focusing selected option only if it exists
selectRef.current.select.scrollToFocusedOptionOnUpdate = true
selectRef.current.select.inputIsHiddenAfterUpdate = false
selectRef.current.select.setState({
focusedValue: null,
focusedOption: option,
})
}
}
})
}
}
}, [selectRef.current, onMenuOpenProp, isMulti])
return <Select ref={selectRef} isMulti={isMulti} onMenuOpen={onMenuOpen} {...props} />
} Hope it'll help someone as well 🙏🏻 |
Can confirm that the above work-around works in version 3.0.8. react-select/packages/react-select/src/Select.js Lines 503 to 506 in d787303
|
This issue was fixed for me in 3.1.0 |
Hello - In an effort to sustain the We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our efforts towards the current major version. If you aren't using the latest version of However, if you feel this issue is still relevant and you'd like us to review it - please leave a comment and we'll do our best to get back to you! |
@bladey I think this should be re-opened, I'm using option groups, and it's not scrolling to the selected element. Update: This seem to be caused by using custom components. |
Thanks @peterp. |
Greetings, I can replicate the issue as well with the following criteria with or without custom components. <Select
isMulti
hideSelectedOptions={false}
options={groups}
/> https://codesandbox.io/s/react-select-bug-scroll-selected-group-option-k9942?file=/src/App.js |
Adding a setTimeout to /node_modules/react-select/dist/Select-#####.browser.esm.js seems to fix it for me (4.1.0)
to:
|
Any idea if this bug will be fixed soon? @louisptremblay , have you submitted a pull request with your fix? |
PR submitted... you can use yarn patch-package in the meantime |
So I was able to solve this using onMenuOpen() call back function with timeOut() function as we do not have "MyDropdown__option--is-selected" class at the time when this function is invoked. My solution is as follows;
|
Greetings all, Merge conflicts have been resolved and version 4.3 has been released as we wanted to squeeze in at least one more release before the conversion to TypeScript. One of the changes that was added was that the focusedOption is now passed as a prop to the MenuList component so hopefully this makes it easier to find the option to be scrolled to if using a custom component. This does not resolve the core issue, but may give some ideas for work arounds for the time being. More to come, but wanted to at least give an update that there are eyes on this. |
Doesn't work at all for me on version 4.3! |
It's still not working for me, any solution? |
Not working for me on 5.0.0. Are there any code snippets for workarounds? |
Here is my the solution, what worked for me : https://stackoverflow.com/a/66710895/7844963 |
Thanks so much! I had tried mhammadsiddiqui's solution above, which is similar, but omits the |
Is a fix for this issue scheduled, it's 4 years old? |
react-select: 3.0.4
After selecting a value and then re-opening the menu, the component does not scroll the selected value into view.
This behaviour occurs for both standard options and also the new options with group headers.
Options with group header issue:
https://codesandbox.io/s/p68rh?module=/example.js
Standard options:
https://codesandbox.io/s/kwv9t?module=/example.js
similar issue reported by #3535 for custom options as well
The text was updated successfully, but these errors were encountered: