Skip to content

Comments

feat: number input#81

Open
weinibuliu wants to merge 1 commit intoMistEO:mainfrom
weinibuliu:feat/input/number
Open

feat: number input#81
weinibuliu wants to merge 1 commit intoMistEO:mainfrom
weinibuliu:feat/input/number

Conversation

@weinibuliu
Copy link
Contributor

@weinibuliu weinibuliu commented Feb 21, 2026

Summary by Sourcery

为共享的 TextInput 组件添加仅限整数验证的数值输入支持,并将其接入用于整数类型流水线字段的选项编辑器。

New Features:

  • 允许将 TextInput 配置为带有 inputModestep 属性的数字字段。
  • 在 TextInput 中引入仅限整数的输入处理逻辑,用于规范化并限制用户输入为有效的整数值。
  • 在选项编辑器 UI 中,对整数类型的流水线选项使用数值型 TextInput 配置。
Original summary in English

Summary by Sourcery

Add support for numeric inputs with integer-only validation to the shared TextInput component and wire it into the option editor for integer pipeline fields.

New Features:

  • Allow TextInput to be configured as a number field with inputMode and step attributes.
  • Introduce integer-only input handling that normalizes and restricts user input to valid integer values in TextInput.
  • Use the numeric TextInput configuration for integer-typed pipeline options in the option editor UI.

Copilot AI review requested due to automatic review settings February 21, 2026 12:26
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - 我在这里给出了一些整体性的反馈:

  • TextInput 中的 integerOnly 分支会在每次变更时重写整个字符串,这对用户来说可能会有些突兀(光标跳动、粘贴时出现意料之外的转换);建议将校验/规范化逻辑放到 onBlur 中,或使用一个辅助函数,在字符串实际无效之前尽量避免修改它。
  • type='number'integerOnly 为 true 时,组件仍然允许像 '-''' 这样的过渡状态值,这些值无法很好地映射到原生 number 输入类型上,可能会导致一些奇怪的浏览器行为;在这种场景下,将 type 保持为 'text' 并使用 inputMode='numeric' 可能更安全,只在使用方层面再将其转换为数字。
给 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- The `integerOnly` branch in `TextInput` rewrites the entire string on every change, which can be jarring for users (caret jumps, unexpected transformations on paste); consider delegating validation/normalization to `onBlur` or a helper that avoids changing the string unless actually invalid.
- When `type='number'` and `integerOnly` is true, the component still allows transient values like `'-'` or `''`, which don’t map cleanly to native number inputs and may cause odd browser behavior; it may be safer to keep `type='text'` with `inputMode='numeric'` for this path and only coerce to a number at the consumer level.

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,请考虑分享一下 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码评审。
Original comment in English

Hey - I've left some high level feedback:

  • The integerOnly branch in TextInput rewrites the entire string on every change, which can be jarring for users (caret jumps, unexpected transformations on paste); consider delegating validation/normalization to onBlur or a helper that avoids changing the string unless actually invalid.
  • When type='number' and integerOnly is true, the component still allows transient values like '-' or '', which don’t map cleanly to native number inputs and may cause odd browser behavior; it may be safer to keep type='text' with inputMode='numeric' for this path and only coerce to a number at the consumer level.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `integerOnly` branch in `TextInput` rewrites the entire string on every change, which can be jarring for users (caret jumps, unexpected transformations on paste); consider delegating validation/normalization to `onBlur` or a helper that avoids changing the string unless actually invalid.
- When `type='number'` and `integerOnly` is true, the component still allows transient values like `'-'` or `''`, which don’t map cleanly to native number inputs and may cause odd browser behavior; it may be safer to keep `type='text'` with `inputMode='numeric'` for this path and only coerce to a number at the consumer level.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds number input support for integer pipeline types in the option editor. The implementation allows users to input integer values with proper validation and mobile-optimized keyboard layouts.

Changes:

  • Enhanced TextInput component with number input support including integer-only validation that strips non-numeric characters except minus signs
  • Configured OptionEditor to automatically use number input mode for inputs with pipeline_type: 'int'
  • Added interface.json to .gitignore to exclude generated MaaFramework interface files

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/components/FormControls.tsx Added type, inputMode, step, and integerOnly props to TextInput component with custom onChange handler for integer validation
src/components/OptionEditor.tsx Conditionally passes number input props to TextInput when pipeline_type === 'int'
.gitignore Excludes generated interface.json file from version control

Comment on lines +102 to +105
if (raw === '' || raw === '-') {
onChange(raw);
return;
}
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

The integer input validation allows the user to enter just a minus sign ("-"), which will be passed to the pipeline override generation. In pipelineOverride.ts line 69, when inputVal is "-", the expression inputVal || '0' evaluates to "-" (since it's truthy), resulting in invalid JSON when injected into the pipeline override. Consider changing the early return condition to only allow empty string, or parse and validate the value before allowing it through. For example: if (raw === '') { onChange(raw); return; } and handle the minus sign case by preventing it or treating it as '0' or '-0'.

Suggested change
if (raw === '' || raw === '-') {
onChange(raw);
return;
}
if (raw === '') {
onChange(raw);
return;
}
if (raw === '-') {
// Prevent a bare minus sign from being stored as the value.
// This avoids propagating "-" into downstream JSON generation.
return;
}

Copilot uses AI. Check for mistakes.
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.

1 participant