Skip to content

Commit

Permalink
Add listItemTag method to HasListItem trait. (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Dec 6, 2023
1 parent 80784ae commit d953dd4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Attribute/Component/HasListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
trait HasListItem
{
protected array $listItemAttributes = [];
protected bool $listItemTag = true;

/**
* Get the `HTML` attributes for tag `<li>`.
Expand Down Expand Up @@ -52,4 +53,20 @@ public function listItemClass(string $value): static

return $new;
}

/**
* Disable or enable the tag `<li>`.
*
* @param bool $value Whether to use the tag name or not.
* Default is `true`. If `false` the tag name not will be used.
*
* @return static A new instance of the current class whether to use the tag name `<li>` or not.
*/
public function listItemTag(bool $value): static
{
$new = clone $this;
$new->listItemType = $value;

return $new;
}
}
1 change: 1 addition & 0 deletions tests/Attribute/Component/HasListItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ public function testImmutablity(): void

$this->assertNotSame($instance, $instance->listItemAttributes([]));
$this->assertNotSame($instance, $instance->listItemClass(''));
$this->assertNotSame($instance, $instance->listItemTag(false));
}
}

0 comments on commit d953dd4

Please sign in to comment.