Skip to content

Commit 1b387ce

Browse files
zombieJclaude
andcommitted
fix: handle nested nativeElement structure in SelectInput
Use getDOM to properly extract the underlying DOM element when RootComponent returns a nested structure (e.g., antd Input with nativeElement property). Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 0bde22d commit 1b387ce

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/SelectInput/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ export default React.forwardRef<SelectInputRef, SelectInputProps>(function Selec
165165
blur: () => {
166166
(inputRef.current || rootRef.current).blur?.();
167167
},
168-
nativeElement: rootRef.current,
168+
// Use getDOM to handle nested nativeElement structure (e.g., when RootComponent is antd Input)
169+
nativeElement: getDOM(rootRef.current),
169170
};
170171
});
171172

tests/Custom.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,36 @@ describe('Select.Custom', () => {
4848
expect(onFocus).toHaveBeenCalled();
4949
expect(onBlur).toHaveBeenCalled();
5050
});
51+
52+
it('should handle nested nativeElement structure correctly', () => {
53+
// Mock component that returns nativeElement structure (similar to antd Input)
54+
const CustomInputWithNativeElement = React.forwardRef<
55+
{ nativeElement: HTMLInputElement },
56+
React.InputHTMLAttributes<HTMLInputElement>
57+
>((props, ref) => {
58+
const inputRef = React.useRef<HTMLInputElement>(null);
59+
60+
React.useImperativeHandle(ref, () => ({
61+
nativeElement: inputRef.current!,
62+
focus: () => inputRef.current?.focus(),
63+
blur: () => inputRef.current?.blur(),
64+
}));
65+
66+
return <input ref={inputRef} {...props} />;
67+
});
68+
69+
const selectRef = React.createRef<any>();
70+
71+
render(
72+
<Select
73+
ref={selectRef}
74+
getRawInputElement={() => <CustomInputWithNativeElement className="custom-input" />}
75+
/>,
76+
);
77+
78+
// The nativeElement should be a DOM element, not a nested object
79+
const { nativeElement } = selectRef.current;
80+
expect(nativeElement).toBeInstanceOf(HTMLInputElement);
81+
expect(nativeElement.className).toBe('custom-input');
82+
});
5183
});

0 commit comments

Comments
 (0)