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 checkbox with 0 as a value was unselectable in antd #4068

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ should change the heading of the (upcoming) version to include a major version b

## @rjsf/utils

- [4024](https://github.com/rjsf-team/react-jsonschema-form/issues/4024) Added `base64` to support `encoding`
and `decoding` using the `UTF-8` charset to support the characters out of the `Latin1` range.
- [#4024](https://github.com/rjsf-team/react-jsonschema-form/issues/4024) Added `base64` to support `encoding` and `decoding` using the `UTF-8` charset to support the characters out of the `Latin1` range.
- Updated `enumOptionsValueForIndex()` to fix issue that filtered enum options with a value that was 0, fixing [#4067](https://github.com/rjsf-team/react-jsonschema-form/issues/4067)

## Dev / docs / playground

- [4024](https://github.com/rjsf-team/react-jsonschema-form/issues/4024) Updated the base64 references from (`atob`
and `btoa`) to invoke the functions from the new `base64` object in `@rjsf/utils`.
- [#4024](https://github.com/rjsf-team/react-jsonschema-form/issues/4024) Updated the base64 references from (`atob` and `btoa`) to invoke the functions from the new `base64` object in `@rjsf/utils`.
- Updated the `uiSchema.md` documentation to describe how to use the new `anyOf`/`oneOf` support

# 5.16.1
Expand Down
7 changes: 6 additions & 1 deletion packages/utils/src/enumOptionsValueForIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ export default function enumOptionsValueForIndex<S extends StrictRJSFSchema = RJ
emptyValue?: EnumOptionsType<S>['value']
): EnumOptionsType<S>['value'] | EnumOptionsType<S>['value'][] | undefined {
if (Array.isArray(valueIndex)) {
return valueIndex.map((index) => enumOptionsValueForIndex(index, allEnumOptions)).filter((val) => val);
return (
valueIndex
.map((index) => enumOptionsValueForIndex(index, allEnumOptions))
// Since the recursive call returns `emptyValue` when we get a bad option, only filter those out
.filter((val) => val !== emptyValue)
);
}
// So Number(null) and Number('') both return 0, so use emptyValue for those two values
const index = valueIndex === '' || valueIndex === null ? -1 : Number(valueIndex);
Expand Down
6 changes: 5 additions & 1 deletion packages/utils/test/enumOptionsValueForIndex.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { enumOptionsValueForIndex } from '../src';
import { ALL_OPTIONS } from './testUtils/testData';
import { ALL_OPTIONS, FALSY_OPTIONS } from './testUtils/testData';

const EMPTY_VALUE = 'empty';

Expand Down Expand Up @@ -38,4 +38,8 @@ describe('enumOptionsValueForIndex()', () => {
const expected = [ALL_OPTIONS[2].value, ALL_OPTIONS[1].value];
expect(enumOptionsValueForIndex([2, 1], ALL_OPTIONS)).toEqual(expected);
});
it('keeps falsy values in the options', () => {
const expected = [FALSY_OPTIONS[1].value];
expect(enumOptionsValueForIndex([1], FALSY_OPTIONS)).toEqual(expected);
});
});