Copy-paste using mouse not working
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.
any solution for the above problem ?
+1
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:
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}
/>
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%',
}),
/>
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:
- v1 to v2 upgrade guide
- v1 documentation and examples
can anyone help me on this? i am using tailwind in react js. The input seems weird
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
how to make the input field 100% width
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