-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: add commitBehavior to NumberField #9679
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
330f526
a30ea4b
f5e01f6
1cb6081
6803aa9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -335,6 +335,30 @@ describe('NumberField', function () { | |
| expect(container).not.toHaveAttribute('aria-invalid'); | ||
| }); | ||
|
|
||
| it.each` | ||
| Name | ||
| ${'NumberField'} | ||
| `('$Name will allow typing of a number less than the min when value snapping is disabled', async () => { | ||
| let { | ||
| container, | ||
| textField | ||
| } = renderNumberField({onChange: onChangeSpy, minValue: 10, isValueSnappingDisabled: true}); | ||
|
|
||
| expect(container).not.toHaveAttribute('aria-invalid'); | ||
|
|
||
| act(() => {textField.focus();}); | ||
| await user.clear(textField); | ||
| await user.keyboard('5'); | ||
| expect(onChangeSpy).toHaveBeenCalledTimes(0); | ||
| expect(textField).toHaveAttribute('value', '5'); | ||
| act(() => {textField.blur();}); | ||
| expect(onChangeSpy).toHaveBeenCalledTimes(1); | ||
| expect(onChangeSpy).toHaveBeenCalledWith(5); | ||
| expect(textField).toHaveAttribute('value', '5'); | ||
|
|
||
| expect(container).not.toHaveAttribute('aria-invalid'); | ||
|
||
| }); | ||
|
|
||
| it.each` | ||
| Name | ||
| ${'NumberField'} | ||
|
|
@@ -383,6 +407,37 @@ describe('NumberField', function () { | |
| expect(textField).toHaveAttribute('value', '1'); | ||
| }); | ||
|
|
||
| it.each` | ||
| Name | ||
| ${'NumberField'} | ||
| `('$Name will allow typing of a number greater than the max when value snapping is disabled', async () => { | ||
| let { | ||
| container, | ||
| textField | ||
| } = renderNumberField({onChange: onChangeSpy, maxValue: 1, defaultValue: 0, isValueSnappingDisabled: true}); | ||
|
|
||
| expect(container).not.toHaveAttribute('aria-invalid'); | ||
|
|
||
| act(() => {textField.focus();}); | ||
| await user.keyboard('2'); | ||
| expect(onChangeSpy).not.toHaveBeenCalled(); | ||
| act(() => {textField.blur();}); | ||
| expect(onChangeSpy).toHaveBeenCalled(); | ||
| expect(onChangeSpy).toHaveBeenCalledWith(2); | ||
| expect(textField).toHaveAttribute('value', '2'); | ||
|
|
||
| expect(container).not.toHaveAttribute('aria-invalid'); | ||
|
|
||
| onChangeSpy.mockReset(); | ||
| act(() => {textField.focus();}); | ||
| await user.keyboard('2'); | ||
| expect(onChangeSpy).not.toHaveBeenCalled(); | ||
| act(() => {textField.blur();}); | ||
| expect(onChangeSpy).toHaveBeenCalled(); | ||
| expect(onChangeSpy).toHaveBeenCalledWith(22); | ||
| expect(textField).toHaveAttribute('value', '22'); | ||
| }); | ||
|
|
||
| it.each` | ||
| Name | ||
| ${'NumberField'} | ||
|
|
@@ -772,6 +827,20 @@ describe('NumberField', function () { | |
| expect(textField).toHaveAttribute('value', result); | ||
| }); | ||
|
|
||
| it.each` | ||
| Name | value | ||
| ${'NumberField down positive'} | ${'6'} | ||
| ${'NumberField up positive'} | ${'8'} | ||
| ${'NumberField down negative'} | ${'-8'} | ||
| ${'NumberField up negative'} | ${'-6'} | ||
| `('$Name does not round to step on commit when value snapping is disabled', async ({value}) => { | ||
| let {textField} = renderNumberField({onChange: onChangeSpy, step: 5, isValueSnappingDisabled: true}); | ||
| act(() => {textField.focus();}); | ||
| await user.keyboard(value); | ||
| act(() => {textField.blur();}); | ||
| expect(textField).toHaveAttribute('value', value); | ||
| }); | ||
|
|
||
| it.each` | ||
| Name | value | result | ||
| ${'NumberField down positive'} | ${'6'} | ${'5'} | ||
|
|
||
snowystinger marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,11 @@ export interface NumberFieldProps extends InputBase, Validation<number>, Focusab | |
| * Formatting options for the value displayed in the number field. | ||
| * This also affects what characters are allowed to be typed by the user. | ||
| */ | ||
| formatOptions?: Intl.NumberFormatOptions | ||
| formatOptions?: Intl.NumberFormatOptions, | ||
| /** | ||
| * Disables value snapping when user finishes editing the value (e.g. on blur). | ||
| */ | ||
| isValueSnappingDisabled?: boolean | ||
|
||
| } | ||
|
|
||
| export interface AriaNumberFieldProps extends NumberFieldProps, DOMProps, AriaLabelingProps, TextInputDOMEvents { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.