diff --git a/CHANGELOG.md b/CHANGELOG.md index c4ddfb47fd..5417256288 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/utils/src/enumOptionsValueForIndex.ts b/packages/utils/src/enumOptionsValueForIndex.ts index 1bfdf69ba8..5c02e2ddfa 100644 --- a/packages/utils/src/enumOptionsValueForIndex.ts +++ b/packages/utils/src/enumOptionsValueForIndex.ts @@ -17,7 +17,12 @@ export default function enumOptionsValueForIndex['value'] ): EnumOptionsType['value'] | EnumOptionsType['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); diff --git a/packages/utils/test/enumOptionsValueForIndex.test.ts b/packages/utils/test/enumOptionsValueForIndex.test.ts index cadb3e16f2..0c56cf26d9 100644 --- a/packages/utils/test/enumOptionsValueForIndex.test.ts +++ b/packages/utils/test/enumOptionsValueForIndex.test.ts @@ -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'; @@ -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); + }); });