Skip to content

Commit

Permalink
Fix prop types for NumberInput
Browse files Browse the repository at this point in the history
  • Loading branch information
mikael-jarvinen committed Jan 12, 2024
1 parent d8b8e73 commit 57e0fb1
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/components/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ export type SizeTypes = 'small' | 'medium';

export type ColorTypes = 'primary' | 'white';

export type NumberInputProps = {
export interface NumberInputProps extends Omit<
OutlinedTextFieldProps,
'variant' | 'color' | 'fullWidth' | 'error' | 'helperText' | 'hiddenLabel' | 'onChange' | 'onBlur' | 'onClick' | 'onFocus'
>, Omit<UseNumberInputParameters, 'value' | 'inputRef'> {
fullWidth?: boolean;
size?: SizeTypes;
startAdornment?: string | JSX.Element;
color?: ColorTypes;
error?: boolean;
helperText?: string;
'data-testid'?: string;
} & Omit<
OutlinedTextFieldProps,
'variant' | 'color' | 'fullWidth' | 'error' | 'helperText' | 'hiddenLabel'
> & UseNumberInputParameters;
value?: number | string; // Allow strings to enable controlled behaviour, empty value "" instead of undefined
}

const NumberInput = (
{
Expand All @@ -43,11 +44,22 @@ const NumberInput = (
helperText = '',
sx = {},
InputLabelProps = {},
...props
...rest
}: NumberInputProps,
ref: Ref<HTMLDivElement>
): JSX.Element => {
const { getRootProps, getInputProps, getIncrementButtonProps, getDecrementButtonProps } = useNumberInput(props);
const { onChange, onBlur, ...props } = rest;

const {
getRootProps,
getInputProps,
getIncrementButtonProps,
getDecrementButtonProps
} = useNumberInput({
...props as UseNumberInputParameters, // Casting due to different value type
onChange,
onBlur
});
const muiTextField = useRef<HTMLDivElement>(null);
const overrideColor = color === 'white' ? 'common.white' : undefined;

Expand Down

0 comments on commit 57e0fb1

Please sign in to comment.