Skip to content

Commit 3ca6f16

Browse files
committed
chore: test config
1 parent 7f38025 commit 3ca6f16

5 files changed

Lines changed: 52 additions & 15 deletions

File tree

src/SelectInput/Input.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react';
22
import { useSelectInputContext } from './context';
3-
import useBaseProps from '../hooks/useBaseProps';
43

54
export interface InputProps {
65
disabled?: boolean;
@@ -19,9 +18,8 @@ export interface InputProps {
1918

2019
const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
2120
const { onChange, onKeyDown, onBlur, ...restProps } = props;
22-
const { prefixCls, mode, onSearch, onSearchSubmit, onInputBlur, maxLength, autoFocus } =
21+
const { prefixCls, mode, onSearch, onSearchSubmit, onInputBlur, autoFocus } =
2322
useSelectInputContext();
24-
const { triggerOpen } = useBaseProps();
2523

2624
const inputCls = `${prefixCls}-input`;
2725

@@ -47,13 +45,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
4745
const { value } = event.currentTarget;
4846

4947
// Handle Enter key submission - referencing Selector implementation
50-
if (
51-
key === 'Enter' &&
52-
mode === 'tags' &&
53-
!compositionStatusRef.current &&
54-
!triggerOpen &&
55-
onSearchSubmit
56-
) {
48+
if (key === 'Enter' && mode === 'tags' && !compositionStatusRef.current && onSearchSubmit) {
5749
onSearchSubmit(value);
5850
}
5951

src/SelectInput/index.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import clsx from 'clsx';
33
import Affix from './Affix';
44
import SelectContent from './Content';
5-
import SelectInputContext, { type ContentContextProps } from './context';
5+
import SelectInputContext from './context';
66
import type { DisplayValueType, Mode } from '../interface';
77

88
export interface SelectInputRef {
@@ -95,6 +95,18 @@ export default React.forwardRef<SelectInputRef, SelectInputProps>(function Selec
9595
const rootRef = React.useRef<HTMLDivElement>(null);
9696
const inputRef = React.useRef<HTMLInputElement>(null);
9797

98+
// Wrap onSearch to trigger dropdown open when typing
99+
const onInternalSearch = useEvent(
100+
(searchText: string, fromTyping: boolean, isCompositing: boolean) => {
101+
// Open dropdown when user is typing and not compositing
102+
if (fromTyping && !isCompositing && !triggerOpen) {
103+
toggleOpen(true);
104+
}
105+
106+
onSearch?.(searchText, fromTyping, isCompositing);
107+
},
108+
);
109+
98110
// ====================== Refs ======================
99111
React.useImperativeHandle(
100112
ref,
@@ -134,8 +146,14 @@ export default React.forwardRef<SelectInputRef, SelectInputProps>(function Selec
134146
// ===================== Render =====================
135147
const domProps = omit(restProps, DEFAULT_OMIT_PROPS);
136148

149+
// Create context value with wrapped onSearch
150+
const contextValue = {
151+
...props,
152+
onSearch: onInternalSearch,
153+
};
154+
137155
return (
138-
<SelectInputContext.Provider value={props}>
156+
<SelectInputContext.Provider value={contextValue}>
139157
<div
140158
{...domProps}
141159
// Style

src/hooks/useOpen.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ export default function useOpen(
4040
return;
4141
}
4242

43-
console.error('toggleOpen', nextOpenVal);
44-
4543
if (nextOpenVal) {
4644
triggerEvent(true);
4745
return;

tests/Combobox.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ describe('Select.Combobox', () => {
239239
fireEvent.change(container.querySelector('input')!, { target: { value: '0' } });
240240
expectOpen(container);
241241

242+
console.log('!11111111111111');
242243
selectItem(container);
244+
console.log('!2222222222222');
243245
jest.runAllTimers();
244246
expectOpen(container, false);
245247
jest.useRealTimers();

tests/setup.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
1-
window.MessageChannel = require('worker_threads').MessageChannel;
1+
window.MessageChannel = class {
2+
port1: any;
3+
port2: any;
4+
5+
constructor() {
6+
const createPort = () => {
7+
const port = {
8+
onmessage: null,
9+
postMessage: (message: any) => {
10+
setTimeout(() => {
11+
if (port._target && typeof port._target.onmessage === 'function') {
12+
port._target.onmessage({ data: message });
13+
}
14+
}, 0);
15+
},
16+
_target: null,
17+
};
18+
return port;
19+
};
20+
21+
const port1 = createPort();
22+
const port2 = createPort();
23+
port1._target = port2;
24+
port2._target = port1;
25+
this.port1 = port1;
26+
this.port2 = port2;
27+
}
28+
} as any;

0 commit comments

Comments
 (0)