Skip to content

Conversation

SkylerXie
Copy link
Contributor

@SkylerXie SkylerXie commented Sep 1, 2025

🤔 这个 PR 的性质是?

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

🔗 相关 Issue

#697

💡 需求背景和解决方案

📝 更新日志

  • feat(input): 新增cursorColor和extra特性

  • fix(input): 修复onChange的context为空、allowInputOverMax不生效、「中文输入的时候禁止触发」不生效、clearTrigger=focus不生效问题

  • 本条 PR 不需要纳入 Changelog

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

Copy link
Contributor

github-actions bot commented Sep 1, 2025

完成

Copy link

pkg-pr-new bot commented Sep 1, 2025

Open in StackBlitz

npm i https://pkg.pr.new/tdesign-mobile-react@768

commit: c5cad24

Copy link

@Copilot 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 PR adds new features and test coverage to the Input component, addressing issue #697. The changes include new properties for cursor color and extra content, fixes to onChange event handling, improvements to input validation behavior, and comprehensive test cases.

  • Adds cursorColor and extra properties to the Input component
  • Fixes onChange context and trigger type issues, adding 'blur' trigger support
  • Improves input validation behavior for allowInputOverMax and composition input handling
  • Adds comprehensive test coverage for the Input component

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/input/type.ts Adds cursorColor and extra property definitions, updates onChange trigger types
src/input/input.md Updates documentation for new properties and onChange trigger types
src/input/input.en-US.md Updates English documentation for new properties and onChange trigger types
src/input/defaultProps.ts Adds default value for cursorColor property
src/input/tests/input.test.tsx Adds comprehensive test suite covering all Input component functionality
src/input/Input.tsx Implements new features, fixes input handling logic, and improves event management
src/_util/useDefault.ts Extends hook to return additional update function for internal state management
site/test-coverage.js Updates test coverage metrics for Input component
Comments suppressed due to low confidence (1)

src/input/Input.tsx:1

  • The maxLength attribute has been removed but the logic that calculates resultMaxLength is still present in the component. This creates a disconnect between the UI constraint and the component's internal validation logic, potentially causing inconsistent behavior.
import type { ChangeEvent, CompositionEvent, CSSProperties, FocusEvent, FormEvent, TouchEvent } from 'react';

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 145 to 146
if (nativeEvent.isComposing || nativeEvent.inputType === 'insertCompositionText') {
updateValue(finalValue);
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

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

During composition input, updateValue(finalValue) is called but onChange is not triggered. This creates inconsistency where the internal state updates but parent components don't receive the change notification, potentially causing state synchronization issues.

Suggested change
if (nativeEvent.isComposing || nativeEvent.inputType === 'insertCompositionText') {
updateValue(finalValue);
setInnerValue(finalValue, { e, trigger: 'input' });

Copilot uses AI. Check for mistakes.


const [showClear, setShowClear] = useState<boolean>(false);
const [innerValue, setInnerValue] = useDefault(value, defaultValue, onChange);
const [innerValue, setInnerValue, updateValue] = useDefault(value, defaultValue, onChange);
Copy link
Collaborator

Choose a reason for hiding this comment

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

受控逻辑直接换用 useControlled,与 pc 端保持一致,其他组件也会切换过去

@SkylerXie SkylerXie force-pushed the add-input-test branch 3 times, most recently from 5a4c14a to 00197c4 Compare September 4, 2025 06:52
@SkylerXie
Copy link
Contributor Author

/update-common

1 similar comment
@novlan1
Copy link
Collaborator

novlan1 commented Sep 5, 2025

/update-common

@anlyyao
Copy link
Collaborator

anlyyao commented Sep 5, 2025

/update-snapshot

Copy link
Contributor

github-actions bot commented Sep 5, 2025

⏳ 正在运行快照更新。。。 CI: Open

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.

3 participants