2

React select does not allow text selection of selected option. I want user to be able to select text of selected option. Whenever user tries to select the text of selected option, react select's menu gets open(pops up).

link for code sandbox: https://codesandbox.io/s/bzdhr?module=/example.js

Any help appreciated, Thanks in advance.

Yasin
  • 1,150
  • 5
  • 19
  • 39

2 Answers2

5

react-select doesn't allow us to select the text.. neither in options or the selected value for that matter..

the input component dominated the div that keeps the value.. there is no way to select that div.

however.. i managed to find a work-around for you.. this should do..

https://codesandbox.io/s/react-codesandboxer-example-5jhzf

Barun Patro
  • 860
  • 4
  • 13
1

This happens because of the react-select onMouseDown event. You can better handle it by overriding react-select custom renderers, wrap the single value renderer in a div which doesn't propagate onMouseDown events.

import React from 'react';
import Select, { Props, components, SingleValueProps } from 'react-select';


const SingleValueRenderer: React.FC<SingleValueProps<any>> = ({ children, ...props }) => (
    <div
        onMouseDown={(event) => {
            event.stopPropagation();
        }}>
        <components.SingleValue {...props}>{children}</components.SingleValue>
    </div>
);

const Dropdown: React.FC<Props> = (props) => (
    <Select
        components={{ SingleValue: SingleValueRenderer }}
        {...props}
    />
);


export default Dropdown;

shaym2
  • 87
  • 2
  • 11