Skip to content

Commit

Permalink
🐛 fix: fix Input ref props
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Jun 16, 2023
1 parent 5e5cd62 commit da05109
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions src/antd/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InputProps as Props, Input as _Input } from 'antd';
import type { FC } from 'react';
import { useRef } from 'react';
import { InputRef, InputProps as Props, Input as _Input } from 'antd';
import { forwardRef, useRef } from 'react';

import { ConfigProvider } from '../ConfigProvider';
import { createStyles } from '../theme';

Expand All @@ -12,22 +12,31 @@ const useStyles = createStyles(
`,
);

export const Input: FC<InputProps> = ({ className, ...props }) => {
const { styles, cx } = useStyles();
const compositionRef = useRef(false);
export const Input = forwardRef<InputRef, InputProps>(
({ className, onCompositionStart, onCompositionEnd, ...props }, ref) => {
const { styles, cx } = useStyles();
const compositionRef = useRef(false);

return (
<ConfigProvider>
<_Input
onCompositionStart={() => (compositionRef.current = true)}
onCompositionEnd={() => (compositionRef.current = false)}
{...props}
className={cx(styles, className)}
onPressEnter={(e) => {
if (compositionRef.current) return;
props.onPressEnter?.(e);
}}
/>
</ConfigProvider>
);
};
return (
<ConfigProvider>
<_Input
{...props}
ref={ref}
className={cx(styles, className)}
onPressEnter={(e) => {
if (compositionRef.current) return;
props.onPressEnter?.(e);
}}
onCompositionStart={(e) => {
compositionRef.current = true;
onCompositionStart?.(e);
}}
onCompositionEnd={(e) => {
compositionRef.current = false;
onCompositionEnd?.(e);
}}
/>
</ConfigProvider>
);
},
);

0 comments on commit da05109

Please sign in to comment.