Skip to content

Commit

Permalink
🔀 Merge pull request #69 from codermarcos/fix/#67/problem-input-behav…
Browse files Browse the repository at this point in the history
…iour

🐛 Fix problem input behaviour
  • Loading branch information
codermarcos authored Jan 28, 2024
2 parents 030573f + e9caf4f commit cc06f6e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
30 changes: 29 additions & 1 deletion cypress/e2e/v4.x.x/set-mask.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,35 @@ describe(
}
);

describe(
'form submit',
() => {
beforeEach(
() => {
cy.visit(getUrl({ prefix: '$', suffix: 'CAD' }, '6.66'));
}
);

it(
'should trigger form submit',
(done) => {
const spy = cy.spy().as('submit');

cy.get('form').then(form$ => {
form$.on('submit', e => {
e.preventDefault();
spy();
done();
});
});

cy.get('input').type('{Enter}');

cy.get('@submit').should('have.not.been.called');
},
);
}
);
}
);

Expand Down Expand Up @@ -307,7 +336,6 @@ describe(
}
);


describe(
'negative numbers',
() => {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-mask-money",
"version": "4.1.1",
"version": "4.1.2",
"private": false,
"description": "Simple money mask developed with pure JavaScript. To run on Client Side and Server Side",
"types": "./lib/simple-mask-money.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/set-mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ function setMask(
let start = element.selectionStart ?? lastPositionToNumber;
let end = element.selectionEnd ?? lastPositionToNumber;

// Trigger input submit
if (e.key === 'Enter') return;

// Select all
if (e.ctrlKey && e.key === 'a') return setCaretPosition([firstPositionToNumber, lastPositionToNumber]);

Expand Down

0 comments on commit cc06f6e

Please sign in to comment.