Skip to content
Merged
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
19 changes: 19 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ class CurrencyInput extends React.Component<CurrencyInputProps, CurrencyInputSta
static prepareProps(props: Readonly<CurrencyInputProps>): CurrencyInputState {
const {
onChangeEvent,
onBlur,
onClick,
onFocus,
value: propValue,
decimalSeparator,
thousandSeparator,
Expand All @@ -140,6 +143,10 @@ class CurrencyInput extends React.Component<CurrencyInputProps, CurrencyInputSta
selectAllOnFocus,
autoFocus,
disableSelectionHandling: propDisableSelectionHandling,
style,
id,
tabIndex,
logValues,
...customProps
} = props;
let initialValue = propValue;
Expand Down Expand Up @@ -167,6 +174,18 @@ class CurrencyInput extends React.Component<CurrencyInputProps, CurrencyInputSta
suffix
);

// Exhaustive check: if a new field is added to CurrencyInputProps but not destructured
// above, TypeScript will produce a compile error here (missing key in the object literal).
const _: Record<keyof Required<CurrencyInputProps>, unknown> = {
onBlur, onClick, onFocus, onChangeEvent,
allowEmpty, allowNegative, autoFocus,
disableSelectionHandling: propDisableSelectionHandling, selectAllOnFocus,
decimalSeparator, inputType, precision, prefix, style, suffix, thousandSeparator,
id, tabIndex, value: propValue,
logValues,
};
void _;

const disableSelectionHandling = propDisableSelectionHandling || inputType === 'number';
return { maskedValue, value, customProps, disableSelectionHandling, previousProps: props };
}
Expand Down
Loading