Skip to content

Add Menu::collapseAfter() for overflow dropdown - #141

Open
WarLikeLaux wants to merge 17 commits into
yiisoft:masterfrom
WarLikeLaux:add-menu-collapseAfter
Open

Add Menu::collapseAfter() for overflow dropdown#141
WarLikeLaux wants to merge 17 commits into
yiisoft:masterfrom
WarLikeLaux:add-menu-collapseAfter

Conversation

@WarLikeLaux

@WarLikeLaux WarLikeLaux commented Mar 24, 2026

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

What does this PR do?

Adds Menu::collapseAfter() to keep the first N visible items in place and move the rest into a "More" dropdown.

Menu::widget()
    ->collapseAfter(4)
    ->collapseLabel('More')
    ->items([...])
    ->render();

New methods: collapseAfter(?int), collapseLabel(string), and collapseDropdownDefinitions(?array). The default collapseAfter value is null, so all items stay visible. Invisible items don't count toward the threshold. The collapse dropdown reuses dropdownDefinitions() unless collapseDropdownDefinitions() is set separately.

No BC break: the new behavior is disabled by default, and existing menu output is unchanged unless collapseAfter() is set.

@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 (c3ae973) to head (93903d0).

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #141   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       327       342   +15     
===========================================
  Files              8         8           
  Lines           1038      1082   +44     
===========================================
+ Hits            1038      1082   +44     

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

Comment thread CHANGELOG.md Outdated
Comment thread src/Menu.php Outdated
Comment thread src/Menu.php Outdated
Comment thread src/Menu.php Outdated
Comment thread src/Menu.php Outdated
Comment thread src/Menu.php Outdated
Comment thread src/Menu.php Outdated
WarLikeLaux and others added 7 commits May 31, 2026 17:34
Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com>
Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com>
Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com>
Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com>
Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com>
@WarLikeLaux
WarLikeLaux requested a review from vjik May 31, 2026 11:52
Comment thread CHANGELOG.md Outdated
Comment thread src/Menu.php Outdated
Comment thread src/Menu.php Outdated
Comment thread src/Menu.php Outdated
Comment thread src/Menu.php Outdated
WarLikeLaux and others added 5 commits June 19, 2026 22:40
Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com>
Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com>
Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com>
Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com>
@WarLikeLaux
WarLikeLaux requested a review from vjik June 19, 2026 16:47
Comment thread src/Menu.php Outdated
@vjik
vjik requested a review from a team June 20, 2026 13:54
@vjik vjik added the status:code review The pull request needs review. label Jun 20, 2026
Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com>
@samdark

samdark commented Jun 30, 2026

Copy link
Copy Markdown
Member

Code review findings:

  • Bug: Collapsed item labels are normalized twice, which breaks escaping and icons. In src/Menu.php, collapsed raw items are first normalized as Menu items, then renderDropdown() sends them through Dropdown::render(), which normalizes them again. Example: Black & White renders as Black &amp;amp; White, encode => false is ignored, and icon markup renders as escaped text. Please add collapse tests for encoded labels, encode => false, and icons.

  • Contract mismatch: Menu::collapseAfter() is documented/stored as positive-int|null, but it accepts 0 and negative values without validation. Both currently collapse every item into “More”, which conflicts with the declared contract and with the existing Breadcrumbs::maxItems() validation pattern.

Checks run locally on the PR branch:

  • vendor/bin/phpunit tests/Menu/MenuTest.php --testdox passed.
  • vendor/bin/psalm --no-cache --output-format=console passed.
  • Targeted renders confirmed the double-encoding/icon regression and collapseAfter(0/-1) behavior.

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

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants