Skip to content

Commit 1d24ee2

Browse files
- Responded to reviewer feedback
1 parent d4457b2 commit 1d24ee2

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/core/src/components/fields/LayoutGridField.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ function getNonNullishValue<T = unknown>(value?: T, fallback?: T): T | undefined
134134

135135
/** Detects if a `str` is made up entirely of numeric characters
136136
*
137-
* @param str - The string to check to see if it as number
137+
* @param str - The string to check to see if it is a numeric index
138138
* @return - True if the string consists entirely of numeric characters
139139
*/
140-
function isNumeric(str: string) {
141-
return /^-?\d+(\.\d+)?$/.test(str); // Matches integers or decimals, positive or negative
140+
function isNumericIndex(str: string) {
141+
return /^\d+?$/.test(str); // Matches positive integers
142142
}
143143

144144
/** The `LayoutGridField` will render a schema, uiSchema and formData combination out into a GridTemplate in the shape
@@ -531,7 +531,7 @@ export default class LayoutGridField<
531531
idSchema: IdSchema<T>;
532532
} {
533533
let rawSchema: S | undefined;
534-
if (isNumeric(potentialIndex) && schema && schema?.type === 'array' && has(schema, ITEMS_KEY)) {
534+
if (isNumericIndex(potentialIndex) && schema && schema?.type === 'array' && has(schema, ITEMS_KEY)) {
535535
const index = Number(potentialIndex);
536536
const items = schema[ITEMS_KEY];
537537
if (Array.isArray(items)) {

packages/core/test/LayoutGridField.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ describe('LayoutGridField', () => {
12461246
retrieveSchemaSpy.mockRestore();
12471247
toIdSchemaSpy.mockRestore();
12481248
});
1249-
test('returns schema, isRequired: false, isReadonly: undefined, options when oneOf schema is requested', () => {
1249+
test('returns schema, isRequired: false, isReadonly: undefined, options undefined when 1d array schema is requested', () => {
12501250
const path = 'example.0';
12511251
const schema = innerArraySchema;
12521252
expect(
@@ -1267,7 +1267,7 @@ describe('LayoutGridField', () => {
12671267
expect(retrieveSchemaSpy).toHaveBeenCalledTimes(2);
12681268
expect(toIdSchemaSpy).not.toHaveBeenCalled();
12691269
});
1270-
test('returns schema, isRequired: true, isReadonly: true, options: undefined when selecting readonly field', () => {
1270+
test('returns schema, isRequired: false, isReadonly: undefined, options: undefined when 2d array schema is requested', () => {
12711271
const path = 'example.0.1';
12721272
const schema = get(innerArraySchema.items, '1');
12731273
expect(

0 commit comments

Comments
 (0)