Skip to content

Commit

Permalink
chore: add value type
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Sep 19, 2023
1 parent 13a5a28 commit b92640a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
39 changes: 22 additions & 17 deletions src/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,28 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {

const getInputElement = () => {
// Fix https://fb.me/react-unknown-prop
const otherProps = omit(props as InputProps, [
'prefixCls',
'onPressEnter',
'addonBefore',
'addonAfter',
'prefix',
'suffix',
'allowClear',
// Input elements must be either controlled or uncontrolled,
// specify either the value prop, or the defaultValue prop, but not both.
'defaultValue',
'showCount',
'classes',
'htmlSize',
'styles',
'classNames',
]);
const otherProps = omit(
props as Omit<InputProps, 'value'> & {
value?: React.InputHTMLAttributes<HTMLInputElement>['value'];
},
[
'prefixCls',
'onPressEnter',
'addonBefore',
'addonAfter',
'prefix',
'suffix',
'allowClear',
// Input elements must be either controlled or uncontrolled,
// specify either the value prop, or the defaultValue prop, but not both.
'defaultValue',
'showCount',
'classes',
'htmlSize',
'styles',
'classNames',
],
);
return (
<input
autoComplete={autoComplete}
Expand Down
10 changes: 8 additions & 2 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ export interface CommonInputProps {

type DataAttr = Record<`data-${string}`, string>;

export type ValueType = InputHTMLAttributes<HTMLInputElement>['value'] | bigint;

export interface BaseInputProps extends CommonInputProps {
value?: InputHTMLAttributes<HTMLInputElement>['value'];
value?: ValueType;
inputElement: ReactElement;
prefixCls?: string;
className?: string;
Expand Down Expand Up @@ -68,7 +70,11 @@ export interface ShowCountProps {

export interface InputProps
extends CommonInputProps,
Omit<InputHTMLAttributes<HTMLInputElement>, 'size' | 'prefix' | 'type'> {
Omit<
InputHTMLAttributes<HTMLInputElement>,
'size' | 'prefix' | 'type' | 'value'
> {
value?: ValueType;
prefixCls?: string;
// ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#%3Cinput%3E_types
type?: LiteralUnion<
Expand Down
4 changes: 4 additions & 0 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ describe('Input', () => {
await user.click(container.querySelector('.rc-input-clear-icon')!);
expect(document.activeElement).toBe(container.querySelector('input'));
});

it('support bigint type', () => {
expect(<Input value={BigInt('2222')} />).toBeTruthy();
});
});

describe('should support showCount', () => {
Expand Down

0 comments on commit b92640a

Please sign in to comment.