Skip to content

Commit 7a97e11

Browse files
fix(attribute): Better naming prefix CanBe for boolean attributes. (#85)
1 parent 62d9d86 commit 7a97e11

22 files changed

+89
-63
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
- Bug #82: Update `ui-awesome/html-helper` requirement to use stable version constraint `^0.7` in `composer.json` (@terabytesoftw)
5656
- Enh #83: Enhance `HasAria`, `HasData`, and `HasEvents` traits to support prefix attributes `aria-`, `data-`, and `on` (@terabytesoftw)
5757
- Bug #84: Refactor attribute documentation in traits (@terabytesoftw)
58+
- Bug #85: Bug `#85`: Rename boolean attribute traits from `Has*` prefix to improve naming clarity (@terabytesoftw)
5859

5960
## 0.5.2 January 29, 2026
6061

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
* @copyright Copyright (C) 2026 Terabytesoftw.
1616
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
1717
*/
18-
trait HasDisabled
18+
trait CanBeDisabled
1919
{
2020
/**
2121
* Sets the `disabled` attribute.
2222
*
2323
* Usage example:
2424
* ```php
2525
* $element->disabled(true);
26-
* $element->disabled(false);
2726
* $element->disabled(null);
2827
* ```
2928
*
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
* @copyright Copyright (C) 2026 Terabytesoftw.
1616
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
1717
*/
18-
trait HasChecked
18+
trait CanBeChecked
1919
{
2020
/**
2121
* Sets the `checked` attribute.
2222
*
2323
* Usage example:
2424
* ```php
2525
* $element->checked(true);
26-
* $element->checked(false);
2726
* $element->checked(null);
2827
* ```
2928
*
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
* @copyright Copyright (C) 2026 Terabytesoftw.
1616
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
1717
*/
18-
trait HasMultiple
18+
trait CanBeMultiple
1919
{
2020
/**
2121
* Sets the `multiple` attribute.
2222
*
2323
* Usage example:
2424
* ```php
2525
* $element->multiple(true);
26-
* $element->multiple(false);
2726
* $element->multiple(null);
2827
* ```
2928
*
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
* @copyright Copyright (C) 2026 Terabytesoftw.
1616
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
1717
*/
18-
trait HasReadonly
18+
trait CanBeReadonly
1919
{
2020
/**
2121
* Sets the `readonly` attribute.
2222
*
2323
* Usage example:
2424
* ```php
2525
* $element->readonly(true);
26-
* $element->readonly(false);
2726
* $element->readonly(null);
2827
* ```
2928
*
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
* @copyright Copyright (C) 2026 Terabytesoftw.
1616
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
1717
*/
18-
trait HasRequired
18+
trait CanBeRequired
1919
{
2020
/**
2121
* Sets the `required` attribute.
2222
*
2323
* Usage example:
2424
* ```php
2525
* $element->required(true);
26-
* $element->required(false);
2726
* $element->required(null);
2827
* ```
2928
*

src/Global/CanBeAutofocus.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ trait CanBeAutofocus
2525
* $element->autofocus(true);
2626
* ```
2727
*
28-
* @param bool $value Whether to enable autofocus. Use `true` to enable and `false` to disable.
28+
* @param bool|null $value Whether to enable autofocus. Use `true` to enable, `false` to disable, or `null` to
29+
* remove the attribute.
2930
*
3031
* @return static New instance with the updated `autofocus` attribute.
3132
*/
32-
public function autofocus(bool $value): static
33+
public function autofocus(bool|null $value): static
3334
{
3435
return $this->setAttribute(GlobalAttribute::AUTOFOCUS, $value);
3536
}

src/Global/CanBeHidden.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ trait CanBeHidden
2626
* $element->hidden(false);
2727
* ```
2828
*
29-
* @param bool $value Whether to hide the element. Use `true` to hide and `false` to show.
29+
* @param bool|null $value Whether to hide the element. Use `true` to hide, `false` to show, or `null` to remove the
30+
* attribute.
3031
*
3132
* @return static New instance with the updated `hidden` attribute.
3233
*/
33-
public function hidden(bool $value): static
34+
public function hidden(bool|null $value): static
3435
{
3536
return $this->setAttribute(GlobalAttribute::HIDDEN, $value);
3637
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
use PHPUnit\Framework\Attributes\{DataProviderExternal, Group};
88
use PHPUnit\Framework\TestCase;
9-
use UIAwesome\Html\Attribute\HasDisabled;
9+
use UIAwesome\Html\Attribute\CanBeDisabled;
1010
use UIAwesome\Html\Attribute\Tests\Provider\DisabledProvider;
1111
use UIAwesome\Html\Attribute\Values\Attribute;
1212
use UIAwesome\Html\Helper\Attributes;
1313
use UIAwesome\Html\Mixin\HasAttributes;
1414

1515
/**
16-
* Unit tests for the {@see HasDisabled} trait managing the `disabled` HTML attribute.
16+
* Unit tests for the {@see CanBeDisabled} trait managing the `disabled` HTML attribute.
1717
*
1818
* Test coverage.
1919
* - Ensures fluent setters return new instances (immutability).
@@ -26,13 +26,13 @@
2626
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
2727
*/
2828
#[Group('attribute')]
29-
final class HasDisabledTest extends TestCase
29+
final class CanBeDisabledTest extends TestCase
3030
{
3131
public function testReturnEmptyWhenDisabledAttributeNotSet(): void
3232
{
3333
$instance = new class {
34+
use CanBeDisabled;
3435
use HasAttributes;
35-
use HasDisabled;
3636
};
3737

3838
self::assertEmpty(
@@ -44,8 +44,8 @@ public function testReturnEmptyWhenDisabledAttributeNotSet(): void
4444
public function testReturnNewInstanceWhenSettingDisabledAttribute(): void
4545
{
4646
$instance = new class {
47+
use CanBeDisabled;
4748
use HasAttributes;
48-
use HasDisabled;
4949
};
5050

5151
self::assertNotSame(
@@ -62,13 +62,13 @@ public function testReturnNewInstanceWhenSettingDisabledAttribute(): void
6262
public function testSetDisabledAttributeValue(
6363
bool|null $disabled,
6464
array $attributes,
65-
bool|string|null $expectedValue,
65+
bool|null $expectedValue,
6666
string $expectedRenderAttributes,
6767
string $message,
6868
): void {
6969
$instance = new class {
70+
use CanBeDisabled;
7071
use HasAttributes;
71-
use HasDisabled;
7272
};
7373

7474
$instance = $instance->attributes($attributes)->disabled($disabled);
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
use PHPUnit\Framework\Attributes\{DataProviderExternal, Group};
88
use PHPUnit\Framework\TestCase;
9-
use UIAwesome\Html\Attribute\Form\HasChecked;
9+
use UIAwesome\Html\Attribute\Form\CanBeChecked;
1010
use UIAwesome\Html\Attribute\Tests\Provider\Form\CheckedProvider;
1111
use UIAwesome\Html\Attribute\Values\Attribute;
1212
use UIAwesome\Html\Helper\Attributes;
1313
use UIAwesome\Html\Mixin\HasAttributes;
1414

1515
/**
16-
* Unit tests for the {@see HasChecked} trait managing the `checked` HTML attribute.
16+
* Unit tests for the {@see CanBeChecked} trait managing the `checked` HTML attribute.
1717
*
1818
* Test coverage.
1919
* - Ensures fluent setters return new instances (immutability).
@@ -26,13 +26,13 @@
2626
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
2727
*/
2828
#[Group('attribute')]
29-
final class HasCheckedTest extends TestCase
29+
final class CanBeCheckedTest extends TestCase
3030
{
3131
public function testReturnEmptyWhenCheckedAttributeNotSet(): void
3232
{
3333
$instance = new class {
34+
use CanBeChecked;
3435
use HasAttributes;
35-
use HasChecked;
3636
};
3737

3838
self::assertEmpty(
@@ -44,8 +44,8 @@ public function testReturnEmptyWhenCheckedAttributeNotSet(): void
4444
public function testReturnNewInstanceWhenSettingCheckedAttribute(): void
4545
{
4646
$instance = new class {
47+
use CanBeChecked;
4748
use HasAttributes;
48-
use HasChecked;
4949
};
5050

5151
self::assertNotSame(
@@ -62,13 +62,13 @@ public function testReturnNewInstanceWhenSettingCheckedAttribute(): void
6262
public function testSetCheckedAttributeValue(
6363
bool|null $checked,
6464
array $attributes,
65-
bool|string|null $expectedValue,
65+
bool|null $expectedValue,
6666
string $expectedRenderAttributes,
6767
string $message,
6868
): void {
6969
$instance = new class {
70+
use CanBeChecked;
7071
use HasAttributes;
71-
use HasChecked;
7272
};
7373

7474
$instance = $instance->attributes($attributes)->checked($checked);

0 commit comments

Comments
 (0)