Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4197 in various themes by showing empty option in SelectWidget when appropriate #4200

Merged
merged 6 commits into from
Jul 8, 2024

Conversation

nickgros
Copy link
Contributor

Fix #4197 for antd, chakra-ui, fluentui-rc, material-ui, mui, semantic-ui

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run 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

@nickgros nickgros marked this pull request as draft May 24, 2024 20:03
@nickgros
Copy link
Contributor Author

nickgros commented May 28, 2024

@heath-freenome WDYT about moving this change to the optionsList util function so all themes are provided a placeholder entry when appropriate? This has a huge downstream effect on all of our tests (and maybe users selecting enums programmatically?) where the enum option index values would now be offset if a placeholder option is present. For example this would be the rendered HTML for a simple enum with ['foo', 'bar']

old

<select>
	<option value="">placeholder</option>
	<option value="0">foo</option>
	<option value="1">bar</option>
</select>

new

<select>
	<option value="0">placeholder</option>
	<option value="1">foo</option>
	<option value="2">bar</option>
</select>

CHANGELOG.md Outdated Show resolved Hide resolved
@nickgros nickgros force-pushed the fix-4197 branch 2 times, most recently from f0bf135 to c936652 Compare May 28, 2024 15:15
@heath-freenome
Copy link
Member

heath-freenome commented May 29, 2024

@heath-freenome WDYT about moving this change to the optionsList util function so all themes are provided a placeholder entry when appropriate? This has a huge downstream effect on all of our tests (and maybe users selecting enums programmatically?) where the enum option index values would now be offset if a placeholder option is present. For example this would be the rendered HTML for a simple enum with ['foo', 'bar']

old

<select>
	<option value="">placeholder</option>
	<option value="0">foo</option>
	<option value="1">bar</option>
</select>

new

<select>
	<option value="0">placeholder</option>
	<option value="1">foo</option>
	<option value="2">bar</option>
</select>

Hey Nick, That could be considered a breaking change. While it kind of make sense, it requires that we have access to placeholder in the fields (I'm not sure we do) in a way that would work properly. Maybe we can use the labelValue() function in place of the placeholder || ''? or we assign placeholder = '' in the destructure?

@Vity01
Copy link

Vity01 commented Jul 8, 2024

Any progress on this?

@nickgros
Copy link
Contributor Author

nickgros commented Jul 8, 2024

Another reason to not update the optionsList utility is because it also affects radio groups. This best to be left to the SelectWidget implementations. Future PRs may improve the theme-specific behavior by e.g. rendering 'clear' buttons instead of a blank placeholder option.

@nickgros nickgros marked this pull request as ready for review July 8, 2024 12:28
Copy link
Member

@heath-freenome heath-freenome left a comment

Choose a reason for hiding this comment

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

Just some tweaks to the CHANGELOG.md

CHANGELOG.md Outdated
@@ -18,10 +18,34 @@ should change the heading of the (upcoming) version to include a major version b

# 5.19.2
Copy link
Member

Choose a reason for hiding this comment

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

I've released 5.19.2 so you'll have to bump this

@@ -92,6 +116,7 @@ should change the heading of the (upcoming) version to include a major version b
- Fix case where NumberField would not properly reset the field when using programmatic form reset (#4202)[https://github.com/rjsf-team/react-jsonschema-form/issues/4202]
- Updated widgets to handle undefined `target` in `onFocus` and `onBlur` handlers
- Fix field disable or readonly property can't cover globalOptions corresponding property (#4212)[https://github.com/rjsf-team/react-jsonschema-form/pull/4212]
- Added support for `default` values in `additionalProperties` in [#4199](https://github.com/rjsf-team/react-jsonschema-form/issues/4199), fixing [#3195](https://github.com/rjsf-team/react-jsonschema-form/issues/3915)
Copy link
Member

Choose a reason for hiding this comment

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

Where did this come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think when I picked this up, we decided I would add this missing changelog message, assuming this would be a faster change to implement. I didn't realize it was missing until I revisited this.

CHANGELOG.md Outdated Show resolved Hide resolved
@nickgros nickgros merged commit b56da64 into rjsf-team:main Jul 8, 2024
5 checks passed
@Vity01
Copy link

Vity01 commented Jul 8, 2024

Excellent, thank you @nickgros

@mahendra790
Copy link

@nickgros Is there any way to opt out of this feature? because to remove this I need to add default: "" which makes it a valid field and required validation is not applied.

@nickgros
Copy link
Contributor Author

@mahendra790 Sorry, I'm not understanding what you expect to happen, especially because this behavior was how the core theme worked originally.

Could you set the default value in the schema to be equal to the the first option in your list of options?

nickgros added a commit that referenced this pull request Aug 18, 2024
Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com>
Co-authored-by: Abdallah Al-Soqatri <abdallah.al-soqatri@aspentech.com>
Co-authored-by: Kevin Burnett <18027+burnettk@users.noreply.github.com>
Co-authored-by: Marek Bodinger <marek.bodinger@gmail.com>
Co-authored-by: Mehdi Salem <mehdi.salem@qt.io>
Co-authored-by: Nick Grosenbacher <nickgrosenbacher@gmail.com>
Co-authored-by: Abdallah Al-Soqatri <abdallah.al-soqatri@inmation.com>
Co-authored-by: Jonasz Wiącek <jonaszwiacek@gmail.com>
Co-authored-by: Bogdan Savluk <savluk.bogdan@gmail.com>
Co-authored-by: Christian Wendt <54559756+cwendtxealth@users.noreply.github.com>
Co-authored-by: Ben Lambert <ben@blam.sh>
Co-authored-by: David R. Bild <david@davidbild.org>
Co-authored-by: Ariqun <38001928+Ariqun@users.noreply.github.com>
Co-authored-by: Shivam Anand Murmu <35562703+Rozamo@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Shubham Biswas <46351104+Shubhcoder@users.noreply.github.com>
Co-authored-by: popmanhe <neo_temp@hotmail.com>
Co-authored-by: Yuki Aoki <me@aoki.app>
Co-authored-by: Xiangcheng Kuo <37873394+orange-guo@users.noreply.github.com>
Co-authored-by: Bart van Andel <bavanandel@gmail.com>
Co-authored-by: Laurent Direr <laurent.direr@gmail.com>
Co-authored-by: Vegard Stenvik <42935080+vstenvik@users.noreply.github.com>
Co-authored-by: Appie <abdallarko@hotmail.com>
Co-authored-by: Oren Forer <oforer@gmail.com>
Co-authored-by: Marcus Penn <11893741+mpenndev@users.noreply.github.com>
Co-authored-by: joachimhagheim <47362824+joachimhagheim@users.noreply.github.com>
Co-authored-by: MarekBodingerBA <104828482+MarekBodingerBA@users.noreply.github.com>
Co-authored-by: momesana <momesana@gmail.com>
Co-authored-by: Martti Roitto <MarttiR@users.noreply.github.com>
Co-authored-by: Serge van den Oever <serge@macaw.nl>
Co-authored-by: Enzo Ferey <hello@enzoferey.com>
Co-authored-by: Skyf0l <tom.rorato@gmail.com>
Co-authored-by: Jaejoon Han <jj2726@gmail.com>
Co-authored-by: とまとみ <tomatommy.bs@gmail.com>
Co-authored-by: Daniel Todd <todddaniel@gmail.com>
Co-authored-by: Dmitry Dzhus <dima@dzhus.org>
Co-authored-by: Alexander Kachkaev <alexander@kachkaev.ru>
Co-authored-by: shaddollxz <56341682+shaddollxz@users.noreply.github.com>
Co-authored-by: Changyu Geng <gcyyq@hotmail.com>
Co-authored-by: Helen Lin <46795546+helen-m-lin@users.noreply.github.com>
Co-authored-by: solimant <solimant@users.noreply.github.com>
Co-authored-by: David Li <davidli@cs.stanford.edu>
fix(utils): direct lodash function import to improve bundling on library client side (#3976)
fix: #3961 resolve all recurse list for object properties (#3981)
fix gap in outline when label is hidden (#3984)
Fix: Expose the internal `ajv` variable in the validator implementation classes (#3991)
Fixes: #3972 indirectly by exposing the `ajv` variable for use in the issue
Fix: Change FormHelperText usage with @mui/material to render divs (#4032)
Fixes #4031 by switching the render component for `FormHelperText` to be `div`
fix: Added support for anyOf/oneOf in uiSchema (#4055)
Fixes #4039 by updating `MultiSchemaField` to properly support `anyOf`/`oneOf` arrays in the `uiSchema`
Fix checkbox with 0 as a value was unselectable in antd (#4068)
Fixed #4067 by properly dealing with enums that have 0 as a value
Fix potential XSS in the preview button of FileWidget (#4065)
Fix: Make 'ui:rows' option work with chakra-ui for textarea elements #4070 (#4078)
Fix typo in ErrorsListTemplate example (#4087)
Fix #4080 by moving `base64` encoder/decoder from `@rjsf/utils` to playground (#4093)
Fix: Error state not resetting when schema changes (#4079) (#4103)
Fix noImplicitAny error (#4106)
Fixes: [WARNING] Duplicate key "include" in object literal [duplicate-object-key] (#4114)
Fixes: Warning: validateDOMNesting(...): <p> cannot appear as a descendant of <p>. (#4117)
Fix documentation to add missing Form imports (#4131)
Fix #4127 to add missing `Form` import in documentation
Fix: filename should be bold (#4125)
Fix: use correct ConfigProvider context by using named imports (#4132)
Fix 4134 by filtering out bad DOM props (#4140)
Fixes: #4134 by updating the spreading of props onto the `TextField` to remove bad DOM fields
Fixed Programmatic submit not working properly in Firefox (#4150)
Fix Maximum call stack size exceeded in findSchemaDefinition (#4123)
fix typos in constants.ts, Form.tsx (#4185)
Fix mui imports in docs (#4218)
fix] Resetting number fields should check the entire string when deciding to leave the input text alone (#4202) (#4220)
Fixed performance issue with large schema dependencies and oneOf (#4203) (#4204)
Fixed performance issue #4203
fix(core): field ui-options higher priority (#4212)
fix(antd): disabled property of options of antd theme (#4216)
fix: omitExtraData on submit and on validateForm (#4228)
Fix IdSchema and PathSchema types (#4196)
fixes #4236
Fix #4197 in various themes by showing empty option in SelectWidget when appropriate (#4200)
fix: xss when rendering schema errors (#4256)
fix 4215 and 4260 by updating optionsList() to take a uiSchema (#4263)
Fixes #4215 and #4260 by supporting alternate titles for enums and anyOf/oneOf lists via the uiSchema
Fixed Changelog (#4269)
@XavierLeTohic
Copy link

The updated RJSF Antd theme now displays placeholders as selectable options (differing from Antd's default behavior), and without an opt-out mechanism in uiSchema, it requires a custom Select widget implementation for cases where we need the original behavior. 😕

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.

Empty item in selectbox for enum is not visible
5 participants