patch(form-core): expose mimicUserInput test-helper

This commit is contained in:
Thijs Louisse 2022-03-15 19:06:13 +01:00
parent 876cf07fdb
commit 3772c94301
3 changed files with 22 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/form-core': patch
---
form-core: expose 'mimicUserInput' test-helper

View file

@ -1,2 +1,3 @@
export * from './ExampleValidators.js';
export * from './getFormControlMembers.js';
export * from './mimicUserInput.js';

View 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 }));
}