From b6cb5764f49a2e9dcf726f68300ace715a487e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=AC=A2?= Date: Fri, 8 May 2026 16:30:24 +0800 Subject: [PATCH 1/2] feat: add inputProps prop to pass props to internal input - Add inputProps to BaseSelectProps, SelectInputProps and InputProps - Merge user inputProps with default props in Content/index.tsx - Add test case for inputProps - Update README with API documentation Close ant-design/ant-design#38012 --- README.md | 1 + src/BaseSelect/index.tsx | 7 +++++-- src/SelectInput/Content/index.tsx | 8 +++++++- src/SelectInput/Input.tsx | 4 ++++ src/SelectInput/index.tsx | 2 ++ tests/BaseSelect.test.tsx | 20 ++++++++++++++++++++ 6 files changed, 39 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4e666e10..4b18c1c7 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,7 @@ export default () => ( | optionRender | Custom rendering options | (oriOption: FlattenOptionData\ , info: { index: number }) => React.ReactNode | - | | labelRender | Custom rendering label | (props: LabelInValueType) => React.ReactNode | - | | maxCount | The max number of items can be selected | number | - | +| inputProps | props passed to the internal input element | React.InputHTMLAttributes | - | ### Methods diff --git a/src/BaseSelect/index.tsx b/src/BaseSelect/index.tsx index 2b56b4dc..7215b30e 100644 --- a/src/BaseSelect/index.tsx +++ b/src/BaseSelect/index.tsx @@ -130,8 +130,7 @@ export interface BaseSelectPrivateProps { export type BaseSelectPropsWithoutPrivate = Omit; export interface BaseSelectProps - extends - BaseSelectPrivateProps, + extends BaseSelectPrivateProps, React.AriaAttributes, Pick, 'role'> { // Style @@ -229,6 +228,10 @@ export interface BaseSelectProps // >>> Components components?: ComponentsConfig; + + // >>> Input + /** Props passed to the internal input element */ + inputProps?: React.InputHTMLAttributes; } export const isMultiple = (mode: Mode) => mode === 'tags' || mode === 'multiple'; diff --git a/src/SelectInput/Content/index.tsx b/src/SelectInput/Content/index.tsx index fc56d19a..e10eeb03 100644 --- a/src/SelectInput/Content/index.tsx +++ b/src/SelectInput/Content/index.tsx @@ -10,7 +10,12 @@ export interface SharedContentProps { } const SelectContent = React.forwardRef(function SelectContent(_, ref) { - const { multiple, onInputKeyDown, tabIndex } = useSelectInputContext(); + const { + multiple, + onInputKeyDown, + tabIndex, + inputProps: userInputProps, + } = useSelectInputContext(); const baseProps = useBaseProps(); const { showSearch } = baseProps; @@ -18,6 +23,7 @@ const SelectContent = React.forwardRef(function SelectContent( const sharedInputProps: SharedContentProps['inputProps'] = { ...ariaProps, + ...userInputProps, onKeyDown: onInputKeyDown, readOnly: !showSearch, tabIndex, diff --git a/src/SelectInput/Input.tsx b/src/SelectInput/Input.tsx index 8c12606a..c52d5acc 100644 --- a/src/SelectInput/Input.tsx +++ b/src/SelectInput/Input.tsx @@ -21,6 +21,8 @@ export interface InputProps { syncWidth?: boolean; /** autoComplete for input */ autoComplete?: string; + /** Props passed to the internal input element */ + inputProps?: React.InputHTMLAttributes; } const Input = React.forwardRef((props, ref) => { @@ -33,6 +35,7 @@ const Input = React.forwardRef((props, ref) => { value, className, autoComplete, + inputProps, ...restProps } = props; const { @@ -164,6 +167,7 @@ const Input = React.forwardRef((props, ref) => { id, type: mode === 'combobox' ? 'text' : 'search', ...restProps, + ...inputProps, ref: inputRef as React.Ref, style: { ...styles?.input, diff --git a/src/SelectInput/index.tsx b/src/SelectInput/index.tsx index ee5ad4fc..d358f9b2 100644 --- a/src/SelectInput/index.tsx +++ b/src/SelectInput/index.tsx @@ -48,6 +48,8 @@ export interface SelectInputProps extends Omit; } const DEFAULT_OMIT_PROPS = [ diff --git a/tests/BaseSelect.test.tsx b/tests/BaseSelect.test.tsx index d107743d..22de60f3 100644 --- a/tests/BaseSelect.test.tsx +++ b/tests/BaseSelect.test.tsx @@ -190,4 +190,24 @@ describe('BaseSelect', () => { expect(container.querySelector('.custom-root-element')).toBeTruthy(); expect(container.querySelector('.rc-select')).toBeFalsy(); }); + + it('should pass inputProps to internal input', () => { + const { container } = render( + {}} + onSearch={() => {}} + searchValue="" + />, + ); + + const input = container.querySelector('input'); + expect(input?.getAttribute('spellcheck')).toBe('false'); + }); }); From 56e4bb0fca818e58a88721a7eda52e0ed34ef698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=AC=A2?= Date: Fri, 8 May 2026 16:48:03 +0800 Subject: [PATCH 2/2] fix: add inputProps to DEFAULT_OMIT_PROPS to prevent React DOM warning --- src/SelectInput/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SelectInput/index.tsx b/src/SelectInput/index.tsx index d358f9b2..090dffc8 100644 --- a/src/SelectInput/index.tsx +++ b/src/SelectInput/index.tsx @@ -67,6 +67,7 @@ const DEFAULT_OMIT_PROPS = [ 'activeValue', 'onSelectorRemove', 'focused', + 'inputProps', ] as const; export default React.forwardRef(function SelectInput(