Skip to content

Commit

Permalink
♻️ Removed use of processInputValue
Browse files Browse the repository at this point in the history
  • Loading branch information
ekwoka committed May 14, 2024
1 parent 401987f commit 017f0b1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/mask/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ export default function (Alpine) {
el._x_model.set(el.value)
const updater = el._x_forceModelUpdate;
el._x_forceModelUpdate = (value) => {
value = String(value);
value = formatInput(value, templateFn(value));
lastInputValue = value;
updater(value);
processInputValue(el, false, true);
el._x_model.set(el.value);
el._x_model.set(value);
};
}
})
Expand All @@ -68,7 +70,7 @@ export default function (Alpine) {
// will re-focus the input and cause a focus trap.
el.addEventListener('blur', () => processInputValue(el, false), { signal: controller.signal })

function processInputValue (el, shouldRestoreCursor = true, forceFormat = false) {
function processInputValue (el, shouldRestoreCursor = true) {
let input = el.value

let template = templateFn(input)
Expand All @@ -77,7 +79,7 @@ export default function (Alpine) {
if(!template || template === 'false') return false

// If they hit backspace, don't process input.
if (lastInputValue.length - el.value.length === 1 && !forceFormat) {
if (lastInputValue.length - el.value.length === 1) {
return lastInputValue = el.value
}

Expand Down
3 changes: 2 additions & 1 deletion tests/cypress/integration/plugins/mask.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { haveValue, html, test } from '../../utils'
import { haveData, haveValue, html, test } from '../../utils'

test('x-mask',
[html`<input x-data x-mask="(999) 999-9999">`],
Expand Down Expand Up @@ -251,5 +251,6 @@ test('$mask should process the value when updated by x-model',
get('input').should(haveValue('55,555'))
get('button').click()
get('input').should(haveValue('23,420'))
get('div').should(haveData('value', '23,420'))
}
)

0 comments on commit 017f0b1

Please sign in to comment.