Skip to content

Commit d56184d

Browse files
vjiksamdarkarogachev
authored
Add optional wrap parameter to BooleanInputTag::label() (#224)
* Add optional `wrap` parameter to `BooleanInputTag::label()` * Update CHANGELOG.md Co-authored-by: Alexander Makarov <sam@rmcreative.ru> * Update CHANGELOG.md Co-authored-by: Alexey Rogachev <arogachev90@gmail.com> * Update src/Tag/Base/BooleanInputTag.php Co-authored-by: Alexey Rogachev <arogachev90@gmail.com> * Update src/Tag/Base/BooleanInputTag.php Co-authored-by: Alexey Rogachev <arogachev90@gmail.com> * fix --------- Co-authored-by: Alexander Makarov <sam@rmcreative.ru> Co-authored-by: Alexey Rogachev <arogachev90@gmail.com>
1 parent 279ef55 commit d56184d

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- Enh #220: Add `non-empty-string` psalm type of `Html::generateId()` method result (@vjik)
66
- Enh #220: Add `non-empty-string|null` psalm type of `Tag::id()` method parameter (@vjik)
77
- Enh #222: Bump minimal PHP version to 8.1 and refactor (@vjik)
8+
- New #224: Add optional `wrap` parameter to `BooleanInputTag::label()` method that controls whether to wrap input tag
9+
with label tag or place them aside (@vjik)
810

911
## 3.7.0 September 18, 2024
1012

src/Tag/Base/BooleanInputTag.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ final public function checked(bool $checked = true): static
3636
*
3737
* @param string|null $label Input label.
3838
* @param array $attributes Name-value set of label attributes.
39+
* @param bool $wrap Whether to wrap input with label tag. If set to `false`, label will be rendered aside with
40+
* input.
3941
*/
40-
final public function label(?string $label, array $attributes = []): static
41-
{
42+
final public function label(
43+
?string $label,
44+
array $attributes = [],
45+
bool $wrap = true,
46+
): static {
4247
$new = clone $this;
4348
$new->label = $label;
4449
$new->labelAttributes = $attributes;
50+
$new->labelWrap = $wrap;
4551
return $new;
4652
}
4753

tests/Tag/Base/BooleanInputTagTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ public function testLabel(string $expected, ?string $label, array $attributes):
6161
);
6262
}
6363

64+
public function testLabelNoWrap(): void
65+
{
66+
$this->assertSame(
67+
'<input type="test" id="ID"> <label for="ID">Voronezh</label>',
68+
(string) TestBooleanInputTag::tag()
69+
->id('ID')
70+
->label('Voronezh', wrap: false),
71+
);
72+
}
73+
6474
public function testLabelWithId(): void
6575
{
6676
$this->assertSame(

0 commit comments

Comments
 (0)