Skip to content

refactor(components): [autocomplete] use type-based definitions#23410

Merged
btea merged 8 commits into
element-plus:devfrom
E66Crisp:refactor-autocomplete
Jan 18, 2026
Merged

refactor(components): [autocomplete] use type-based definitions#23410
btea merged 8 commits into
element-plus:devfrom
E66Crisp:refactor-autocomplete

Conversation

@E66Crisp
Copy link
Copy Markdown
Contributor

@E66Crisp E66Crisp commented Jan 17, 2026

Please make sure these boxes are checked before submitting your PR, thank you!

  • Make sure you follow contributing guide English | (中文 | Español | Français).
  • Make sure you are merging your commits to dev branch.
  • Add some descriptions and refer to relative issues for your PR.

rel #23399

Summary by CodeRabbit

  • New Features

    • Enhanced Autocomplete: placement options, debounce, improved suggestion handling, defaulted fetch behavior, popup styling, focus/select controls, and loop navigation.
  • Refactor

    • Prop surface modernized and expanded for Autocomplete; legacy public prop types marked deprecated for compatibility.
  • Chores

    • Added shared input defaults to unify input component behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 17, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 17, 2026

📝 Walkthrough

Walkthrough

Refactors Autocomplete and Input public prop APIs: introduces AutocompletePlacement and AutocompleteProps, exports shared inputPropsDefaults, switches components to defineProps<...>() with withDefaults, sets new defaults (e.g., fetchSuggestions NOOP), and marks legacy public prop aliases as deprecated. (47 words)

Changes

Cohort / File(s) Summary
Autocomplete Types
packages/components/autocomplete/src/autocomplete.ts
Adds AutocompletePlacement union and AutocompleteProps interface (extends InputProps) with many new fields (valueKey, modelValue, debounce, placement, fetchSuggestions, popperClass, popperStyle, triggerOnFocus, selectWhenUnmatched, hideLoading, teleported, appendTo, highlightFirstItem, fitInputWidth, loopNavigation); introduces deprecation comments for legacy public alias and switches public-type composition imports.
Autocomplete Component
packages/components/autocomplete/src/autocomplete.vue
Replaces defineProps(autocompleteProps) with defineProps<AutocompleteProps>() + withDefaults(...); adds NOOP default for fetchSuggestions and supplies several new defaulted props (valueKey, modelValue, debounce, placement, triggerOnFocus, loopNavigation, teleported).
Input Defaults Export
packages/components/input/src/input.ts
Adds exported inputPropsDefaults constant (as const) containing canonical default values for InputProps (uses markRaw(CircleClose) for clearIcon).
Input Component
packages/components/input/src/input.vue
Replaces inline prop defaults with spread ...inputPropsDefaults in withDefaults(defineProps<InputProps>(), ...); updates imports to consume inputPropsDefaults.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • rzzf
  • keeplearning66
  • btea

Poem

🐇 I hopped through lines of code tonight,
Swapped old props for typed delight.
Defaults in baskets, tidy and bright,
Autocomplete hums, Input feels light.
A tiny rabbit claps—what a sight!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: refactoring the autocomplete component to use type-based definitions instead of build-time prop definitions.
Description check ✅ Passed The PR description confirms all required checklist items are completed: following contributing guide, merging to dev branch, and providing descriptions with issue reference (#23399).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 17, 2026

Open in StackBlitz

pnpm add https://pkg.pr.new/element-plus/element-plus@23410
npm i https://pkg.pr.new/element-plus/element-plus@23410
yarn add https://pkg.pr.new/element-plus/[email protected]

commit: e59507f

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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/components/autocomplete/src/autocomplete.ts`:
- Around line 35-104: The AutocompleteProps interface narrows modelValue to
string | number which conflicts with InputProps (allowing null/undefined) and
breaks consumers/tests; update AutocompleteProps to inherit the same modelValue
type as InputProps (do not re-declare or, if re-declaring, use
InputProps['modelValue']) so modelValue remains nullable/optional; locate the
modelValue declaration in AutocompleteProps and replace the narrowed type with
the original InputProps type (or remove the override) to match the
implementation that already handles null via the ?? '' usage.

Comment thread packages/components/autocomplete/src/autocomplete.ts
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 17, 2026

🧪 Playground Preview: https://element-plus.run/?pr=23410
Please comment the example via this playground if needed.

@E66Crisp E66Crisp changed the title refactor(components): [autocomplete] use type-based definitions refactor(components): [autocomplete/avatar] use type-based definitions Jan 17, 2026
Comment thread packages/components/avatar/src/avatar.vue Outdated
Comment thread packages/components/avatar/src/avatar-group.tsx Outdated
@E66Crisp E66Crisp changed the title refactor(components): [autocomplete/avatar] use type-based definitions refactor(components): [autocomplete] use type-based definitions Jan 17, 2026
@E66Crisp E66Crisp requested a review from rzzf January 17, 2026 14:29
@E66Crisp
Copy link
Copy Markdown
Contributor Author

E66Crisp commented Jan 17, 2026

Hello @rzzf , the refactoring of the avatar component will not be included in this PR, as this component overall involves the use of defineComponent. I'm not sure if this type of modification is reasonable. Thank you for your review.

Comment thread packages/components/autocomplete/src/autocomplete.vue
Copy link
Copy Markdown
Member

@rzzf rzzf left a comment

Choose a reason for hiding this comment

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

Thank you for your quick response.

Comment thread packages/components/input/src/input.vue Outdated
@E66Crisp E66Crisp requested a review from rzzf January 17, 2026 15:41
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.

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/components/input/src/input.vue (1)

205-219: Missing default values in inputPropsDefaults — this will cause regressions.

The inputPropsDefaults export is incomplete. It omits several defaults from the original inline configuration, most notably autosize: false. When input.vue spreads inputPropsDefaults into withDefaults(), these properties will lose their default values:

  • autosize: false (behavioral default — important)
  • containerRole: undefined
  • inputmode: undefined
  • id: undefined

Add these missing defaults to inputPropsDefaults before the refactoring can be merged.

Comment thread packages/components/input/src/input.ts Outdated
@E66Crisp E66Crisp requested a review from rzzf January 17, 2026 16:10
rzzf

This comment was marked as outdated.

Copy link
Copy Markdown
Member

@rzzf rzzf left a comment

Choose a reason for hiding this comment

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

Thanks for all the back-and-forth

@E66Crisp
Copy link
Copy Markdown
Contributor Author

Thanks for all the back-and-forth感谢大家的来回交流

Happy to contribute

@btea btea merged commit 3ef8bbb into element-plus:dev Jan 18, 2026
17 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

@E66Crisp Thanks for your contribution! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants