Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: prevent default behavior for the paste event #833

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading