Skip to content

Documented and Typed fields.value #96

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

Merged
merged 1 commit into from
Jul 11, 2019
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ Updates a value of the specified index of the array field.

A function to add a value to the beginning of the array.

#### `fields.value: any[]`

The value of the array. Should be treated as readonly.

#### `meta.active?: boolean`

[See the 🏁 Final Form docs on `active`](https://github.com/final-form/final-form#active-boolean).
Expand Down
22 changes: 22 additions & 0 deletions src/FieldArray.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,28 @@ describe('FieldArray', () => {
expect(getByTestId('values')).toHaveTextContent('')
})

it('should provide value', () => {
const renderArray = jest.fn(() => <div />)
render(
<Form
onSubmit={onSubmitMock}
mutators={arrayMutators}
subscription={{}}
initialValues={{ foo: ['a', 'b', 'c'] }}
>
{() => (
<form>
<FieldArray name="foo">{renderArray}</FieldArray>
</form>
)}
</Form>
)
expect(renderArray).toHaveBeenCalled()
expect(renderArray).toHaveBeenCalledTimes(1)

expect(renderArray.mock.calls[0][0].fields.value).toEqual(['a', 'b', 'c'])
})

// it('should respect record-level validation', () => {
// // https://github.com/final-form/react-final-form-arrays/pull/84
// const { getByTestId, getByText } = render(
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface FieldArrayRenderProps<FieldValue, T extends HTMLElement> {
shift: () => FieldValue
swap: (indexA: number, indexB: number) => void
unshift: (value: FieldValue) => void
value: FieldValue[]
} & FieldState<FieldValue[]>
meta: Partial<{
// TODO: Make a diff of `FieldState` without all the functions
Expand Down
3 changes: 2 additions & 1 deletion src/types.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export type FieldArrayRenderProps = {
remove: (index: number) => any,
shift: () => any,
swap: (indexA: number, indexB: number) => void,
unshift: (value: any) => void
unshift: (value: any) => void,
value: any[]
},
meta: Meta
}
Expand Down