Skip to content

feat: add inputProps prop to pass props to internal input#1221

Closed
EmilyyyLiu wants to merge 2 commits intoreact-component:masterfrom
EmilyyyLiu:feat/input-props
Closed

feat: add inputProps prop to pass props to internal input#1221
EmilyyyLiu wants to merge 2 commits intoreact-component:masterfrom
EmilyyyLiu:feat/input-props

Conversation

@EmilyyyLiu
Copy link
Copy Markdown
Contributor

@EmilyyyLiu EmilyyyLiu commented May 8, 2026

Background

Users need to customize the internal input element of Select component (e.g., disable spellCheck). Currently there's no way to pass props to the internal input.

Changes

  1. src/BaseSelect/index.tsx - Add inputProps to BaseSelectProps interface
  2. src/SelectInput/index.tsx - Add inputProps to SelectInputProps interface
  3. src/SelectInput/Input.tsx - Add inputProps type and merge to sharedInputProps
  4. src/SelectInput/Content/index.tsx - Merge user inputProps with default props
  5. tests/BaseSelect.test.tsx - Add test case
  6. README.md - Add API documentation

Usage

// Disable spellCheck
<Select showSearch inputProps={{ spellCheck: false }} />

Related Issue

Summary by CodeRabbit

发布说明

  • 新功能

    • 为 Select 组件及其子组件新增了 inputProps 属性,允许将标准 HTML 输入属性传递到内部 input 元素以便定制。
  • 测试

    • 增加测试,验证 inputProps 能正确转发并影响内部 input(例如 spellcheck 属性)。
  • 文档

    • 更新 README 中的 API 文档,新增 inputProps 的说明与类型示例。

- 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
@vercel
Copy link
Copy Markdown

vercel Bot commented May 8, 2026

Someone is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 8, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b7e9a69f-f211-4fb1-87b7-63623c3cc359

📥 Commits

Reviewing files that changed from the base of the PR and between b6cb576 and 56e4bb0.

📒 Files selected for processing (1)
  • src/SelectInput/index.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/SelectInput/index.tsx

Walkthrough

为 Select 组件引入可选的 inputProps(React.InputHTMLAttributes),在 BaseSelect → SelectInput → SelectContent → Input 链路中合并并应用到实际渲染的 input 元素;同时添加单元测试并在 README 中记录该 prop。

Changes

Input Props 透传功能

Layer / File(s) Summary
Props 类型契约
src/BaseSelect/index.tsx, src/SelectInput/index.tsx, src/SelectInput/Input.tsx
BaseSelectPropsSelectInputPropsInputProps 接口新增 inputProps?: React.InputHTMLAttributes<HTMLInputElement>BaseSelectextends 子句格式化调整;inputProps 添加到 DEFAULT_OMIT_PROPS
核心实现与应用
src/SelectInput/Input.tsx, src/SelectInput/Content/index.tsx
SelectContent 从上下文读取 inputProps(作为 userInputProps)并将其合并进渲染 input 所用的 props;Input 组件从 props 解构 inputProps 并将其展开到 sharedInputProps(包含克隆自定义输入组件时的 props 合并)。
测试 / 文档
tests/BaseSelect.test.tsx, README.md
新增 Jest 测试检查 inputProps(通过 spellcheck 属性)能从 BaseSelect 转发到内部 <input>;README 的 props 表格新增 inputProps 行。

Sequence Diagram(s)

sequenceDiagram
  participant BaseSelect
  participant SelectInput
  participant SelectContent
  participant Input
  participant HTMLInput
  BaseSelect->>SelectInput: 接收 props (含 inputProps)
  SelectInput->>SelectContent: 在 context 中包含 inputProps
  SelectContent->>Input: 传递 userInputProps
  Input->>Input: 合并 inputProps 到 sharedInputProps
  Input->>HTMLInput: 渲染并应用最终属性
Loading

Estimated code review effort

🎯 2 (简单) | ⏱️ ~12 分钟

Possibly related PRs

Suggested reviewers

  • zombieJ

诗歌

🐰 兔子轻跃进代码林,
为 input 带来新行李,
属性透传不再绕弯子,
文档与测试齐步行,
小改动,大欢喜 ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding an inputProps prop to allow passing props to the internal input element.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.44%. Comparing base (740b93b) to head (56e4bb0).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1221   +/-   ##
=======================================
  Coverage   99.44%   99.44%           
=======================================
  Files          31       31           
  Lines        1256     1256           
  Branches      437      459   +22     
=======================================
  Hits         1249     1249           
  Misses          7        7           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an inputProps property to allow passing standard HTML input attributes to the internal input element across BaseSelect, SelectInput, and Input components. The changes include documentation and a test case. Feedback highlights that inputProps should be destructured in SelectInput to avoid React warnings on the wrapper element, and user-provided styles or classes within inputProps should be merged rather than overwritten in the Input component.

Comment thread src/SelectInput/index.tsx
components: ComponentsConfig;
children?: React.ReactElement;
/** Props passed to the internal input element */
inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The inputProps prop added to the interface should also be destructured in the SelectInput component body (around line 76). Currently, it is not destructured, which means it remains in restProps and is subsequently included in domProps. This leads to inputProps being passed as a DOM attribute to the wrapper div element at line 261, which will trigger a React warning about unknown props on a DOM element.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经修改了,使用DEFAULT_OMIT_PROPS 排除了

Comment thread src/SelectInput/Input.tsx
Comment on lines +170 to 173
...inputProps,
ref: inputRef as React.Ref<HTMLInputElement>,
style: {
...styles?.input,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The style and className properties from inputProps are currently overwritten by the component's explicit assignments that follow the spread. To ensure user-provided styles and classes are applied, they should be merged. Note that className also needs to be merged into the inputCls definition (around line 54), though that line is outside the current diff hunk.

Suggested change
...inputProps,
ref: inputRef as React.Ref<HTMLInputElement>,
style: {
...styles?.input,
...inputProps,
ref: inputRef as React.Ref<HTMLInputElement>,
style: {
...styles?.input,
...inputProps?.style,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

暂时不考虑这个style问题,应该统一由styles处理

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/SelectInput/index.tsx (1)

55-70: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

inputProps 缺少过滤,对象值会被展开到根 <div> 上,触发 React DOM 警告

inputProps 未在组件函数体中显式解构,也未加入 DEFAULT_OMIT_PROPS,因此它会经由 domProps 最终展开到根 <div> 上。React 会在控制台输出警告:

Warning: React does not recognize the inputProps prop on a DOM element…

对比 tabIndexfocused 等同类 "仅供内部消费" 的 props,它们已加入 DEFAULT_OMIT_PROPS 以阻止 DOM 透传,inputProps 应当遵循相同模式。

inputProps 通过 contextValue = { ...props, ... } 已正确进入 SelectInputContext,功能链路本身正常,只需防止其漏出到 DOM 即可。

🐛 修复:将 `inputProps` 加入 `DEFAULT_OMIT_PROPS`
 const DEFAULT_OMIT_PROPS = [
   'value',
   'onChange',
   'removeIcon',
   'placeholder',
   'maxTagCount',
   'maxTagTextLength',
   'maxTagPlaceholder',
   'choiceTransitionName',
   'onInputKeyDown',
   'onPopupScroll',
   'tabIndex',
   'activeValue',
   'onSelectorRemove',
   'focused',
+  'inputProps',
 ] as const;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/SelectInput/index.tsx` around lines 55 - 70, DEFAULT_OMIT_PROPS currently
omits internal-only props but is missing inputProps, which causes inputProps to
be spread into domProps and onto the root <div>; add 'inputProps' to the
DEFAULT_OMIT_PROPS array so it is omitted from domProps (preventing React DOM
warnings) while leaving the code that injects inputProps into SelectInputContext
/ contextValue unchanged.
🧹 Nitpick comments (1)
src/SelectInput/Content/index.tsx (1)

24-30: ⚡ Quick win

inputProps 中的事件处理函数会被静默覆盖,类型定义过于宽泛

当前的合并顺序:

  • Content/index.tsxuserInputProps.onKeyDownonInputKeyDown 替换(而非合并),用户的 onKeyDown 直接被丢弃。
  • Input.tsxonChangeonBlur 等内部处理函数位于 ...inputProps 之后,用户通过 inputProps 传入的同名事件处理函数全部被静默忽略。

但当前类型 React.InputHTMLAttributes<HTMLInputElement> 包含完整的事件处理函数类型,用户很可能传入 onChangeonBlur 等并期望它们生效,实际上却静默无效,难以排查。

建议收窄类型,明确排除事件处理函数(React.DOMAttributes 中的内容),例如:

- inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
+ inputProps?: Omit<React.InputHTMLAttributes<HTMLInputElement>, keyof React.DOMAttributes<HTMLInputElement>>;

或在 README 和 JSDoc 中明确说明事件处理函数会被忽略。若需要合并 onKeyDown,可改为:

- onKeyDown: onInputKeyDown,
+ onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => {
+   userInputProps?.onKeyDown?.(e);
+   onInputKeyDown?.(e);
+ },
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/SelectInput/Content/index.tsx` around lines 24 - 30, The current merging
silently overwrites user event handlers: userInputProps (and final inputProps)
uses React.InputHTMLAttributes which includes DOM event handlers, so user
onChange/onBlur/onKeyDown get ignored by internal handlers in Content/index.tsx
(sharedInputProps) and Input.tsx; fix by narrowing the type used for
userInputProps/sharedInputProps to explicitly exclude DOM event handlers (e.g.
Omit<React.InputHTMLAttributes<HTMLInputElement>, keyof
React.DOMAttributes<any>>) or by whitelisting only safe attributes, and change
the onKeyDown merge in Content/index.tsx to call both handlers (invoke
userInputProps.onKeyDown if present, then onInputKeyDown, or vice versa) so user
callbacks are preserved; also update README/JSDoc to state that event handlers
are either ignored or merged based on chosen approach.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/SelectInput/index.tsx`:
- Around line 55-70: DEFAULT_OMIT_PROPS currently omits internal-only props but
is missing inputProps, which causes inputProps to be spread into domProps and
onto the root <div>; add 'inputProps' to the DEFAULT_OMIT_PROPS array so it is
omitted from domProps (preventing React DOM warnings) while leaving the code
that injects inputProps into SelectInputContext / contextValue unchanged.

---

Nitpick comments:
In `@src/SelectInput/Content/index.tsx`:
- Around line 24-30: The current merging silently overwrites user event
handlers: userInputProps (and final inputProps) uses React.InputHTMLAttributes
which includes DOM event handlers, so user onChange/onBlur/onKeyDown get ignored
by internal handlers in Content/index.tsx (sharedInputProps) and Input.tsx; fix
by narrowing the type used for userInputProps/sharedInputProps to explicitly
exclude DOM event handlers (e.g.
Omit<React.InputHTMLAttributes<HTMLInputElement>, keyof
React.DOMAttributes<any>>) or by whitelisting only safe attributes, and change
the onKeyDown merge in Content/index.tsx to call both handlers (invoke
userInputProps.onKeyDown if present, then onInputKeyDown, or vice versa) so user
callbacks are preserved; also update README/JSDoc to state that event handlers
are either ignored or merged based on chosen approach.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a88676fa-d39c-416c-af6f-ebdf9d169fe9

📥 Commits

Reviewing files that changed from the base of the PR and between 740b93b and b6cb576.

📒 Files selected for processing (6)
  • README.md
  • src/BaseSelect/index.tsx
  • src/SelectInput/Content/index.tsx
  • src/SelectInput/Input.tsx
  • src/SelectInput/index.tsx
  • tests/BaseSelect.test.tsx

Comment thread src/BaseSelect/index.tsx

// >>> Input
/** Props passed to the internal input element */
inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经有 components 可以自定义子组件,inputProps 有点多余了。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以components.input = Input 。我去回复issue吧

@EmilyyyLiu EmilyyyLiu closed this May 8, 2026
@EmilyyyLiu EmilyyyLiu deleted the feat/input-props branch May 8, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants