Skip to content

Add toggleContent() method to Dropdown - #153

Open
WarLikeLaux wants to merge 6 commits into
yiisoft:masterfrom
WarLikeLaux:add-toggle-content
Open

Add toggleContent() method to Dropdown#153
WarLikeLaux wants to merge 6 commits into
yiisoft:masterfrom
WarLikeLaux:add-toggle-content

Conversation

@WarLikeLaux

Copy link
Copy Markdown
Contributor
Q A
Is bugfix?
New feature? ✔️
Docs added?
Tests added? ✔️
Breaks BC?

What does this PR do?

Adds toggleContent(string|Stringable $value) method to Dropdown that sets custom content for the toggle button instead of using the item label.

Use cases

When the dropdown toggle should display something other than plain text - an icon, avatar image, or any Stringable widget:

// Icon toggle
Dropdown::widget()
    ->toggleContent((new Span())->content('🔔'))
    ->toggleAttributes(['class' => 'btn btn-light', 'data-bs-toggle' => 'dropdown'])
    ->items([...])

// Plain text override
Dropdown::widget()
    ->toggleContent('Menu')
    ->items([...])

Without toggleContent(), the toggle button renders the item's label as before.

No BC break: new optional method, existing code unaffected.

@codecov

codecov Bot commented Mar 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (fe1a223) to head (6182334).

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #153   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       327       329    +2     
===========================================
  Files              8         8           
  Lines           1038      1044    +6     
===========================================
+ Hits            1038      1044    +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samdark
samdark requested a review from vjik March 25, 2026 20:12
@vjik

vjik commented Jun 17, 2026

Copy link
Copy Markdown
Member

@WarLikeLaux resolve conflicts, please

@vjik vjik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about adding support Stringable objects to label and respect NoEncodeInterface?

Seems, it resolves task without adding new methods.

@samdark

samdark commented Jul 2, 2026

Copy link
Copy Markdown
Member

@WarLikeLaux added a test for label leaks. Please ensure the case is handled properly.

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