react-select icon indicating copy to clipboard operation
react-select copied to clipboard

Copy-paste using mouse not working

Open nkt opened this issue 11 years ago • 9 comments

Try to paste something into react-select, using mouse. Many users are trying to do this, because doesn't know about cmd + v/ctrl + v. This could be fixed by increesing real input width, I guess.

nkt avatar Nov 22 '15 16:11 nkt

any solution for the above problem ?

rahulchavan30 avatar Aug 01 '16 15:08 rahulchavan30

+1

turnerniles avatar Sep 08 '17 18:09 turnerniles

I fixed it with this (using multi={true}):

CSS

.Select-multi-value-wrapper {
  .Select-placeholder {
    display: none;
  }
}
.Select-multi-value-wrapper > .Select-input > input {
  width: 100%;
}

And this on componentDidUpdate where I use the component:

componentDidUpdate() {
  const searchbar             = ReactDOM.findDOMNode(this.refs.nosoytsundere);
  const valueWrapper          = searchbar.getElementsByClassName('Select-multi-value-wrapper')[0];
  const selectInput           = searchbar.getElementsByClassName('Select-input')[0];
  const input                 = searchbar.querySelector('input[role="combobox"]');
  if(!isNull(input)){
    input.placeholder         = "You current placeholder";
    if(!isEmpty(this.state.value)){
      valueWrapper.style.width  = "auto";
      selectInput.style.width   = "auto";
      input.style.width         = "auto";
      input.placeholder         = "";
    }else{
      valueWrapper.style.width  = "100%";
      selectInput.style.width   = "100%";
      input.style.width         = "100%";
    }
  }
}

render () {
  return (
    <Select.Async
      ref='nosoytsundere'
      multi={true} {...});
}

Hope this help someone c:

blkdr avatar Sep 11 '17 17:09 blkdr

Thanks @blkdr! Here's a similar idea, only using CSS. Allows for copy-paste with an empty input when the input is selected (doesn't work with a non-empty input). The placeholder will be rendered behind the input when focused.

To right-click and copy-paste (i.e. without selecting the input first), the placeholder needs to be hidden/removed (as above).

#parent-div-id > .Select.is-focused > .Select-control > .Select-multi-value-wrapper > .Select-placeholder {
    z-index: -1;
}

#parent-div-id > .Select > .Select-control > .Select-multi-value-wrapper > .Select-input {
    width: 100%;
}

#parent-div-id > .Select > .Select-control > .Select-multi-value-wrapper > .Select-input > input {
    width: 100% !important;
}

My configuration:

<Select.Async
    autoFocus={!this.props.editable}
    autoLoad={false}
    cache={false}
    clearable
    closeOnSelect
    filterOptions={false}
    tabSelectsValue
    onBlurResetsInput={false}
    onCloseResetsInput={false}
    onSelectResetsInput={false}
    isLoading={false}
    value={this.state.myField}
    onChange={this.handleSelectChange}
    loadOptions={this.handleTypeaheadSearch}
    valueKey="myFieldKey"
    labelKey="label"
    onBlur={(e) => this.onFieldBlur(e, 'myField')}
    disabled={this.state.disabled}
/>

whns avatar Jun 11 '18 16:06 whns

did anyone get it working without using css !important? It would be great if I could add styling to input with js (I find it confusing to write styles for input when really it's for div which is container for the input)

<Creatable
    styles={{
        ...styles,
        input: () => ({
            color: theme.colors.text.default,
            width: '100%',
        }),
/>

Iulia-Soimaru avatar Dec 18 '18 22:12 Iulia-Soimaru

Version 1 of react-select is no longer supported.

In the best interest of the community we've decided to spend the time we have available on the latest version.

We apologise for any inconvenience.

Please see:

  1. v1 to v2 upgrade guide
  2. v1 documentation and examples

jossmac avatar Mar 17 '20 07:03 jossmac

can anyone help me on this? i am using tailwind in react js. The input seems weird

image the there is an empty small box on top of the placeholder, i can't right click in the input because the width is too small , anyone can help me on this? thanks in advance

alextaymx avatar Jul 13 '21 18:07 alextaymx

how to make the input field 100% width

alextaymx avatar Jul 13 '21 18:07 alextaymx

I also face this same issue with mouse copy paste. I need this in react-select/creatable. So what I did is passing following style on <creatable/>

styles={{ placeholder: (provided) => ({ ...provided, pointerEvents: "none", userSelect: "none", MozUserSelect: "none", WebkitUserSelect: "none", msUserSelect: "none" }), input: (provided) => ({ ...provided, input: { gridArea: '1 / 2 / 4 / 4 !important' } }), }}

https://stackoverflow.com/questions/59393210/how-to-copy-paste-through-mouse-in-react-select

anwin-aot avatar Jul 07 '23 07:07 anwin-aot