Skip to content

Commit 6a75b6c

Browse files
committed
meta pass current name
1 parent 9c245b3 commit 6a75b6c

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/Field.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ class Field extends React.Component<FieldProps, FieldState> implements FieldEnti
289289
touched: this.isFieldTouched(),
290290
validating: this.prevValidating,
291291
errors: this.errors,
292+
name: this.getNamePath(),
292293
};
293294

294295
return meta;

src/interface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ export interface Meta {
1414
touched: boolean;
1515
validating: boolean;
1616
errors: string[];
17+
name: InternalNamePath;
1718
}
1819

1920
/**
2021
* Used by `setFields` config
2122
*/
22-
export interface FieldData extends Partial<Meta> {
23+
export interface FieldData extends Partial<Omit<Meta, 'name'>> {
2324
name: NamePath;
2425
value?: StoreValue;
2526
}

tests/index.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,4 +447,31 @@ describe('Form.Basic', () => {
447447
expect(wrapper.find('.validating').length).toBeTruthy();
448448
expect(form.isFieldsTouched()).toBeFalsy();
449449
});
450+
451+
it('render props get meta', () => {
452+
let called1 = false;
453+
let called2 = false;
454+
455+
mount(
456+
<Form>
457+
<Field name="Light">
458+
{(_, meta) => {
459+
expect(meta.name).toEqual(['Light']);
460+
called1 = true;
461+
return null;
462+
}}
463+
</Field>
464+
<Field name={['Bamboo', 'Best']}>
465+
{(_, meta) => {
466+
expect(meta.name).toEqual(['Bamboo', 'Best']);
467+
called2 = true;
468+
return null;
469+
}}
470+
</Field>
471+
</Form>,
472+
);
473+
474+
expect(called1).toBeTruthy();
475+
expect(called2).toBeTruthy();
476+
});
450477
});

0 commit comments

Comments
 (0)