Skip to content

Commit

Permalink
fix: invalid class (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaynethiessen committed Jan 8, 2024
1 parent 3c8d677 commit 2734e5d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/controls/src/money/useMoneyInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import {MutableRefObject, useCallback, useEffect, useRef} from 'react';

const d = debug('thx.controls.money.useMoneyInput');

// @ts-ignore inputmask .d.ts file is correct, but ESM causes some difficulty. -mk
const InputmaskClass = Inputmask.default || Inputmask;

interface UseMoneyInputProps {
value?: Money;
onChange?: (value?: Money) => void;
Expand Down Expand Up @@ -34,7 +37,7 @@ export function useMoneyInput(props: UseMoneyInputProps): [MutableRefObject<HTML
if (!inputElement.current) throw new Error('Could not get input element');

d('Creating input mask instance');
maskInstance.current = new Inputmask({
maskInstance.current = new InputmaskClass({
alias: 'numeric',
groupSeparator: ',',
digits: wholeNumber ? '0' : Money[currencyCode].decimal_digits.toString(),
Expand All @@ -58,6 +61,7 @@ export function useMoneyInput(props: UseMoneyInputProps): [MutableRefObject<HTML
if (onChange) onChange(toMoney(inputElement.current?.value, currencyCode));
},
});
// @ts-ignore We just created the instance but typescript can't figure it out. -mk
maskInstance.current.mask(inputElement.current);

return () => {
Expand Down Expand Up @@ -96,4 +100,4 @@ export function useMoneyInput(props: UseMoneyInputProps): [MutableRefObject<HTML
}, [setVal, value]);

return [inputElement, setVal];
}
}

0 comments on commit 2734e5d

Please sign in to comment.