-
Notifications
You must be signed in to change notification settings - Fork 18
fix(number input): prevent from clearing on intermediate decimal entry (Angular) #6115
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
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7258d38
Initial plan
Copilot 7f98008
fix: skip value propagation for number inputs in intermediate decimal…
Copilot fee6312
fix: only skip writeValue for Angular badInput; revert Vue and packag…
Copilot d6827b3
fix: also guard writeValue against comma input where badInput stays f…
Copilot 019869a
fix: issue with form-components for angular
nmerget b1ac2e4
auto update snapshots (#6149)
github-actions[bot] 30b34f5
Merge remote-tracking branch 'origin/main' into copilot/fix-input-fie…
nmerget 8c3929a
fix: ensure input fields default to empty string when no value is pro…
nmerget 4f1f5b8
fix: issue with react value
nmerget b0fd6dd
Merge remote-tracking branch 'origin/main' into copilot/fix-input-fie…
nmerget 11c1f1c
fix: issue with test
nmerget 6b8c7e1
refactor: added changeset
mfranzke 45505d7
auto update snapshots (#6231)
github-actions[bot] 9e5849d
fix: call propagateChange before writeValue guard in handleFrameworkE…
Copilot 0fe9235
Merge remote-tracking branch 'origin/main' into copilot/fix-input-fie…
nmerget ca879a1
fix: enhance number input handling to skip invalid states and improve…
nmerget 6ece0c0
Merge remote-tracking branch 'refs/remotes/origin/main' into copilot/…
nmerget b93258e
fix: remove unnecessary 'dev' flags from package-lock.json
nmerget 19136eb
chore: update changset
nmerget 662f094
fix: update input field value handling to use undefined instead of em…
nmerget 5d3c765
Merge branch 'main' into copilot/fix-input-field-decimal-separator
nmerget 030503f
fix: update input field value handling to use undefined instead of em…
nmerget 12917a7
Merge branch 'main' into copilot/fix-input-field-decimal-separator
nmerget File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| "@db-ux/core-components": patch | ||
| "@db-ux/react-core-components": patch | ||
| "@db-ux/wc-core-components": patch | ||
| "@db-ux/v-core-components": patch | ||
| "@db-ux/ngx-core-components": patch | ||
| --- | ||
|
|
||
| fix(number input): prevent from clearing on intermediate decimal entry | ||
| fix(input,textarea): allow using `undefined` as `value` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { | ||
| handleFrameworkEventAngular, | ||
| handleFrameworkEventVue | ||
| } from './form-components'; | ||
|
|
||
| const createNumberEvent = ( | ||
| value: string, | ||
| badInput: boolean, | ||
| inputType?: string | ||
| ) => ({ | ||
| inputType, | ||
| target: { | ||
| type: 'number', | ||
| value, | ||
| validity: { badInput } | ||
| } | ||
| }); | ||
|
|
||
| const createTextEvent = (value: string) => ({ | ||
| target: { | ||
| type: 'text', | ||
| value, | ||
| validity: { badInput: false } | ||
| } | ||
| }); | ||
|
|
||
| describe('handleFrameworkEventAngular', () => { | ||
| it('calls propagateChange and writeValue for valid number value', () => { | ||
| const component = { | ||
| propagateChange: vi.fn(), | ||
| writeValue: vi.fn() | ||
| }; | ||
| const event = createNumberEvent('1.5', false); | ||
| handleFrameworkEventAngular(component, event); | ||
| expect(component.propagateChange).toHaveBeenCalledWith('1.5'); | ||
| expect(component.writeValue).toHaveBeenCalledWith('1.5'); | ||
| }); | ||
|
|
||
| it('skips propagateChange and writeValue when "." is typed (intermediate state)', () => { | ||
| const component = { | ||
| propagateChange: vi.fn(), | ||
| writeValue: vi.fn() | ||
| }; | ||
| const event = { | ||
| type: 'input', | ||
| data: '.', | ||
| inputType: 'insertText', | ||
| target: { type: 'number', value: '1.' } | ||
| }; | ||
| handleFrameworkEventAngular(component, event, 'value', '1'); | ||
| expect(component.propagateChange).not.toHaveBeenCalled(); | ||
| expect(component.writeValue).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('skips propagateChange and writeValue when "," is typed (intermediate state)', () => { | ||
| const component = { | ||
| propagateChange: vi.fn(), | ||
| writeValue: vi.fn() | ||
| }; | ||
| const event = { | ||
| type: 'input', | ||
| data: ',', | ||
| inputType: 'insertText', | ||
| target: { type: 'number', value: '' } | ||
| }; | ||
| handleFrameworkEventAngular(component, event, 'value', '1'); | ||
| expect(component.propagateChange).not.toHaveBeenCalled(); | ||
| expect(component.writeValue).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it.each(['e', 'E', '+', '-'])( | ||
| 'skips propagateChange and writeValue when "%s" is typed (intermediate state)', | ||
| (char) => { | ||
| const component = { | ||
| propagateChange: vi.fn(), | ||
| writeValue: vi.fn() | ||
| }; | ||
| const event = { | ||
| type: 'input', | ||
| data: char, | ||
| inputType: 'insertText', | ||
| target: { type: 'number', value: '' } | ||
| }; | ||
| handleFrameworkEventAngular(component, event, 'value', '1'); | ||
| expect(component.propagateChange).not.toHaveBeenCalled(); | ||
| expect(component.writeValue).not.toHaveBeenCalled(); | ||
| } | ||
| ); | ||
|
|
||
| it('skips propagateChange and writeValue when deleting content and lastValue has decimal', () => { | ||
| const component = { | ||
| propagateChange: vi.fn(), | ||
| writeValue: vi.fn() | ||
| }; | ||
| const event = { | ||
| type: 'input', | ||
| data: null, | ||
| inputType: 'deleteContentBackward', | ||
| target: { type: 'number', value: '' } | ||
| }; | ||
| handleFrameworkEventAngular(component, event, 'value', '1.5'); | ||
| expect(component.propagateChange).not.toHaveBeenCalled(); | ||
| expect(component.writeValue).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('calls propagateChange and writeValue when number input is cleared via backspace (no decimal in lastValue)', () => { | ||
| const component = { | ||
| propagateChange: vi.fn(), | ||
| writeValue: vi.fn() | ||
| }; | ||
| const event = createNumberEvent('', false, 'deleteContentBackward'); | ||
| handleFrameworkEventAngular(component, event); | ||
| expect(component.propagateChange).toHaveBeenCalledWith(''); | ||
| expect(component.writeValue).toHaveBeenCalledWith(''); | ||
| }); | ||
|
|
||
| it('skips propagateChange and writeValue for number change events', () => { | ||
| const component = { | ||
| propagateChange: vi.fn(), | ||
| writeValue: vi.fn() | ||
| }; | ||
| const event = { | ||
| type: 'change', | ||
| target: { type: 'number', value: '5' } | ||
| }; | ||
| handleFrameworkEventAngular(component, event); | ||
| expect(component.propagateChange).not.toHaveBeenCalled(); | ||
| expect(component.writeValue).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('calls propagateChange and writeValue for text input type', () => { | ||
| const component = { | ||
| propagateChange: vi.fn(), | ||
| writeValue: vi.fn() | ||
| }; | ||
| const event = createTextEvent('hello'); | ||
| handleFrameworkEventAngular(component, event); | ||
| expect(component.propagateChange).toHaveBeenCalledWith('hello'); | ||
| expect(component.writeValue).toHaveBeenCalledWith('hello'); | ||
| }); | ||
| }); | ||
nmerget marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| describe('handleFrameworkEventVue', () => { | ||
| it('emits update:value for valid number value', () => { | ||
| const emit = vi.fn(); | ||
| const event = createNumberEvent('1.5', false); | ||
| handleFrameworkEventVue(emit, event); | ||
| expect(emit).toHaveBeenCalledWith('update:value', '1.5'); | ||
| }); | ||
|
|
||
| it('emits update:value with empty string when number input has badInput (intermediate state like "1.")', () => { | ||
| const emit = vi.fn(); | ||
| const event = createNumberEvent('', true); | ||
| handleFrameworkEventVue(emit, event); | ||
| expect(emit).toHaveBeenCalledWith('update:value', ''); | ||
| }); | ||
|
|
||
| it('emits update:value when number input is cleared (empty, no badInput)', () => { | ||
| const emit = vi.fn(); | ||
| const event = createNumberEvent('', false); | ||
| handleFrameworkEventVue(emit, event); | ||
| expect(emit).toHaveBeenCalledWith('update:value', ''); | ||
| }); | ||
|
|
||
| it('emits update:value for text input type', () => { | ||
| const emit = vi.fn(); | ||
| const event = createTextEvent('hello'); | ||
| handleFrameworkEventVue(emit, event); | ||
| expect(emit).toHaveBeenCalledWith('update:value', 'hello'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.