The Polaris Select component is missing attributes which are required to work properly within React.
Related documentation: https://polaris.shopify.com/components/selection-and-input/select
Here is the code I’m using which is generating the error:
<Select
label={''}
labelHidden={true}
options={[
{ label: 'Thank You', value: '' }
]}
/>
This is rendered at a specific point where I want “thank you” to be the only option but do not want the input field to actually be disabled, and it works as expected. However, it throws the following console error when rendering in the browser:
Warning: You provided a
valueprop to a form field without anonChangehandler. This will render a read-only field. If the field should be mutable usedefaultValue. Otherwise, set eitheronChangeorreadOnly.
As you can see in the code, I am not providing a value prop on the component. I am only providing the single option which needs to be there for my requirements. The correct remedy for this according to React is to add a defaultValue or readOnly attribute, but the Polaris Select component does not support either of these attributes. The only way to clear this error is to add an onChange attribute that does nothing (ie: onChange={() => {}}) which is not ideal.
The Polaris Select component should support the defaultValue and/or readOnly attributes as React specifies so that we do not have to add empty onChange callbacks.