Skip to content

feat(components): [popover] expose hide() through slot#23694

Merged
btea merged 6 commits into
element-plus:devfrom
ZacharyBear:popover-slot-hide
Mar 6, 2026
Merged

feat(components): [popover] expose hide() through slot#23694
btea merged 6 commits into
element-plus:devfrom
ZacharyBear:popover-slot-hide

Conversation

@ZacharyBear
Copy link
Copy Markdown
Contributor

@ZacharyBear ZacharyBear commented Feb 27, 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.

close #23690

Summary by CodeRabbit

  • New Features

    • The Popover's default slot now exposes a hide function, allowing custom slot content to close the popover programmatically.
  • Documentation

    • Popover docs updated: Slots table adds a Type column and clarifies the default slot description to reflect the exposed slot properties.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 27, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 27, 2026

📝 Walkthrough

Walkthrough

Popover's default slot now exposes a hide scoped prop; documentation adds a "Type" column and updates the default slot's description and type metadata.

Changes

Cohort / File(s) Summary
Documentation
docs/en-US/component/popover.md
Adds a "Type" column to the slots table; updates the default slot description to note it can receive hide (version ^2.13.4 and later) and sets the slot type to ^[object]{hide: () => void}; reference slot Type set to -`.
Component Implementation
packages/components/popover/src/popover.vue
Exposes internal hide function to slot consumers by changing <slot> to <slot :hide="hide">, making hide available as a slot-scoped prop.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • btea

Poem

🐇 I found a secret, soft and sly,
A little hide to give a try,
I slipped it through the slot's sweet seam,
A rabbit's hush, a tiny dream. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: exposing the hide() method through the popover slot, matching the code modifications in both the Vue template and documentation.
Description check ✅ Passed The description includes all required template checklist items checked and references the related issue (#23690), though it lacks additional context about the implementation details.
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 unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

@github-actions github-actions Bot added the CommitMessage::Unqualified Unqualified commit message label Feb 27, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 27, 2026

Open in StackBlitz

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

commit: 71e28a7

@ZacharyBear ZacharyBear changed the title Popover slot hide feat(components): [popover] expose hide() through slot Feb 27, 2026
@github-actions github-actions Bot removed the CommitMessage::Unqualified Unqualified commit message label Feb 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 27, 2026

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

Comment thread docs/en-US/component/popover.md Outdated
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.

🧹 Nitpick comments (1)
docs/en-US/component/popover.md (1)

111-111: Clarify the slot description wording.

The phrase "can receive the hide parameter" is imprecise. The slot doesn't receive a parameter—it exposes a scoped slot prop. Consider revising for clarity:

📝 Suggested wording improvement
-| default   | content of popover, version ^(2.13.3) and later can receive the hide parameter. | ^[object]`{hide: () => void}` |
+| default   | content of popover, version ^(2.13.3) and later exposes a hide function via scoped slot. | ^[object]`{hide: () => void}` |

Alternatively:

-| default   | content of popover, version ^(2.13.3) and later can receive the hide parameter. | ^[object]`{hide: () => void}` |
+| default   | content of popover, version ^(2.13.3) and later provides access to the hide function. | ^[object]`{hide: () => void}` |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/en-US/component/popover.md` at line 111, Update the slot description row
for the "default" slot in popover docs: replace the phrase "can receive the hide
parameter" with clearer wording that it "exposes a scoped slot prop `hide`
(function)". Reference the "default" slot and the scoped slot prop name "hide"
so readers understand it's a provided prop rather than an input parameter.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@docs/en-US/component/popover.md`:
- Line 111: Update the slot description row for the "default" slot in popover
docs: replace the phrase "can receive the hide parameter" with clearer wording
that it "exposes a scoped slot prop `hide` (function)". Reference the "default"
slot and the scoped slot prop name "hide" so readers understand it's a provided
prop rather than an input parameter.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 265dde5 and b859cd2.

📒 Files selected for processing (1)
  • docs/en-US/component/popover.md

@ZacharyBear
Copy link
Copy Markdown
Contributor Author

Shall I add a test case to this slot

@btea
Copy link
Copy Markdown
Member

btea commented Feb 27, 2026

That would be better.

Copy link
Copy Markdown
Member

@keeplearning66 keeplearning66 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 contribution! Based on the description in #23690, would directly using Popconfirm meet your needs?

@ZacharyBear
Copy link
Copy Markdown
Contributor Author

ZacharyBear commented Feb 28, 2026

Thank you for your contribution! Based on the description in #23690, would directly using Popconfirm meet your needs?

image

I think popconfirm couldn't achieve my needs, it does provided cancel() and confirm() prop to actions slot, but I can't write the content in , I must to write vnode and pass it into title prop.

Another reason to choose [popover] is that it offers more APIs.

@keeplearning66
Copy link
Copy Markdown
Member

keeplearning66 commented Mar 4, 2026

I think popconfirm couldn't achieve my needs, it does provided cancel() and confirm() prop to actions slot, but I can't write the content in , I must to write vnode and pass it into title prop.

Do you mean you want to have both title and content at the same time? The title prop only supports string type.

Another reason to choose [popover] is that it offers more APIs.

Actually, some props in Popconfirm can be referenced from Popover.

00D2D8A4-E657-49ec-B14D-009A67A3AF01

@ZacharyBear
Copy link
Copy Markdown
Contributor Author

I think popconfirm couldn't achieve my needs, it does provided cancel() and confirm() prop to actions slot, but I can't write the content in , I must to write vnode and pass it into title prop.

Do you mean you want to have both title and content at the same time?

Another reason to choose [popover] is that it offers more APIs.

Actually, some props in Popconfirm can be referenced from Popover.

00D2D8A4-E657-49ec-B14D-009A67A3AF01

In this sample, popover is singleton and controlled by the visible prop.

In my situation, popover has been multiple duplicate rendered in a list. Using the ref value to controll their visibility will increase the logic complixety: each popover needs a value to control visibility. Or I have to package the Popover into a single component.

I just want to hide popover from inside, by adding this context prop to default slot is greatly helpful. And I believe it could be used in more situation.

@keeplearning66
Copy link
Copy Markdown
Member

I think popconfirm couldn't achieve my needs, it does provided cancel() and confirm() prop to actions slot, but I can't write the content in , I must to write vnode and pass it into title prop.

Do you mean you want to have both title and content at the same time? The title prop only supports string type.

Thank you for your explanation. I just feel that the behavior of 'manually closing the popup through a button inside the popup' is more in line with Popconfirm. So based on my previous comment, I would like to confirm whether the existing Popconfirm truly cannot meet your needs. If it indeed cannot, then we can consider extending the component's functionality. 😃

@ZacharyBear
Copy link
Copy Markdown
Contributor Author

I think popconfirm couldn't achieve my needs, it does provided cancel() and confirm() prop to actions slot, but I can't write the content in , I must to write vnode and pass it into title prop.

Do you mean you want to have both title and content at the same time? The title prop only supports string type.

Thank you for your explanation. I just feel that the behavior of 'manually closing the popup through a button inside the popup' is more in line with Popconfirm. So based on my previous comment, I would like to confirm whether the existing Popconfirm truly cannot meet your needs. If it indeed cannot, then we can consider extending the component's functionality. 😃

Here is my use-case, here is my ui looks like:
image

I'm implement custom [color-picker] by [color-picker-panel] and [popover]. For saving spaces, I put close button into footer slot of [color-picker-panel], neitherfooter slot of [popconfirm], it occupies a whole line.

If use [popconfirm] the close button have to be moved to footer of [popconfirm].

Copy link
Copy Markdown
Member

@keeplearning66 keeplearning66 left a comment

Choose a reason for hiding this comment

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

Okay, thank you for your patient explanation. Just need to update the version number.

Comment thread docs/en-US/component/popover.md Outdated
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.

🧹 Nitpick comments (1)
docs/en-US/component/popover.md (1)

109-112: Documentation accurately reflects the slot API changes.

The Type column addition and slot documentation are correct. The type signature {hide: () => void} matches the implementation, and version 2.13.4 aligns with the previous review discussion.

Optional: Minor wording refinement for clarity

Consider adding backticks around hide in the description for consistency with documentation conventions:

-| default   | content of popover, version ^(2.13.4) and later can receive the hide parameter. | ^[object]`{hide: () => void}` |
+| default   | content of popover, version ^(2.13.4) and later can receive the `hide` parameter. | ^[object]`{hide: () => void}` |

Alternatively, for even more precision, you could rephrase to:

-| default   | content of popover, version ^(2.13.4) and later can receive the hide parameter. | ^[object]`{hide: () => void}` |
+| default   | content of popover, version ^(2.13.4) and later exposes a `hide` function in the slot scope. | ^[object]`{hide: () => void}` |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/en-US/component/popover.md` around lines 109 - 112, Update the
documentation table row for the "default" slot so the description uses backticks
around the hide parameter (e.g., change "hide parameter" to "`hide` parameter")
and ensure the Type column remains `^[object]`{hide: () => void}` to match the
implementation and version note; edit the "default" row string in
docs/en-US/component/popover.md where the slot is defined to apply this wording
change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@docs/en-US/component/popover.md`:
- Around line 109-112: Update the documentation table row for the "default" slot
so the description uses backticks around the hide parameter (e.g., change "hide
parameter" to "`hide` parameter") and ensure the Type column remains
`^[object]`{hide: () => void}` to match the implementation and version note;
edit the "default" row string in docs/en-US/component/popover.md where the slot
is defined to apply this wording change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f2e61976-3e8f-45e9-bcce-eac427c1d525

📥 Commits

Reviewing files that changed from the base of the PR and between b859cd2 and 68ca5b8.

📒 Files selected for processing (1)
  • docs/en-US/component/popover.md

Copy link
Copy Markdown
Member

@keeplearning66 keeplearning66 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!

@btea btea merged commit ada3b2a into element-plus:dev Mar 6, 2026
15 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 6, 2026

@ZacharyBear Thanks for your contribution! ❤️

@ZacharyBear ZacharyBear deleted the popover-slot-hide branch March 6, 2026 09:03
@element-bot element-bot mentioned this pull request Mar 6, 2026
3 tasks
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