Skip to content

Commit 10257fa

Browse files
author
Yt
authored
feat: add onValueChange callback (#47)
1 parent 7c2919f commit 10257fa

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/lib/CurrencyInput.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
formattedZero?: string;
2222
}
2323
24+
type Callback = (value: number) => any;
25+
2426
export let value: number = DEFAULT_VALUE;
2527
export let locale: string = DEFAULT_LOCALE;
2628
export let currency: string = DEFAULT_CURRENCY;
@@ -31,6 +33,7 @@
3133
export let isNegativeAllowed: boolean = true;
3234
export let fractionDigits: number = DEFAULT_FRACTION_DIGITS;
3335
export let inputClasses: InputClasses | null = null;
36+
export let onValueChange: Callback = () => {};
3437
3538
// Formats value as: e.g. $1,523.00 | -$1,523.00
3639
const formatCurrency = (
@@ -120,6 +123,7 @@
120123
}
121124
}
122125
}
126+
onValueChange(value)
123127
};
124128
125129
const setFormattedValue = () => {

src/routes/+page.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
placeholder={null}
2323
locale="en-GB"
2424
currency="GBP"
25+
onValueChange={(value) => {console.log("you typed in the gbp input", value)}}
2526
/>
2627
<CurrencyInput
2728
name="bitcoin"

0 commit comments

Comments
 (0)