react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

Option to hide dropdown for single-option oneOf / anyOf / allOf

Open CiaranMn opened this issue 2 years ago • 8 comments

Prerequisites

What theme are you using?

core

Is your feature request related to a problem? Please describe.

We have a project where users build schemas composed of other schemas. We extend and limit JSON schema using custom meta-schemas to standardize certain things.

The relevant consequence of this is that it is possible to end up with oneOf and allOf fields that contain one item, which means an unnecessary dropdown containing one item.

For our purposes, it would be great to have an option to hide the dropdown if it only contains one option.

Describe the solution you'd like

A uiSchema option which, if true, would hide the select widget in MultiSchemaField if it contained only one option.

Describe alternatives you've considered

I appreciate that this is a non-standard use case that depends on both: (a) allowing users to create schemas which are unknown ahead of time (b) using fields such as oneOf even if the schema could be represented in normal JSON schema without them

I have considered patching or forking the library, or using a custom MultiSchemaField which implemented the behavior above. I suspect the last is likely the best option absent in-built support but welcome advice. All would be messier and require ongoing investment to keep up to date, so I thought I would see if there was any appetite for this feature first.

CiaranMn avatar Feb 02 '23 09:02 CiaranMn