feat(form): Add InputColor class for HTML <input type="color"> element with attributes and rendering capabilities.#53
Conversation
…ement with attributes and rendering capabilities.
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds an InputColor form component (type="color"), two attribute traits (alpha, colorspace), a Colorspace enum, changelog entry, and an extensive PHPUnit test suite validating rendering, attributes, and validation. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #53 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 158 163 +5
===========================================
Files 81 84 +3
Lines 376 387 +11
===========================================
+ Hits 376 387 +11 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (6)
CHANGELOG.mdsrc/Form/Attribute/HasAlpha.phpsrc/Form/Attribute/HasColorspace.phpsrc/Form/InputColor.phpsrc/Form/Values/Colorspace.phptests/Form/InputColorTest.php
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2026-02-06T21:37:44.509Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 24
File: tests/Form/InputTextTest.php:33-620
Timestamp: 2026-02-06T21:37:44.509Z
Learning: In the ui-awesome/html repository, prefer individual test methods over PHPUnit data providers in test classes. This helps maintainers see exactly how each test behaves without cross-referencing data providers. Apply to all PHP test files under tests. Use separate, descriptively named test methods to cover different inputs/edge cases; retain data providers only if they clearly improve readability or reduce duplication.
Applied to files:
tests/Form/InputColorTest.php
📚 Learning: 2026-02-11T14:56:18.277Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 37
File: tests/Form/InputTextTest.php:448-457
Timestamp: 2026-02-11T14:56:18.277Z
Learning: In PHP test files under the repository ui-awesome/html (e.g., tests/Form/InputTextTest.php), it is acceptable to use short variable names (e.g., 2-character names like $id). PHPMD's short-variable rule does not need to be strictly followed in test code. During reviews, allow short names in test files and note that this relaxed style applies to tests, while production code should adhere to the standard variable naming conventions.
Applied to files:
tests/Form/InputColorTest.php
📚 Learning: 2026-02-21T01:17:40.877Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 51
File: tests/List/UlTest.php:282-283
Timestamp: 2026-02-21T01:17:40.877Z
Learning: In the ui-awesome/html repository, for PHP tests, ensure that assertion messages in tests/List/UlTest.php for methods named testRenderWith*UsingEnum remain identical to the corresponding non-enum tests (i.e., do not append 'using enum' to the failure message). The reason: the underlying render method treats enum and string inputs the same, so failure output should be uniform. Apply this pattern to all similar test cases under tests/ to maintain consistent failure messages across enum vs non-enum variants.
Applied to files:
tests/Form/InputColorTest.php
🧬 Code graph analysis (2)
src/Form/InputColor.php (1)
src/Root/Html.php (1)
Html(27-40)
tests/Form/InputColorTest.php (6)
src/Root/Html.php (1)
Html(27-40)src/Form/InputColor.php (1)
InputColor(42-84)tests/Support/Stub/DefaultProvider.php (1)
DefaultProvider(17-34)tests/Support/Stub/DefaultThemeProvider.php (1)
DefaultThemeProvider(17-39)src/Form/Attribute/HasAlpha.php (1)
alpha(30-33)src/Form/Attribute/HasColorspace.php (1)
colorspace(42-47)
🪛 PHPMD (2.15.0)
src/Form/Attribute/HasColorspace.php
[error] 44-44: Avoid using static access to class '\UIAwesome\Html\Helper\Validator' in method 'colorspace'. (undefined)
(StaticAccess)
[error] 44-44: Avoid using static access to class '\UIAwesome\Html\Form\Values\Colorspace' in method 'colorspace'. (undefined)
(StaticAccess)
tests/Form/InputColorTest.php
[warning] 46-983: The class InputColorTest has 64 public methods and attributes. Consider reducing the number of public items to less than 45. (undefined)
(ExcessivePublicCount)
[warning] 46-983: The class InputColorTest has 64 non-getter- and setter-methods. Consider refactoring InputColorTest to keep number of methods under 25. (undefined)
(TooManyMethods)
[warning] 46-983: The class InputColorTest has 64 public methods. Consider refactoring InputColorTest to keep number of public methods under 10. (undefined)
(TooManyPublicMethods)
[warning] 46-983: The class InputColorTest has an overall complexity of 64 which is very high. The configured complexity threshold is 50. (undefined)
(ExcessiveClassComplexity)
[error] 46-983: The class InputColorTest has a coupling between objects value of 19. Consider to reduce the number of dependencies under 13. (undefined)
(CouplingBetweenObjects)
[warning] 590-590: Avoid variables with short names like $id. Configured minimum length is 3. (undefined)
(ShortVariable)
[error] 601-604: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 616-619: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 934-940: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)
(StaticAccess)
[error] 950-953: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)
(StaticAccess)
[error] 977-977: Avoid using static access to class '\UIAwesome\Html\Helper\Enum' in method 'testThrowInvalidArgumentExceptionForSettingColorspace'. (undefined)
(StaticAccess)
[error] 977-977: Avoid using static access to class '\UIAwesome\Html\Form\Values\Colorspace' in method 'testThrowInvalidArgumentExceptionForSettingColorspace'. (undefined)
(StaticAccess)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: phpunit / PHP 8.4-windows-2022
- GitHub Check: phpunit / PHP 8.2-ubuntu-latest
- GitHub Check: phpunit / PHP 8.5-windows-2022
- GitHub Check: phpunit / PHP 8.1-ubuntu-latest
- GitHub Check: phpunit / PHP 8.3-ubuntu-latest
- GitHub Check: linter / Super Linter
- GitHub Check: linter / Super Linter
🔇 Additional comments (5)
CHANGELOG.md (1)
40-40: LGTM!Changelog entry format, issue reference, and phrasing are consistent with all prior entries.
src/Form/Attribute/HasAlpha.php (1)
16-33: LGTM!
alphais confirmed as a valid boolean attribute for<input type="color">per MDN/WHATWG. The immutable delegation tosetAttributeis correct and consistent with the rest of the trait-based API.src/Form/Values/Colorspace.php (1)
15-26: LGTM!The two enum cases correctly reflect the only valid
colorspacevalues for<input type="color">:"limited-srgb"(the default) and"display-p3"(the Display P3 color space).src/Form/InputColor.php (1)
42-83: LGTM!The class follows the established pattern for all other
InputXxxtypes. The composed traits correctly cover all attributes valid for<input type="color">, includingalpha(boolean, controls opacity),colorspace(color space selector),autocomplete,list,form,tabindex,autofocus, andvalue.tests/Form/InputColorTest.php (1)
599-620:⚠️ Potential issue | 🟠 MajorGlobal state is leaked if assertions fail — wrap
SimpleFactorysetup/teardown intry/finally.Both
testRenderWithGlobalDefaultsAreAppliedandtestRenderWithUserOverridesGlobalDefaultscallSimpleFactory::setDefaults()and then reset it at the end. Because PHPUnit assertion failures throwAssertionFailedError, the cleanup calls (lines 616–619 and 950–953) are never reached when an assertion fails. This leavesInputColor::classwith stale global defaults, which can cause non-obvious failures in any test that runs afterward.🔒 Proposed fix — use
try/finallyin both methodspublic function testRenderWithGlobalDefaultsAreApplied(): void { SimpleFactory::setDefaults( InputColor::class, ['class' => 'default-class'], ); + try { self::assertSame( <<<HTML <input class="default-class" id="inputcolor" type="color"> HTML, InputColor::tag() ->id('inputcolor') ->render(), 'Failed asserting that global defaults are applied correctly.', ); - - SimpleFactory::setDefaults( - InputColor::class, - [], - ); + } finally { + SimpleFactory::setDefaults( + InputColor::class, + [], + ); + } }public function testRenderWithUserOverridesGlobalDefaults(): void { SimpleFactory::setDefaults( InputColor::class, [ 'class' => 'from-global', 'id' => 'id-global', ], ); + try { self::assertSame( <<<HTML <input class="from-global" id="value" type="color"> HTML, InputColor::tag(['id' => 'value'])->render(), 'Failed asserting that user-defined attributes override global defaults correctly.', ); - - SimpleFactory::setDefaults( - InputColor::class, - [], - ); + } finally { + SimpleFactory::setDefaults( + InputColor::class, + [], + ); + } }Also applies to: 932-954
⛔ Skipped due to learnings
Learnt from: terabytesoftw Repo: ui-awesome/html PR: 24 File: tests/Form/InputTextTest.php:33-620 Timestamp: 2026-02-06T21:37:51.711Z Learning: In the ui-awesome/html repository, prefer individual test methods over PHPUnit data providers in test classes. The maintainer values the ability to see exactly how each test works without needing to cross-reference data providers, even if it results in more methods.Learnt from: terabytesoftw Repo: ui-awesome/html PR: 24 File: tests/Form/InputTextTest.php:289-300 Timestamp: 2026-02-06T21:37:24.484Z Learning: In the ui-awesome/html repository, the maintainer prefers not to use defensive cleanup patterns (like try/finally) for global state in tests. Their philosophy is that if one test fails, they all fail anyway, so defensive cleanup is not necessary.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/Form/Attribute/HasColorspace.php`:
- Around line 42-47: Add an explicit null guard so null is treated as "remove
the attribute" and not passed into Validator::oneOf: in
HasColorspace::colorspace and the analogous method in HasShadowRootMode, check
if $value === null and immediately return $this->setAttribute('colorspace',
null) (or the corresponding attribute name) before calling Validator::oneOf;
only call Validator::oneOf when $value is non-null.
In `@tests/Form/InputColorTest.php`:
- Around line 970-982: Add a new unit test method testRenderWithColorspaceNull
that verifies calling colorspace('display-p3') followed by colorspace(null)
removes the attribute: create the test to assert
InputColor::tag()->colorspace('display-p3')->colorspace(null)->id('inputcolor')->render()
returns "<input id=\"inputcolor\" type=\"color\">". This exercises
HasColorspace::colorspace()’s null-path and complements
testThrowInvalidArgumentExceptionForSettingColorspace which covers invalid
values.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
tests/Form/InputColorTest.php
🧰 Additional context used
🧠 Learnings (6)
📚 Learning: 2026-02-06T21:37:44.509Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 24
File: tests/Form/InputTextTest.php:33-620
Timestamp: 2026-02-06T21:37:44.509Z
Learning: In the ui-awesome/html repository, prefer individual test methods over PHPUnit data providers in test classes. This helps maintainers see exactly how each test behaves without cross-referencing data providers. Apply to all PHP test files under tests. Use separate, descriptively named test methods to cover different inputs/edge cases; retain data providers only if they clearly improve readability or reduce duplication.
Applied to files:
tests/Form/InputColorTest.php
📚 Learning: 2026-02-21T13:17:56.866Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 53
File: src/Form/Attribute/HasColorspace.php:42-47
Timestamp: 2026-02-21T13:17:56.866Z
Learning: In the ui-awesome/html repository, `Validator::oneOf()` from the html-helper package already handles `null` values gracefully by returning early without throwing an exception. Methods that use `Validator::oneOf()` with nullable parameters do not need explicit null guards before calling the validator.
Applied to files:
tests/Form/InputColorTest.php
📚 Learning: 2026-02-07T18:51:41.006Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 31
File: src/Form/Mixin/HasLabel.php:195-195
Timestamp: 2026-02-07T18:51:41.006Z
Learning: In the ui-awesome/html repository, explicit boolean comparisons (e.g., `isset($var) === false`) are required instead of negation operators (e.g., `!isset($var)`) due to PHPStan strict rules configuration at the highest level.
Applied to files:
tests/Form/InputColorTest.php
📚 Learning: 2026-02-09T11:28:09.334Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 35
File: tests/Provider/Form/CheckedProvider.php:13-14
Timestamp: 2026-02-09T11:28:09.334Z
Learning: In the ui-awesome/html repository, using `str_replace` to adapt shared data provider HTML strings for different input types (e.g., adapting `CheckedProvider` for both `InputCheckboxTest` and `InputRadioTest` by replacing "inputcheckbox-" with "inputradio-" and "checkbox" with "radio") is acceptable and considered clear. Don't suggest refactoring such patterns to avoid string replacement.
Applied to files:
tests/Form/InputColorTest.php
📚 Learning: 2026-02-11T14:56:18.277Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 37
File: tests/Form/InputTextTest.php:448-457
Timestamp: 2026-02-11T14:56:18.277Z
Learning: In PHP test files under the repository ui-awesome/html (e.g., tests/Form/InputTextTest.php), it is acceptable to use short variable names (e.g., 2-character names like $id). PHPMD's short-variable rule does not need to be strictly followed in test code. During reviews, allow short names in test files and note that this relaxed style applies to tests, while production code should adhere to the standard variable naming conventions.
Applied to files:
tests/Form/InputColorTest.php
📚 Learning: 2026-02-21T01:17:40.877Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 51
File: tests/List/UlTest.php:282-283
Timestamp: 2026-02-21T01:17:40.877Z
Learning: In the ui-awesome/html repository, for PHP tests, ensure that assertion messages in tests/List/UlTest.php for methods named testRenderWith*UsingEnum remain identical to the corresponding non-enum tests (i.e., do not append 'using enum' to the failure message). The reason: the underlying render method treats enum and string inputs the same, so failure output should be uniform. Apply this pattern to all similar test cases under tests/ to maintain consistent failure messages across enum vs non-enum variants.
Applied to files:
tests/Form/InputColorTest.php
🧬 Code graph analysis (1)
tests/Form/InputColorTest.php (6)
src/Root/Html.php (1)
Html(27-40)src/Form/InputColor.php (1)
InputColor(42-84)tests/Support/Stub/DefaultProvider.php (1)
DefaultProvider(17-34)tests/Support/Stub/DefaultThemeProvider.php (1)
DefaultThemeProvider(17-39)src/Form/Attribute/HasAlpha.php (1)
alpha(30-33)src/Form/Attribute/HasColorspace.php (1)
colorspace(42-47)
🪛 PHPMD (2.15.0)
tests/Form/InputColorTest.php
[warning] 46-999: The class InputColorTest has 65 public methods and attributes. Consider reducing the number of public items to less than 45. (undefined)
(ExcessivePublicCount)
[warning] 46-999: The class InputColorTest has 65 non-getter- and setter-methods. Consider refactoring InputColorTest to keep number of methods under 25. (undefined)
(TooManyMethods)
[warning] 46-999: The class InputColorTest has 65 public methods. Consider refactoring InputColorTest to keep number of public methods under 10. (undefined)
(TooManyPublicMethods)
[warning] 46-999: The class InputColorTest has an overall complexity of 65 which is very high. The configured complexity threshold is 50. (undefined)
(ExcessiveClassComplexity)
[error] 46-999: The class InputColorTest has a coupling between objects value of 19. Consider to reduce the number of dependencies under 13. (undefined)
(CouplingBetweenObjects)
[warning] 590-590: Avoid variables with short names like $id. Configured minimum length is 3. (undefined)
(ShortVariable)
[error] 601-604: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 616-619: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 934-940: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)
(StaticAccess)
[error] 950-953: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)
(StaticAccess)
[error] 972-972: Avoid using static access to class '\UIAwesome\Html\Form\InputColor' in method 'testReturnNewInstanceWhenSettingAttribute'. (undefined)
(StaticAccess)
[error] 993-993: Avoid using static access to class '\UIAwesome\Html\Helper\Enum' in method 'testThrowInvalidArgumentExceptionForSettingColorspace'. (undefined)
(StaticAccess)
[error] 993-993: Avoid using static access to class '\UIAwesome\Html\Form\Values\Colorspace' in method 'testThrowInvalidArgumentExceptionForSettingColorspace'. (undefined)
(StaticAccess)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: phpunit / PHP 8.3-ubuntu-latest
- GitHub Check: phpunit / PHP 8.5-ubuntu-latest
- GitHub Check: phpunit / PHP 8.2-ubuntu-latest
- GitHub Check: phpunit / PHP 8.4-ubuntu-latest
- GitHub Check: phpunit / PHP 8.1-ubuntu-latest
- GitHub Check: mutation / PHP 8.5-ubuntu-latest
- GitHub Check: phpstan / PHP 8.5-ubuntu-latest
- GitHub Check: linter / Super Linter
- GitHub Check: easy-coding-standard / PHP 8.5-ubuntu-latest
- GitHub Check: phpunit / PHP 8.4-ubuntu-latest
- GitHub Check: linter / Super Linter
🔇 Additional comments (1)
tests/Form/InputColorTest.php (1)
599-620:⚠️ Potential issue | 🟠 Major
SimpleFactory::setDefaultscleanup is not protected bytry/finally— a failing assertion leaves global state dirty.In both
testRenderWithGlobalDefaultsAreApplied(Lines 599–620) andtestRenderWithUserOverridesGlobalDefaults(Lines 932–954),SimpleFactory::setDefaults(InputColor::class, [])is placed after the assertion. IfassertSamethrowsAssertionFailedError, execution halts and the cleanup is skipped. TheSimpleFactoryis a static registry, so any residual defaults (class => 'default-class',id => 'id-global') leak into all subsequently executed tests in the suite, causing non-deterministic failures.Wrap the assertion in a
try/finallyblock (or use atearDown()method):🛡️ Proposed fix — try/finally guard for testRenderWithGlobalDefaultsAreApplied
public function testRenderWithGlobalDefaultsAreApplied(): void { SimpleFactory::setDefaults( InputColor::class, ['class' => 'default-class'], ); + try { self::assertSame( <<<HTML <input class="default-class" id="inputcolor" type="color"> HTML, InputColor::tag() ->id('inputcolor') ->render(), 'Failed asserting that global defaults are applied correctly.', ); + } finally { SimpleFactory::setDefaults( InputColor::class, [], ); + } }Apply the same pattern to
testRenderWithUserOverridesGlobalDefaults(Lines 932–954).⛔ Skipped due to learnings
Learnt from: terabytesoftw Repo: ui-awesome/html PR: 24 File: tests/Form/InputTextTest.php:289-300 Timestamp: 2026-02-06T21:37:24.484Z Learning: In the ui-awesome/html repository, the maintainer prefers not to use defensive cleanup patterns (like try/finally) for global state in tests. Their philosophy is that if one test fails, they all fail anyway, so defensive cleanup is not necessary.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/Form/InputColorTest.php`:
- Around line 979-983: The assertion calls $inputColor->colorspace('') which
throws InvalidArgumentException because '' is not a valid Colorspace; change the
test to pass a valid value (e.g. 'display-p3') or null so colorspace(...)
returns a new instance and the assertNotSame is reached (refer to
InputColor::colorspace and HasColorspace::colorspace). Also ensure tests that
call SimpleFactory::setDefaults(...) always clean up by wrapping the
modification and assertions in try/finally blocks (or move cleanup to tearDown)
so SimpleFactory::setDefaults(InputColor::class, []) runs in the finally for
both testRenderWithGlobalDefaultsAreApplied and
testRenderWithUserOverridesGlobalDefaults.
Pull Request