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

Accept readOnly props

Open mping opened this issue 11 years ago • 13 comments

The component should accept readOnly props, in some cases its helpful because it prevents the keyboard in mobile devices from appearing.

mping avatar Dec 01 '15 11:12 mping

Nevermind, just use inputProps={{readOnly:true}}

mping avatar Dec 17 '15 09:12 mping

not working

lkjx77 avatar Jan 16 '19 03:01 lkjx77

this doesnt work...

johneakin avatar Feb 01 '19 14:02 johneakin

isSearchable={ false } worked!

umdech avatar Feb 14 '19 08:02 umdech

isSearchable as you can tell by it's name will only prevent user from typing/searching in the select.

I think what @mping wants is isDisabled={ true } which will make select grayed out and will prevent interaction.

sombrerox avatar Jun 28 '19 07:06 sombrerox

I achieved readonly mode with the following approach:

<Select
   isSearchable={!readOnly}
   menuIsOpen={readOnly ? false : undefined}
   ...otherProps
/>

mehrdad-shokri avatar Sep 21 '19 11:09 mehrdad-shokri

There is the isDisabled={true} option that works (prevents any clicking, and greys the input out).

lakesare avatar Sep 26 '19 21:09 lakesare

I need to specifically set readonly=true on the rendered <input/>. is there any straightforward way to do this?

the reason is that even if isSearchable=false, the mobile system keyboard opens when the user clicks on the select field.

johnmarinelli avatar Oct 29 '19 14:10 johnmarinelli

Hi, I think thats still not work good even with isSearchable=false .. if we have another Input field on the same page and click on the select list it still shows iOS footer with "Done" button and arrow to jump between inputs in Safari "iPhone". Any way to solve this? https://i.ibb.co/jLh8RHc/Screenshot-2019-11-22-at-11-14-29.png

Thanks

MohammedAlasaad avatar Nov 22 '19 10:11 MohammedAlasaad

A lot of suggestions here are using disabled. While this is visually the same, it is a problem for accessibility, as a screen reader won't read a disabled field (Will skip it) Whereas, for a readonly field, the screenreader will read the field, and will say that it is read only and can't be modified.

bhargavshah avatar Feb 13 '20 11:02 bhargavshah

My workaround was with the following props:

isClearable={!readOnly}
isSearchable={!readOnly}
openMenuOnClick={!readOnly}

Of course that doesn't help with adding a readonly attribute to the input field. For those who need it, you should probably create a thin wrapper around <Select/> with your custom props, then manually set the readonly attribute via the input element's handle.

umphy avatar Jun 09 '20 05:06 umphy

I added the following, as clicking the chevron for opening the menu also opened it: menuIsOpen={readonly ? false : undefined} As mentioned by @umphy it doesn't help with the readonly attribute...

richardpaynea55 avatar Jun 30 '20 17:06 richardpaynea55

Hi, in cas anyone still here after 2024, you can add the following to prevent removing option in case of multi-select: styles={{ multiValueRemove: () => (readOnly ? { display: 'none' } : {}) }}

abotsi avatar Mar 26 '24 20:03 abotsi