patch(form-core): expose mimicUserInput test-helper
This commit is contained in:
parent
876cf07fdb
commit
3772c94301
3 changed files with 22 additions and 0 deletions
5
.changeset/green-ads-fold.md
Normal file
5
.changeset/green-ads-fold.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@lion/form-core': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
form-core: expose 'mimicUserInput' test-helper
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
export * from './ExampleValidators.js';
|
export * from './ExampleValidators.js';
|
||||||
export * from './getFormControlMembers.js';
|
export * from './getFormControlMembers.js';
|
||||||
|
export * from './mimicUserInput.js';
|
||||||
|
|
|
||||||
16
packages/form-core/test-helpers/mimicUserInput.js
Normal file
16
packages/form-core/test-helpers/mimicUserInput.js
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
// @ts-nocheck
|
||||||
|
/**
|
||||||
|
* @param {HTMLElement} formControl
|
||||||
|
* @param {?} newViewValue
|
||||||
|
* @param {{caretIndex?:number}} config
|
||||||
|
*/
|
||||||
|
export function mimicUserInput(formControl, newViewValue, { caretIndex } = {}) {
|
||||||
|
formControl.value = newViewValue; // eslint-disable-line no-param-reassign
|
||||||
|
if (caretIndex) {
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
formControl._inputNode.selectionStart = caretIndex;
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
formControl._inputNode.selectionEnd = caretIndex;
|
||||||
|
}
|
||||||
|
formControl._inputNode.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue