Skip to content

Conversation

@Chang-Chen
Copy link

@Chang-Chen Chang-Chen commented Sep 16, 2025

closed #263

Summary by CodeRabbit

  • New Features

    • Sender component now accepts minlength and maxlength to constrain input length.
  • Documentation

    • Storybook updated with controls and descriptions for minlength and maxlength.
  • Refactor

    • Conditionals and early-return patterns reformatted for readability; no behavioral changes.
  • Style

    • Minor syntax/brace consolidations and formatting tweaks with no impact on functionality.

@coderabbitai
Copy link

coderabbitai bot commented Sep 16, 2025

Walkthrough

Adds two public props, minlength and maxlength, to the Sender component and its TypeScript types, exposes them in Storybook controls, and reformats internal guards/returns; no behavioral changes or new events introduced.

Changes

Cohort / File(s) Summary
Sender component (props + refactor)
packages/core/src/components/Sender/index.vue
Adds public props minlength and maxlength (default: undefined) and binds them to the underlying input. Refactors conditionals and early-returns into more compact forms; no functional changes.
Type definitions
packages/core/src/components/Sender/types.d.ts
Extends SenderProps with optional minlength?: string | number and maxlength?: string | number.
Storybook metadata
packages/core/src/stories/Sender/Sender.stories.ts
Adds minlength and maxlength to argTypes and default args (controls and defaults updated for stories).

Sequence Diagram(s):

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I’m a rabbit tapping keys so light,
Min and max now guard the write.
Types aligned and stories bright,
Small hops tidy—everything’s right. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed 标题直接反映了主要变更:为 Sender 组件新增 minlength 和 maxlength 属性;措辞有轻微重复(“增加 … 增加”),但含义明确且能让审阅者快速理解主要改动。
Linked Issues Check ✅ Passed 该 PR 在 Sender 组件、类型声明和 Storybook 中新增并绑定了 maxlength 属性,从实现层面将该属性传递给底层 el-input,从而直接满足了 Issue #263 要求的“输入最大字符数限制”;同时添加的 minlength 为向后兼容的额外属性,且摘要显示其余改动为格式化重构并未改变行为。
Out of Scope Changes Check ✅ Passed 除了新增的 minlength 和 maxlength 外,变更主要是风格性格式化与些许单行重构(如早期返回和括号紧凑化),摘要表明这些改动不影响控制流或事件发射;未发现功能性、行为性或与 #263 目标无关的新增功能。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

Copy link

@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.

Actionable comments posted: 0

Caution

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

⚠️ Outside diff range comments (1)
packages/core/src/components/Sender/index.vue (1)

430-453: Missing implementation: Props are declared but not used in the template.

The minlength and maxlength props are declared but not passed to the el-input component. These attributes should be bound to the textarea element to actually enforce the length restrictions.

Apply this diff to bind the length attributes to the input:

        <el-input
          ref="inputRef"
          v-model="internalValue"
          class="el-sender-input"
          :input-style="
            props.inputStyle || {
              resize: 'none',
              'max-height': '176px',
              'max-width': inputWidth
            }
          "
          :rows="1"
          :autosize="autoSize"
          type="textarea"
          :validate-event="false"
          :placeholder="placeholder"
+         :minlength="minlength"
+         :maxlength="maxlength"
          :read-only="readOnly || disabled"
          :disabled="disabled"
          @keydown="handleKeyDown"
          @compositionstart="handleCompositionStart"
          @compositionend="handleCompositionEnd"
          @paste="handleInternalPaste"
        />
🧹 Nitpick comments (2)
packages/core/src/components/Sender/index.vue (2)

61-61: Address ESLint formatting issues for consistency.

The code has multiple ESLint violations related to newlines after if statements and brace style. While these are minor formatting issues, they should be addressed to maintain code consistency.

Consider running eslint --fix to automatically resolve these formatting issues, or apply the suggested formatting manually:

-  if (props.readOnly || props.disabled) return;
+  if (props.readOnly || props.disabled)
+    return;

Apply similar formatting fixes to all flagged locations.

Also applies to: 91-91, 103-103, 172-172, 174-174, 179-179, 180-180, 190-190, 254-254, 259-259, 266-266


122-125: Consider consistent brace style formatting.

Multiple locations have closing braces on the same line as subsequent blocks, which violates the project's ESLint brace-style rules.

For consistency with the project's ESLint configuration, consider reformatting these else blocks:

-      } else {
+      }
+      else {

Apply similar formatting to all flagged brace style violations.

Also applies to: 136-139, 151-154, 221-224, 297-300, 318-323

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e3ce64d and 395c48a.

📒 Files selected for processing (3)
  • packages/core/src/components/Sender/index.vue (13 hunks)
  • packages/core/src/components/Sender/types.d.ts (1 hunks)
  • packages/core/src/stories/Sender/Sender.stories.ts (1 hunks)
🧰 Additional context used
🪛 ESLint
packages/core/src/components/Sender/index.vue

[error] 61-61: Expect newline after if

(antfu/if-newline)


[error] 91-91: Expect newline after if

(antfu/if-newline)


[error] 103-103: Expect newline after if

(antfu/if-newline)


[error] 122-122: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)


[error] 136-136: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)


[error] 151-151: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)


[error] 172-172: Expect newline after if

(antfu/if-newline)


[error] 174-174: Expect newline after if

(antfu/if-newline)


[error] 179-179: Expect newline after if

(antfu/if-newline)


[error] 180-180: Expect newline after if

(antfu/if-newline)


[error] 190-190: Expect newline after if

(antfu/if-newline)


[error] 221-221: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)


[error] 254-254: Expect newline after if

(antfu/if-newline)


[error] 259-259: Expect newline after if

(antfu/if-newline)


[error] 266-266: Expect newline after if

(antfu/if-newline)


[error] 297-297: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)


[error] 318-318: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)


[error] 320-320: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)

🔇 Additional comments (3)
packages/core/src/components/Sender/types.d.ts (1)

8-11: LGTM! Clean addition of native input length attributes.

The new minlength and maxlength props are correctly typed as optional string | number values, matching the native HTML input attributes. The Chinese comments provide clear context for their purpose.

packages/core/src/stories/Sender/Sender.stories.ts (1)

27-34: LGTM! Consistent Storybook integration.

The new argTypes for minlength and maxlength are properly configured with text controls and clear Chinese descriptions, making them easily testable in Storybook.

packages/core/src/components/Sender/index.vue (1)

17-18: LGTM! Props correctly declared with appropriate defaults.

The new minlength and maxlength props are properly added with undefined defaults, maintaining backward compatibility.

Copy link

@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.

Actionable comments posted: 0

Caution

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

⚠️ Outside diff range comments (1)
packages/core/src/components/Sender/index.vue (1)

445-451: Bug: wrong prop name; use :readonly, not :read-only.

This prevents the readonly state from being applied to el-input.

           :placeholder="placeholder"
-          :read-only="readOnly || disabled"
+          :readonly="readOnly || disabled"
           :disabled="disabled"
🧹 Nitpick comments (5)
packages/core/src/stories/Sender/Sender.stories.ts (2)

27-36: Add control constraints (min/step) and reconsider default max in Storybook.

  • Prevent invalid inputs by constraining the number controls.
  • Consider not enforcing a 10-char limit by default in the story to avoid implying a component default.
     minlength: {
-      defaultValue: 0,
-      control: 'number',
+      defaultValue: 0,
+      control: { type: 'number', min: 0, step: 1 },
       description: '设置输入框的最小输入长度。'
     },
     maxlength: {
-      defaultValue: 10,
-      control: 'number',
+      // Consider undefined here, so the story doesn't imply a default limit:
+      // defaultValue: undefined,
+      defaultValue: 10,
+      control: { type: 'number', min: 0, step: 1 },
       description: '设置输入框的最大输入长度。'
     },

152-153: Story defaults: avoid opinionated length limits unless intentional.

If the 10-char cap is only for demo, set to undefined in args and let users toggle via controls.

-    minlength: 0,
-    maxlength: 10,
+    minlength: 0,
+    // If only for demo, consider leaving unset to reflect component defaults:
+    // maxlength: undefined,
+    maxlength: 10,
packages/core/src/components/Sender/index.vue (3)

61-61: Fix lint errors (antfu/if-newline, brace-style) and dedupe branches.

  • Expand single-line if-returns to multi-line.
  • Split } else { onto new lines per brace-style.
  • Remove duplicated popoverVisible.value = true/false in the trigger watcher.
-    if (props.readOnly || props.disabled) return;
+    if (props.readOnly || props.disabled) {
+      return;
+    }
...
-    if (isComposing.value) return;
+    if (isComposing.value) {
+      return;
+    }
...
-      if (hasOnTriggerListener.value) {
-        emits('trigger', { ... , isOpen: true });
-        popoverVisible.value = true;
-      } else {
-        popoverVisible.value = true;
-      }
+      if (hasOnTriggerListener.value) {
+        emits('trigger', { ... , isOpen: true });
+      }
+      popoverVisible.value = true;
...
-      if (hasOnTriggerListener.value) {
-        emits('trigger', { ... , isOpen: false });
-        popoverVisible.value = false;
-      } else {
-        popoverVisible.value = false;
-      }
+      if (hasOnTriggerListener.value) {
+        emits('trigger', { ... , isOpen: false });
+      }
+      popoverVisible.value = false;
...
-      if (hasOnTriggerListener.value) {
-        emits('trigger', { ... , isOpen: true });
-        popoverVisible.value = true;
-      } else {
-        popoverVisible.value = true;
-      }
+      if (hasOnTriggerListener.value) {
+        emits('trigger', { ... , isOpen: true });
+      }
+      popoverVisible.value = true;
...
-  if (props.readOnly) return false;
+  if (props.readOnly) {
+    return false;
+  }
...
-  if (props.readOnly) return; // 直接返回,不执行后续逻辑
+  if (props.readOnly) {
+    return; // 直接返回,不执行后续逻辑
+  }

Also applies to: 91-91, 103-103, 122-123, 136-138, 151-153, 172-176, 179-181, 190-195, 221-223, 254-256, 259-262, 266-273, 297-299, 318-323, 320-323


265-300: Use modern key detection; keyCode is deprecated.

Prefer e.key === 'Enter' for key checks.

-  if (e.keyCode === 13) {
+  if (e.key === 'Enter') {
     e.preventDefault();
     if (props.submitType === 'enter') {
       _isComKeyDown ? _resetSelectionRange() : submit();
     } else {
       _isComKeyDown ? submit() : _resetSelectionRange();
     }
   }

170-181: Nit: rename visiableHeader -> visibleHeader.

Minor readability improvement.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 395c48a and 7dd5d57.

📒 Files selected for processing (2)
  • packages/core/src/components/Sender/index.vue (14 hunks)
  • packages/core/src/stories/Sender/Sender.stories.ts (2 hunks)
🧰 Additional context used
🪛 ESLint
packages/core/src/components/Sender/index.vue

[error] 61-61: Expect newline after if

(antfu/if-newline)


[error] 91-91: Expect newline after if

(antfu/if-newline)


[error] 103-103: Expect newline after if

(antfu/if-newline)


[error] 122-122: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)


[error] 136-136: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)


[error] 151-151: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)


[error] 172-172: Expect newline after if

(antfu/if-newline)


[error] 174-174: Expect newline after if

(antfu/if-newline)


[error] 179-179: Expect newline after if

(antfu/if-newline)


[error] 180-180: Expect newline after if

(antfu/if-newline)


[error] 190-190: Expect newline after if

(antfu/if-newline)


[error] 221-221: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)


[error] 254-254: Expect newline after if

(antfu/if-newline)


[error] 259-259: Expect newline after if

(antfu/if-newline)


[error] 266-266: Expect newline after if

(antfu/if-newline)


[error] 297-297: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)


[error] 318-318: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)


[error] 320-320: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)

🔇 Additional comments (3)
packages/core/src/components/Sender/index.vue (3)

17-18: LGTM: new props wired with sensible defaults.

minlength/maxlength default to undefined, matching Element Plus API types.


445-447: LGTM: passthrough of minlength/maxlength to el-input.

These props are officially supported by Element Plus Input for text/textarea and enforce native limits.

References: Element Plus Input docs list both props. (element-plus.org)


445-447: Confirm Element Plus compatibility (minlength/maxlength on textarea)

File: packages/core/src/components/Sender/index.vue Lines: 445-447

          :minlength="minlength"
          :maxlength="maxlength"
          :validate-event="false"

Script returned no output — unable to verify vendored node_modules/element-plus. Confirm Element Plus version in package.json or lockfile and that the Input/Textarea component for that version supports minlength/maxlength. Run the verification script locally and attach its output if uncertain.

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