Skip to content

feat: add support for optgroups in SelectWidget and related documentation updates#5000

Open
nlemoine wants to merge 2 commits into
rjsf-team:mainfrom
nlemoine:feat/optgroup-select-widget
Open

feat: add support for optgroups in SelectWidget and related documentation updates#5000
nlemoine wants to merge 2 commits into
rjsf-team:mainfrom
nlemoine:feat/optgroup-select-widget

Conversation

@nlemoine

@nlemoine nlemoine commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Reasons for making this change

Fixes #1813, #580 and closes #4374

Add optgroup support to RJSF.

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update to update snapshots, if needed.
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

@heath-freenome

heath-freenome commented Mar 25, 2026

Copy link
Copy Markdown
Member

@nlemoine It seems like you are trying to complete the work from #4374. This feature is currently only set up for the native select. I'm curious whether you think it could benefit the other themes? And if so, are you interested in expanding the feature for them? Honestly, I'm not even sure what other themes may have support for it.

render(<Form schema={schema} uiSchema={uiSchema} validator={validator} />, document.getElementById('app'));
```

Currently supported by the `core` and `react-bootstrap` theme packages.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Currently supported by the `core` and `react-bootstrap` theme packages.
Currently only supported by the `core` and `react-bootstrap` theme packages.

@nlemoine

nlemoine commented Mar 26, 2026

Copy link
Copy Markdown
Contributor Author

I'm curious whether you think it could benefit the other themes? And if so, are you interested in expanding the feature for them? Honestly, I'm not even sure what other themes may have support for it.

I started to look at it but it's not that straight forward. Some themes don't use native optgroup and do not really provide any fallback.

Before I dig in a bit more, is it fine if the feature isn't supported everywhere? (falling back to flat list eventually)

@nlemoine nlemoine force-pushed the feat/optgroup-select-widget branch from 00d14c3 to 1b0ded9 Compare March 26, 2026 16:49
@heath-freenome

Copy link
Copy Markdown
Member

I'm curious whether you think it could benefit the other themes? And if so, are you interested in expanding the feature for them? Honestly, I'm not even sure what other themes may have support for it.

I started to look at it but it's not that straight forward. Some themes don't use native optgroup and do not really provide any fallback.

Before I dig in a bit more, is it fine if the feature isn't supported everywhere? (falling back to flat list eventually)

Yes, I'm fine with doing more work in a follow-up PR. I'll take a second look at your PR soon to see if I missed anything.

@nlemoine

Copy link
Copy Markdown
Contributor Author

Yes, I'm fine with doing more work in a follow-up PR

You can wait until next week, I should be able to at least implement the obvious/not problematic themes.

@nlemoine

Copy link
Copy Markdown
Contributor Author

I also need to push a fix on select indices (related to the work done in #4773). That might be needed before this.

const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, multiple);
const showPlaceholderOption = !multiple && schema.default === undefined;

function renderOption(i: number): ReactNode {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks (nearly) identical to what you put into the react-bootstrap code. I would love for you to find a way to DRY up the two implementations. One approach could be to implement a component in core that is a peer to the RichDescription/RichHelp/SchemaExamples components and use it in both places. It likely would require passing props that are currently local variables. Let me know what you think is the best approach.

const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, multiple);
const showPlaceholderOption = !multiple && schema.default === undefined;

function renderOption(i: number): ReactNode {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY all of this up please

@heath-freenome

Copy link
Copy Markdown
Member

@nlemoine I'm assuming you will get back to this once you return from your break

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modify JSON Validation for Optgroup support

2 participants