Skip to content

Commit

Permalink
Merge pull request #833 from qonto/prevent-default-pasting-event
Browse files Browse the repository at this point in the history
Fix: prevent default behavior for the paste event
  • Loading branch information
vscav authored Jul 23, 2024
2 parents 587b263 + 2acb692 commit 5baa608
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion ember-amount-input/src/components/amount-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,17 @@ export default class AmountInput extends Component<AmountInputSignature> {

@action
onPaste(event: ClipboardEvent): boolean {
event.preventDefault();

const pastedValue = event.clipboardData?.getData('text');
const parsedValue = parseFloat(pastedValue?.replace(/\s/g, '') ?? '');

if (!isNaN(parsedValue)) {
this.args.update(parsedValue.toFixed(this.numberOfDecimal));
return true;
}

return true;
return false;
}

@action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ module('Integration | Component | amount-input', function (hooks) {
module('and the value is not a valid amount', function () {
test('calls update with an empty string value', async function (assert) {
await render<TestContext>(hbs`
<AmountInput
@value={{this.value}}
@update={{fn (mut this.value)}}
/>
`);
<AmountInput
@value={{this.value}}
@update={{fn (mut this.value)}}
/>
`);

await simulateUserPasteValue('input', 'foo');

Expand Down

0 comments on commit 5baa608

Please sign in to comment.