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: Correct types for customInput property #827

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions src/number_format_base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,17 @@ export default function NumberFormatBase<BaseType = InputAttributes>(
// add input mode on element based on format prop and device once the component is mounted
const inputMode: InputAttributes['inputMode'] = mounted && addInputMode() ? 'numeric' : undefined;

const inputProps = Object.assign({ inputMode }, otherProps, {
const inputProps: InputAttributes = {
inputMode,
...otherProps,
type,
value: formattedValue,
onChange: _onChange,
onKeyDown: _onKeyDown,
onMouseUp: _onMouseUp,
onFocus: _onFocus,
onBlur: _onBlur,
});
};

if (displayType === 'text') {
return renderText ? (
Expand All @@ -444,7 +446,7 @@ export default function NumberFormatBase<BaseType = InputAttributes>(
);
} else if (customInput) {
const CustomInput = customInput;
/* @ts-ignore */
// @ts-expect-error
return <CustomInput {...inputProps} ref={getInputRef} />;
}

Expand Down
2 changes: 1 addition & 1 deletion src/pattern_format.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export function usePatternFormat<BaseType = InputAttributes>(
inputMode,
format: (numStr: string) => format(numStr, _props),
removeFormatting: (inputValue: string, changeMeta: ChangeMeta) =>
removeFormatting(inputValue, changeMeta, _props),
removeFormatting(inputValue, changeMeta, _props),
getCaretBoundary: _getCaretBoundary,
onKeyDown: _onKeyDown,
};
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type ChangeMeta = {

export type InputAttributes = Omit<
React.InputHTMLAttributes<HTMLInputElement>,
'defaultValue' | 'value' | 'children'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FMI: why do you need to omit 'defaultValue' | 'value' from InputAttributes?

'defaultValue' | 'children'
>;

type NumberFormatProps<Props, BaseType = InputAttributes> = Props &
Expand Down