Skip to content

Fix #279: Add support for conditional CSS classes in Html::addCssClass()#279

Merged
samdark merged 8 commits into
yiisoft:masterfrom
va108:cssclasses
Jul 8, 2026
Merged

Fix #279: Add support for conditional CSS classes in Html::addCssClass()#279
samdark merged 8 commits into
yiisoft:masterfrom
va108:cssclasses

Conversation

@Mister-42

Copy link
Copy Markdown
Contributor
Q A
Is bugfix?
New feature? ✔️
Breaks BC?
Fixed issues #275

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #279   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity      1062      1067    +5     
===========================================
  Files            138       138           
  Lines           2757      2763    +6     
===========================================
+ Hits            2757      2763    +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.

Comment thread src/Html.php Outdated
Comment thread src/Html.php
Comment thread src/Html.php
Comment thread tests/HtmlTest.php Outdated
- Improve type annotation instead of psalm suppression
- Move is_bool check before BackedEnum handling
- Add phpdoc about conditional boolean behavior
- Add conditional CSS test cases to dataAddCssClass data provider
- Remove separate testAddCssClassConditional test
Comment thread src/Html.php Outdated
@vjik vjik requested review from a team and Copilot June 12, 2026 10:22
@vjik vjik added the status:code review The pull request needs review. label Jun 12, 2026
Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds support for conditionally adding CSS classes via Html::addCssClass() by allowing boolean values in the array form, so class keys can be included/excluded based on truthiness (as requested in #275).

Changes:

  • Extend Html::addCssClass() to treat ['class-name' => true/false] as conditional class inclusion.
  • Add/extend test coverage in HtmlTest::dataAddCssClass() for conditional-class scenarios.
  • Document the new feature in the changelog and update the method PHPDoc/Psalm typing.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Html.php Adds boolean-aware filtering when $class is an array; updates docblock/Psalm type.
tests/HtmlTest.php Adds data provider cases covering conditional class inclusion/exclusion.
CHANGELOG.md Notes the new conditional CSS class support for the upcoming release.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Html.php Outdated
Comment thread tests/HtmlTest.php Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread src/Html.php
Mister-42 and others added 3 commits July 6, 2026 14:00
Html::addCssClass() could silently drop a true conditional class when a
later plain (integer-keyed) class landed on the same auto-assigned key,
e.g. Html::addCssClass($a, ['active' => true, 'btn']) previously kept
only 'btn'. Append colliding integer-keyed entries instead of
overwriting.
@samdark samdark changed the title Add support for conditional CSS classes in Html::addCssClass() Fix #279: Add support for conditional CSS classes in Html::addCssClass() Jul 8, 2026
@samdark samdark merged commit 1e4714d into yiisoft:master Jul 8, 2026
23 checks passed
@samdark

samdark commented Jul 8, 2026

Copy link
Copy Markdown
Member

👍

@Mister-42 Mister-42 deleted the cssclasses branch July 8, 2026 08:35
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.

4 participants