Skip to content

Commit

Permalink
Pass min and max to number input form field
Browse files Browse the repository at this point in the history
  • Loading branch information
sashuk committed Oct 22, 2024
1 parent 89826f5 commit 1272641
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-needles-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@toptal/picasso-forms': patch
---

- pass min and max to number input in forms
2 changes: 2 additions & 0 deletions packages/picasso-forms/src/NumberInput/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export const NumberInput = (props: Props) => {

return (
<InputField<NumberInputProps>
min={min}
max={max}
{...rest}
validate={composeValidators([validateNumberLimits, validate])}
label={
Expand Down
42 changes: 42 additions & 0 deletions packages/picasso-forms/src/NumberInput/test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react'
import { render } from '@toptal/picasso-test-utils'

import { FormCompound as Form } from '../FormCompound'
import { NumberInput, type Props } from './NumberInput'

const numberInputMock = jest.fn()

jest.mock('@toptal/picasso-number-input', () => ({
...jest.requireActual('@toptal/picasso-number-input'),
NumberInput: (props: any) => numberInputMock(props),
}))

const renderFormWithNumberInput = (props: Props) =>
render(
<Form.ConfigProvider value={{}}>
<Form onSubmit={() => {}}>
<NumberInput label='Test' data-testid='number-input' {...props} />
</Form>
</Form.ConfigProvider>
)

describe('Form.NumberInput', () => {
describe('when "min" and "max" props are provided', () => {
it('passes them to NumberInput', () => {
renderFormWithNumberInput({
min: '8',
max: '12',
name: 'test-input',
})

expect(numberInputMock).toHaveBeenCalledTimes(1)
expect(numberInputMock).toHaveBeenCalledWith(
expect.objectContaining({
min: '8',
max: '12',
name: 'test-input',
})
)
})
})
})

0 comments on commit 1272641

Please sign in to comment.