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.

[v2] with openMenuOnClick: false and openMenuOnFocus: false, menu still toggles on click

See original GitHub issue

continuing to stuggle with the upgrade, and seeing this.

We’re using react-select to show results for typeahead search, so I only ever want the menu to be showing when there are results to list. I tried setting both openMenuOnClick and openMenuOnFocus to false, but the menu continues to come up (with no results) when clicking inside of the input.

I expect the menu to never, ever show up when the user clicks in the input, or any parts of the input when these settings are set to false.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:13
  • Comments:7

github_iconTop GitHub Comments

4reactions
Korkemomscommented, Oct 23, 2018

I copied the below function from ReactSelect’s souce code and modified (1) and (2) below. Then using ref I replace the function with my modified one.

<ReactSelect ref={node => {
    if (node) {
      const select = node.select;
      select.onControlMouseDown = event => {
        const { openMenuOnClick } = select.props;
        if (!select.state.isFocused) {
          if (openMenuOnClick) {
            select.openAfterFocus = true;
          }
          select.focusInput();
        } else if (!select.props.menuIsOpen) {

          // i added this if statement  (1)
          if (openMenuOnClick) {
            select.openMenu("first");
          }
          
           // i removed this statement (2)
          //select.openMenu("first");
        } else {
          select.onMenuClose();
        }
        if (event.target.tagName !== "INPUT") {
          event.preventDefault();
        }
      };
    }
  }} />
1reaction
rscottencommented, Jan 9, 2019

@tpict

Here’s the PR using @Korkemoms’s fix: #3334

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-Select how to keep default behavior of menu open ...
i've tried to set menuIsOpen={true} after button click but it ruins the original focus blur behavior the menu is no longer closing on...
Read more >
API - React Select
A flexible and beautiful Select Input control for ReactJS with multiselect, autocomplete and ajax ... Close the select menu when the user selects...
Read more >
react-select-fixed-v2/HISTORY.md - UNPKG
The CDN for react-select-fixed-v2. ... fixed select menu being opened on click, when openMenuOnClick is false. Thanks [caleb](https://github.com/caleb) and ...
Read more >
https://raw.githubusercontent.com/Kashkovsky/react...
React-Select ## v2.2.0 / 2018-12-28 ### Bug Fixes ... issues opening the menu correctly for multiselect when `autosize={false}` * fixed; removed `event.
Read more >
https://elicejus.lt/wp-content/plugins/presto-play...
node_modules/react-select/dist/stateManager-845a3300.esm.js","webpack:///. ... options';},openMenuOnFocus:false,openMenuOnClick:true,options:[],pageSize:5 ...
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