Skip to content

refactor(components): [notification] use type-based definitions#23445

Merged
btea merged 7 commits into
element-plus:devfrom
E66Crisp:refactor-notification
Jan 20, 2026
Merged

refactor(components): [notification] use type-based definitions#23445
btea merged 7 commits into
element-plus:devfrom
E66Crisp:refactor-notification

Conversation

@E66Crisp
Copy link
Copy Markdown
Contributor

@E66Crisp E66Crisp commented Jan 18, 2026

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

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

Summary by CodeRabbit

  • Improvements

    • Clearer, explicit typing and a unified prop surface for notifications.
    • Added explicit notification types and four corner positions (now including bottom-right).
    • Default values declared for all props and a refined default close icon for better dismissal UX.
    • Positioning/offset handling updated to support all corner positions.
    • Legacy prop alias marked as deprecated to guide migration.
  • Tests

    • Simplified tests: removed assertion of console warning for invalid icon types.

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 18, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 18, 2026

📝 Walkthrough

Walkthrough

Introduces explicit Notification prop/interface types and position literals, deprecates the legacy public prop alias, updates the Vue component to use typed props with defaults (including a default close icon), updates notify typings to use the new position type, and removes a console.warn assertion from a test.

Changes

Cohort / File(s) Summary
Type definitions
packages/components/notification/src/notification.ts
Added Component import; introduced NotificationType and NotificationPosition; added NotificationProps interface with JSDoc and defaults; added deprecation notes while preserving notificationProps and deprecated NotificationPropsPublic.
Component implementation
packages/components/notification/src/notification.vue
Switched from defineProps(notificationProps) to withDefaults(defineProps<NotificationProps>(), {...}); import NotificationProps type and notificationEmits; added default closeIcon using Close from @element-plus/icons-vue.
Runtime notify logic
packages/components/notification/src/notify.ts
Replaced NotificationOptions['position'] with NotificationPosition; typed notifications as Record<NotificationPosition, NotificationQueue>; updated close and updateOffsets signatures and included bottom-right key.
Tests
packages/components/notification/__tests__/notification.test.tsx
Removed console.warn spy/assertion related to invalid icon type; left runtime validation TODO and restored mock cleanup.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • btea
  • keeplearning66

Poem

🐰
I hopped through props and IDs tonight,
I stitched new types by soft moonlight.
Defaults tucked in a cozy row,
Close icons ready — off we go! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: refactoring the notification component to use type-based prop definitions instead of buildProps.
Description check ✅ Passed The description includes a reference to issue #23399 and confirms the repository checklist was completed, but lacks specific details about what changes were made.

✏️ 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.

@E66Crisp
Copy link
Copy Markdown
Contributor Author

Hello Reviewer, regarding the content about icon?: string | Component, is it necessary to export it as a type in packages\utils\vue\icon.ts? For example, add export type IconComponentType = string | Component in the icon.ts file.

@rzzf
Copy link
Copy Markdown
Member

rzzf commented Jan 18, 2026

Hello Reviewer, regarding the content about icon?: string | Component, is it necessary to export it as a type in packages\utils\vue\icon.ts? For example, add export type IconComponentType = string | Component in the icon.ts file.

It might be needed in the future, but I don’t think it’s necessary for now.

@rzzf rzzf marked this pull request as draft January 18, 2026 13:46
@E66Crisp
Copy link
Copy Markdown
Contributor Author

Hello Reviewer, regarding the content about icon?: string | Component, is it necessary to export it as a type in packages\utils\vue\icon.ts? For example, add export type IconComponentType = string | Component in the icon.ts file.

It might be needed in the future, but I don’t think it’s necessary for now.

Yes, refactoring the code does not include this part of the modification.

@E66Crisp
Copy link
Copy Markdown
Contributor Author

Hello Reviewer, I'm encountering a test failure after refactoring from buildProps to defineProps<NotificationProps>().

The test expects console.warn to be called for invalid prop values, but runtime validation was lost after the migration. I noticed Message component has a similar test but doesn't check for console.warn after the same migration.

Should I:

  1. Remove the console.warn expectation from the test (similar to Message), or
  2. Add manual runtime validation to preserve the developer experience?

Looking forward to your guidance. Thanks!

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 19, 2026

Open in StackBlitz

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

commit: 7212c30

@E66Crisp E66Crisp marked this pull request as ready for review January 19, 2026 01:29
@E66Crisp E66Crisp marked this pull request as draft January 19, 2026 02:50
@rzzf
Copy link
Copy Markdown
Member

rzzf commented Jan 19, 2026

  1. Remove the console.warn expectation from the test (similar to Message), or

We can first comment out the assertion instead of deleting it.

  1. Add manual runtime validation to preserve the developer experience?

See #23458

@E66Crisp
Copy link
Copy Markdown
Contributor Author

  1. Remove the console.warn expectation from the test (similar to Message), or

We can first comment out the assertion instead of deleting it.

  1. Add manual runtime validation to preserve the developer experience?

See #23458

Got it. I've commented out this section of code. tks.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 20, 2026

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

Comment thread packages/components/notification/src/notification.vue Outdated
@rzzf rzzf marked this pull request as ready for review January 20, 2026 08:57
@btea btea merged commit 77a4e31 into element-plus:dev Jan 20, 2026
16 of 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