Fix #279: Add support for conditional CSS classes in Html::addCssClass()#279
Merged
Conversation
Mister-42
commented
Jun 11, 2026
Contributor
| Q | A |
|---|---|
| Is bugfix? | ❌ |
| New feature? | ✔️ |
| Breaks BC? | ❌ |
| Fixed issues | #275 |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
vjik
requested changes
Jun 12, 2026
- 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
vjik
approved these changes
Jun 12, 2026
Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com>
There was a problem hiding this comment.
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.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
samdark
reviewed
Jul 6, 2026
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
approved these changes
Jul 8, 2026
Html::addCssClass()
Member
|
👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.