vazco / uniforms

A React library for building forms from any schema.
https://uniforms.tools
MIT License
1.94k stars 239 forks source link

Add readonly class to SelectField #1148

Open niklasdahlheimer opened 2 years ago

niklasdahlheimer commented 2 years ago

I need to add custom text styling to readonly fields. For TextFields this works flawlessly with a selector like

.ui.input input[readonly]{
   color: darkgrey;
}

because the readonly attribute is forwarded directly to the <input>element. However, for SelectFields the inner HTML element is <select>. You probably did not forward it here because, according to the specification <select> elements do not accept the readonly attribute.

To respect the specification but still have an anchor for readonly select fields and support css selecting, it would be great if you could add a conditional readonly class to the outer div, similar to the disabled class, here: https://github.com/vazco/uniforms/blob/f19cdcb67a09bb20c8e3618d5211d01eeaf95bf9/packages/uniforms-semantic/src/SelectField.tsx#L51

PS: I only could speak for the semantic-ui package here, maybe this affects other packages too.

radekmie commented 2 years ago

Hey @niklasdahlheimer and thanks for the suggestion! Actually, SelectField is not the only one that doesn't have that - the same goes for all sorts of checkboxes and radio inputs. I'd rather add a readonly attribute rather than a class, but I think it's enough for your use case (and this case in general).

radekmie commented 2 years ago

Update: it looks like some themes (e.g., Bootstrap) have custom styles for readonly <select>s, so it actually affects more themes. Pull requests welcome, as usual!