Skip to content

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

Open
Mister-42 wants to merge 5 commits into
yiisoft:masterfrom
va108:cssclasses
Open

Add support for conditional CSS classes in Html::addCssClass()#279
Mister-42 wants to merge 5 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 (9a710a2) to head (95c6230).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #279   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       837       840    +3     
===========================================
  Files             91        91           
  Lines           2265      2269    +4     
===========================================
+ Hits            2265      2269    +4     

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