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

Description Property Not Shown in OneOf Dropdown Menu 🐛

Open Guilamb opened this issue 1 year ago • 3 comments

Prerequisites

What theme are you using?

core

Version

5.18.4

Current Behavior

When using the description property in a oneOf subSchema, it isn't rendered under the dropdown menu.

{
  "type": "object",
  "properties": {
    "plan": {
      "type": "string",
      "oneOf": [
        {
          "const": "vcluster",
          "title": "Virtual cluster plan",
          "description": "This is a virtual cluster plan."
        },
        {
          "const": "coab",
          "title": "Cloud-on-a-bench plan",
          "description": "This is a cloud-on-a-bench plan."
        },
        {
          "const": "kamaji",
          "title": "Kamaji plan",
          "description": "This is a Kamaji plan."
        }
      ]
    }
  }
}

image

Expected Behavior

We should see a text field under the dropdown selection menu that dynamically changes the description of the selected field, similar to how it works for objects :

{
  "type": "object",
  "oneOf": [
    {
      "title": "Small",
      "description": "Small plan",
      "type": "object"
    },
    {
      "title": "Big",
      "description": "Big plan",
      "type": "object"
    }
  ]
}

image

Steps To Reproduce

No response

Environment

- OS: Ubuntu 22
- Node: 20.11.1
- npm: 10.2.4

Anything else?

No response

Guilamb avatar Jun 10 '24 09:06 Guilamb

@Guilamb Interesting use case. After digging into the code, it seems like we need to update ALL of the SelectWidget implementations to detect whether the select enumOption has its optional schema prop provided with the optional description prop provided, then we'll need to render a DescriptionTemplate with the description in it. Not an easy bit of work, but doable. Is this something you feel interested in implementing?

heath-freenome avatar Jun 28 '24 19:06 heath-freenome

@heath-freenome Thank you for considering my issue. Unfortunately, I don't have the necessary skills and time to contribute to the development of this feature 😞 . However, I hope that my issue can be helpful to someone else who may be interested in implementing it.

Also maybe there is a workaround, can you think of a way to display description associated to constrained one-of-like value in a string type ?

Guilamb avatar Jul 08 '24 12:07 Guilamb

@Guilamb You could create a custom field for dealing with one-ofs. If you need more information about how to do that see the following documentation:

  • https://rjsf-team.github.io/react-jsonschema-form/docs/advanced-customization/custom-widgets-fields/#custom-field-components
  • https://rjsf-team.github.io/react-jsonschema-form/docs/advanced-customization/custom-widgets-fields/#customizing-the-default-fields-and-widgets

heath-freenome avatar Jul 09 '24 20:07 heath-freenome