Skip to content

Commit 78dd42b

Browse files
authored
test: composition events (#511)
1 parent 29edb61 commit 78dd42b

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

src/Selector/MultipleSelector.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ const SelectSelector: React.FC<SelectorProps> = props => {
6060
onInputPaste,
6161
onInputKeyDown,
6262
onInputMouseDown,
63-
onCompositionStart,
64-
onCompositionEnd,
63+
onInputCompositionStart,
64+
onInputCompositionEnd,
6565
} = props;
6666

6767
const [motionAppear, setMotionAppear] = React.useState(false);
@@ -198,8 +198,8 @@ const SelectSelector: React.FC<SelectorProps> = props => {
198198
onMouseDown={onInputMouseDown}
199199
onChange={onInputChange}
200200
onPaste={onInputPaste}
201-
onCompositionStart={onCompositionStart}
202-
onCompositionEnd={onCompositionEnd}
201+
onCompositionStart={onInputCompositionStart}
202+
onCompositionEnd={onInputCompositionEnd}
203203
tabIndex={tabIndex}
204204
attrs={pickAttrs(props, true)}
205205
/>

src/Selector/SingleSelector.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ const SingleSelector: React.FC<SelectorProps> = props => {
3333
onInputMouseDown,
3434
onInputChange,
3535
onInputPaste,
36-
onCompositionStart,
37-
onCompositionEnd,
36+
onInputCompositionStart,
37+
onInputCompositionEnd,
3838
} = props;
3939

4040
const combobox = mode === 'combobox';
@@ -69,8 +69,8 @@ const SingleSelector: React.FC<SelectorProps> = props => {
6969
onMouseDown={onInputMouseDown}
7070
onChange={onInputChange}
7171
onPaste={onInputPaste}
72-
onCompositionStart={onCompositionStart}
73-
onCompositionEnd={onCompositionEnd}
72+
onCompositionStart={onInputCompositionStart}
73+
onCompositionEnd={onInputCompositionEnd}
7474
tabIndex={tabIndex}
7575
attrs={pickAttrs(props, true)}
7676
/>

src/Selector/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export interface InnerSelectorProps {
3737
onInputMouseDown: React.MouseEventHandler<HTMLInputElement | HTMLTextAreaElement>;
3838
onInputChange: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
3939
onInputPaste: React.ClipboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
40-
onCompositionStart: React.CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement>;
41-
onCompositionEnd: React.CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement>;
40+
onInputCompositionStart: React.CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement>;
41+
onInputCompositionEnd: React.CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement>;
4242
}
4343

4444
export interface RefSelectorProps {
@@ -152,11 +152,11 @@ const Selector: React.RefForwardingComponent<RefSelectorProps, SelectorProps> =
152152
}
153153
};
154154

155-
const onCompositionStart = () => {
155+
const onInputCompositionStart = () => {
156156
compositionStatusRef.current = true;
157157
};
158158

159-
const onCompositionEnd = () => {
159+
const onInputCompositionEnd = () => {
160160
compositionStatusRef.current = false;
161161
};
162162

@@ -215,8 +215,8 @@ const Selector: React.RefForwardingComponent<RefSelectorProps, SelectorProps> =
215215
onInputMouseDown: onInternalInputMouseDown,
216216
onInputChange,
217217
onInputPaste,
218-
onCompositionStart,
219-
onCompositionEnd,
218+
onInputCompositionStart,
219+
onInputCompositionEnd,
220220
};
221221

222222
const selectNode = multiple ? (

tests/Select.test.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,8 @@ describe('Select.Basic', () => {
779779
const onKeyDown = jest.fn();
780780
const onChange = jest.fn();
781781
const onMouseDown = jest.fn();
782+
const onCompositionStart = jest.fn();
783+
const onCompositionEnd = jest.fn();
782784
const textareaRef = jest.fn();
783785
const mouseDownPreventDefault = jest.fn();
784786
const wrapper = mount(
@@ -789,6 +791,8 @@ describe('Select.Basic', () => {
789791
onKeyDown={onKeyDown}
790792
onChange={onChange}
791793
onMouseDown={onMouseDown}
794+
onCompositionStart={onCompositionStart}
795+
onCompositionEnd={onCompositionEnd}
792796
ref={textareaRef}
793797
/>
794798
)}
@@ -805,7 +809,9 @@ describe('Select.Basic', () => {
805809
.find('textarea')
806810
.simulate('mouseDown', { preventDefault: mouseDownPreventDefault })
807811
.simulate('keyDown', { which: KeyCode.NUM_ONE })
808-
.simulate('change', { value: '1' });
812+
.simulate('change', { value: '1' })
813+
.simulate('compositionStart')
814+
.simulate('compositionEnd');
809815

810816
selectItem(wrapper);
811817
expect(wrapper.find('textarea').props().value).toEqual('1');
@@ -814,6 +820,8 @@ describe('Select.Basic', () => {
814820
expect(onChange).toHaveBeenCalled();
815821
expect(onMouseDown).toHaveBeenCalled();
816822
expect(textareaRef).toHaveBeenCalled();
823+
expect(onCompositionStart).toHaveBeenCalled();
824+
expect(onCompositionEnd).toHaveBeenCalled();
817825
});
818826

819827
describe('propTypes', () => {

0 commit comments

Comments
 (0)