multiselect-react-dropdown icon indicating copy to clipboard operation
multiselect-react-dropdown copied to clipboard

When clicking on the scrollbar on the dropdown selection, it automatically closes the dropdown

Open ghost opened this issue 3 years ago • 8 comments

Trim.mov.zip I am currently using dropdown and whenever I am scrolling with the mouse, it is fine. However, whenever I use the mouse to click on the dropdown scroll bar to drag it down, the dropdown automatically closes it on itself. I can't figure out what is causing the issue here. Thanks in advance. I have attached a video as well for reference.

ghost avatar Sep 09 '20 06:09 ghost

Seems it is working fine.. For reference https://drive.google.com/file/d/1ThJRGhmMFXC3UK1FDIsJKsMlGuGewTsO/view

srigar avatar Sep 30 '20 03:09 srigar

We are experiencing the same problem. Running react-multiselect-dropdown v1.6.2. The below clip is on Chrome v87.0.4280.88 but we are experiencing the same thing on Firefox.

Kapture 2020-12-15 at 19 29 52

This component is being rendered with almost all default props:

<Multiselect
  options={["beans", "cornbread", "carrots", "tomatoes", "pickles", "lasagna", "doughuts"]}
  selectedValues={["fava beans", "a nice chianti"]}
  isObject={false}
/>

nicholas-deepblocks avatar Dec 16 '20 00:12 nicholas-deepblocks

Anyone have a workaround or a way to resolve this? We just discovered this issue as well, probably would never have even realized since I only use the mouse wheel for scrollables.

rickydo avatar Dec 16 '20 16:12 rickydo

Any update on this issue please? Clicking on the scrollbar is closing the dropdown. It is happening when dropdown is used inside a modal.

jaspreetsinghchhabra avatar May 21 '21 13:05 jaspreetsinghchhabra

Does anyone fix this bug? I'm getting the same. This issue only occurs if we are using a multi-select dropdown inside a modal.

ericcart46 avatar Sep 07 '21 06:09 ericcart46

Can confirm this bug when using multi-select dropdown in dialog.

limmor1 avatar Nov 11 '21 10:11 limmor1

I'm still seeing this bug as of version 2.0.21

I believe that clicking with the mouse pointer on the scroll bar in the optionContainer creates a focus change from the searchBox input, which closes the optionContainer.

I did a really hacky workaround but would appreciate a fix in the plugin.

This was for a class component.

I basically hijack the scroll event for the option container and force it to focus on the search input unless the selected values length changes, upon which I blur the input to close the option list. I did that because I want the option container to close on selection of an item, but if you don't care about that then you don't need to do that.

Example:

// in the class constructor for my search container component
constructor(props) {

    this.multiselectRef = React.createRef();
    this.selectedLength = 0;
    this.dropdown = {};
}

// in component did mount
componentDidMount() {

    window.setTimeout(()=>{
      // I generate multiple search container components so I need to assign each one a unique id 
      // in the props if I want to be able to select a specific option container
      const { searchId = '' } = this.props;
      // save the element for later cleanup of event listener
      this.dropdown = document.querySelector(`#${searchId} .optionContainer`);
      // need this for forcing dropdown list close when selecting/removing values 
      this.selectedLength = this.multiselectRef?.current?.state?.selectedValues?.length;
      this.dropdown.addEventListener('scroll', this.TEMPHACK_handleDropdownScroll);
    }, 150);

}

// cleanup the event listener on component unmount
componentWillUnmount() {
    this.dropdown.removeEventListener("scroll", this.TEMPHACK_handleDropdownScroll);
}

// define a class method so we can cleanup the event listener in the component will unmount method
TEMPHACK_handleDropdownScroll = () => {
    /*
    Really hacky hack to prevent focus from being lost on the search input when
    the options list is manually scrolled by clicking on the scrollbar
    which causes it to close due to focus change. 
     */
    if (!this.multiselectRef?.current?.state) {
      return
    }
    
    // forcing focus might interfere with closing dropdown on selection so manually handling it
    // otherwise we could just focus the search box all the time
    if (this.selectedLength === this.multiselectRef.current.state.selectedValues.length) {
      this.multiselectRef.current.searchBox.current.focus();
    } else {
      this.selectedLength = this.multiselectRef.current.state.selectedValues.length;
      this.multiselectRef.current.searchBox.current.blur();
    }
}

sunnymui avatar Mar 03 '22 00:03 sunnymui

Seems like this bug is still not fixed

lahiru-tennakoon avatar Mar 10 '22 15:03 lahiru-tennakoon