Skip to content

Commit 5d992c9

Browse files
authored
chore: add value type (#46)
1 parent 13a5a28 commit 5d992c9

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

src/Input.tsx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,28 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
110110

111111
const getInputElement = () => {
112112
// Fix https://fb.me/react-unknown-prop
113-
const otherProps = omit(props as InputProps, [
114-
'prefixCls',
115-
'onPressEnter',
116-
'addonBefore',
117-
'addonAfter',
118-
'prefix',
119-
'suffix',
120-
'allowClear',
121-
// Input elements must be either controlled or uncontrolled,
122-
// specify either the value prop, or the defaultValue prop, but not both.
123-
'defaultValue',
124-
'showCount',
125-
'classes',
126-
'htmlSize',
127-
'styles',
128-
'classNames',
129-
]);
113+
const otherProps = omit(
114+
props as Omit<InputProps, 'value'> & {
115+
value?: React.InputHTMLAttributes<HTMLInputElement>['value'];
116+
},
117+
[
118+
'prefixCls',
119+
'onPressEnter',
120+
'addonBefore',
121+
'addonAfter',
122+
'prefix',
123+
'suffix',
124+
'allowClear',
125+
// Input elements must be either controlled or uncontrolled,
126+
// specify either the value prop, or the defaultValue prop, but not both.
127+
'defaultValue',
128+
'showCount',
129+
'classes',
130+
'htmlSize',
131+
'styles',
132+
'classNames',
133+
],
134+
);
130135
return (
131136
<input
132137
autoComplete={autoComplete}

src/interface.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ export interface CommonInputProps {
3535

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

38+
export type ValueType = InputHTMLAttributes<HTMLInputElement>['value'] | bigint;
39+
3840
export interface BaseInputProps extends CommonInputProps {
39-
value?: InputHTMLAttributes<HTMLInputElement>['value'];
41+
value?: ValueType;
4042
inputElement: ReactElement;
4143
prefixCls?: string;
4244
className?: string;
@@ -68,7 +70,11 @@ export interface ShowCountProps {
6870

6971
export interface InputProps
7072
extends CommonInputProps,
71-
Omit<InputHTMLAttributes<HTMLInputElement>, 'size' | 'prefix' | 'type'> {
73+
Omit<
74+
InputHTMLAttributes<HTMLInputElement>,
75+
'size' | 'prefix' | 'type' | 'value'
76+
> {
77+
value?: ValueType;
7278
prefixCls?: string;
7379
// ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#%3Cinput%3E_types
7480
type?: LiteralUnion<

tests/index.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ describe('Input', () => {
7575
await user.click(container.querySelector('.rc-input-clear-icon')!);
7676
expect(document.activeElement).toBe(container.querySelector('input'));
7777
});
78+
79+
it('support bigint type', () => {
80+
expect(<Input value={BigInt('2222')} />).toBeTruthy();
81+
});
7882
});
7983

8084
describe('should support showCount', () => {

0 commit comments

Comments
 (0)