Skip to content

Commit 642379d

Browse files
authored
fix: missing comps event (#49)
1 parent 67ebb95 commit 642379d

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/Input.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
3434
classes,
3535
classNames,
3636
styles,
37+
onCompositionStart,
38+
onCompositionEnd,
3739
...rest
3840
} = props;
3941

@@ -114,9 +116,12 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
114116
triggerChange(e, e.target.value);
115117
};
116118

117-
const onCompositionEnd = (e: React.CompositionEvent<HTMLInputElement>) => {
119+
const onInternalCompositionEnd = (
120+
e: React.CompositionEvent<HTMLInputElement>,
121+
) => {
118122
compositionRef.current = false;
119123
triggerChange(e, e.currentTarget.value);
124+
onCompositionEnd?.(e);
120125
};
121126

122127
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
@@ -189,10 +194,11 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
189194
ref={inputRef}
190195
size={htmlSize}
191196
type={type}
192-
onCompositionStart={() => {
197+
onCompositionStart={(e) => {
193198
compositionRef.current = true;
199+
onCompositionStart?.(e);
194200
}}
195-
onCompositionEnd={onCompositionEnd}
201+
onCompositionEnd={onInternalCompositionEnd}
196202
/>
197203
);
198204
};

tests/count.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ describe('Input.Count', () => {
4848
});
4949

5050
it('exceedFormatter', () => {
51+
const onCompositionStart = jest.fn();
52+
const onCompositionEnd = jest.fn();
53+
5154
const { container } = render(
5255
<Input
5356
count={{
@@ -59,6 +62,8 @@ describe('Input.Count', () => {
5962
.map((seg) => seg.segment)
6063
.join(''),
6164
}}
65+
onCompositionStart={onCompositionStart}
66+
onCompositionEnd={onCompositionEnd}
6267
/>,
6368
);
6469

@@ -70,9 +75,11 @@ describe('Input.Count', () => {
7075
},
7176
});
7277
expect(container.querySelector('input')?.value).toEqual('🔥🔥🔥🔥🔥');
78+
expect(onCompositionStart).toHaveBeenCalled();
7379

7480
// Fallback
7581
fireEvent.compositionEnd(container.querySelector('input')!);
7682
expect(container.querySelector('input')?.value).toEqual('🔥');
83+
expect(onCompositionEnd).toHaveBeenCalled();
7784
});
7885
});

0 commit comments

Comments
 (0)