Skip to content
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

Added new props : autoFocusOption #3484

Closed

Conversation

CharlieBreval
Copy link

@CharlieBreval CharlieBreval commented Mar 22, 2019

Hello,

Recently, I have been facing a problem : Using React Select without preselection of the first available (focusable) option.
This option didn't exist at all. The problem has been raised in multiples issues :
#2848

Behavior with this option is simple :
1 : Click on the select : No option is focused
2 : Your user starts typing a word, no option is focused until the user do an action for that.

src/Select.js Outdated Show resolved Hide resolved
src/Select.js Outdated Show resolved Hide resolved
@CharlieBreval CharlieBreval changed the title Added new props : autoFocusFirstOption Added new props : autoFocusOption Mar 22, 2019
@danishmughal
Copy link

+1 for this, sorely needed.

@alisonhall
Copy link

Any idea when this will be merged and released?

@shepitko
Copy link

shepitko commented May 16, 2019

Any idea when this will be merged and released?

+1, useful functionality, I would like to get information about the merge and release. Thanks a lot.

@elnazabo
Copy link

elnazabo commented Jun 17, 2019

Any chances this could be merged in the near future! 🙏 Seems to be very similar to #3324

@evgenyilin
Copy link

evgenyilin commented Jul 7, 2019

+1 When?) In some cases a workaround can be to add input value to the list as the first option.

mickaobrien added a commit to ScienceCommons/curate_science that referenced this pull request Sep 6, 2019
Clicking on the search button takes the user to the search results page. I've added a new result at the top of the results list ('View all search results for *query*'), this is a workaround because the library used here (`react-select`) doesn't allow you to disable autofocussing yet - JedWatson/react-select#3484

Making clicking on the search button work required another workaround that involves storing the query when the input is blurred (due to issues discussed here - JedWatson/react-select#805). This means that clicking on the search button should work as expected but clicking outside the input and then later clicking the search button will go to the search page for the last stored query even though the input is empty. This isn't great but hopefully a rare enough case (why click on the search button for an empty search box?) that it's worth it to have it working like this for the moment.
Copy link

@Lancer-xu Lancer-xu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, really expect for this

@johannesdold
Copy link

+1 We would urgently need this option - any plans when this pr will be merged?

@rmertens
Copy link

we're also waiting for this. is there any news on this?

@alisman
Copy link

alisman commented Jan 8, 2020

While it would be great for this PR to be merged, I believe I managed to accomplish this with the following hackery:

onInputChange={(value: string) =>{ this.selectRef.select.getNextFocusedOption = ()=>null; }}

There is no longer any default selection, but arrow keying still works.

I then also bind to onKeyDown to intercept submission from input and fire submission callback with text directly from input.

@pisetski
Copy link

pisetski commented Apr 18, 2020

@alisman you have a great but incomplete solution here 🙂The problem is that it doesn't work when you open menu for the first time. Here's the complete:

const ref = React.useRef();
  
React.useEffect(() => {
  ref.current.select.getNextFocusedOption = () => null;
}, []);

const options = [
  {label: 'Option 1', value: '1'},
  {label: 'Option 2', value: '2'},
];

return (
  <ReactSelect
    ref={ref}
    options={options}
  />
);

@bladey bladey added pr/needs-review PRs that need to be reviewed to determine outcome pr/priority PRs that should be addressed sooner rather than later and removed ready-for-review labels May 26, 2020
@bladey
Copy link
Contributor

bladey commented Jun 10, 2020

PR to be reviewed, duplicate of #3010

@bladey
Copy link
Contributor

bladey commented Jun 10, 2020

Hi all,

Thanks for your contribution @CharlieBreval!

There are a number of pull requests adding this feature - I've since created an up to date PR - #4080, and closed similar pull requests.

If I've missed anything, please let me know.

Closing this PR in favor of #4080.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/needs-review PRs that need to be reviewed to determine outcome pr/priority PRs that should be addressed sooner rather than later
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet