Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- Enh #52: Add `InputColor` class for HTML `<input type="color">` element with attributes and rendering capabilities (@terabytesoftw)
- Enh #53: Add `TextArea` class for HTML `<textarea>` element with attributes and rendering capabilities (@terabytesoftw)
- Bug #54: Update exception test method names for consistency and clarity (@terabytesoftw)
- Bug #55: Remove `BaseChoice` class and related mixins; update `InputCheckbox`, `InputFile`, and `InputRadio` to extend `BaseInput` class (@terabytesoftw)

## 0.3.0 March 31, 2024

Expand Down
126 changes: 0 additions & 126 deletions src/Form/Base/BaseChoice.php

This file was deleted.

41 changes: 35 additions & 6 deletions src/Form/InputCheckbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

namespace UIAwesome\Html\Form;

use UIAwesome\Html\Attribute\Form\CanBeRequired;
use UIAwesome\Html\Attribute\Global\{CanBeAutofocus, HasTabindex};
use UIAwesome\Html\Attribute\HasValue;
use UIAwesome\Html\Attribute\Values\Type;
use UIAwesome\Html\Form\Base\BaseChoice;
use UIAwesome\Html\Core\Element\BaseInput;
use UIAwesome\Html\Form\Mixin\HasCheckedState;
use UIAwesome\Html\Interop\{VoidInterface, Voids};

/**
Expand All @@ -28,8 +32,26 @@
* @copyright Copyright (C) 2026 Terabytesoftw.
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
*/
final class InputCheckbox extends BaseChoice
final class InputCheckbox extends BaseInput
{
use CanBeAutofocus;
use CanBeRequired;
use HasCheckedState;
use HasTabindex;
use HasValue;

/**
* Returns the array of HTML attributes for the element.
*
* @return array Attributes array assigned to the element.
*
* @phpstan-return mixed[]
*/
public function getAttributes(): array
{
return $this->buildAttributes(parent::getAttributes());
}

/**
* Returns the tag enumeration for the `<input>` element.
*
Expand All @@ -49,9 +71,16 @@ protected function getTag(): VoidInterface
*/
protected function loadDefault(): array
{
return [
'template' => ['{prefix}\n{unchecked}\n{tag}\n{label}\n{suffix}'],
'type' => [Type::CHECKBOX],
] + parent::loadDefault();
return parent::loadDefault() + ['type' => [Type::CHECKBOX]];
}

/**
* Renders the `<input>` element with its attributes.
*
* @return string Rendered HTML for the `<input>` element.
*/
protected function run(): string
{
return $this->buildElement();
}
}
25 changes: 3 additions & 22 deletions src/Form/InputFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use UIAwesome\Html\Attribute\Values\Type;
use UIAwesome\Html\Core\Element\BaseInput;
use UIAwesome\Html\Form\Attribute\HasCapture;
use UIAwesome\Html\Form\Mixin\HasUnchecked;
use UIAwesome\Html\Helper\Naming;
use UIAwesome\Html\Interop\{VoidInterface, Voids};

Expand Down Expand Up @@ -49,7 +48,6 @@ final class InputFile extends BaseInput
use HasCapture;
use HasForm;
use HasTabindex;
use HasUnchecked;

/**
* Returns the array of HTML attributes for the element.
Expand All @@ -61,6 +59,7 @@ final class InputFile extends BaseInput
public function getAttributes(): array
{
$attributes = parent::getAttributes();

$attributes['name'] = $this->generateNameWithMultiple();

// value attribute is not allowed for the `<input type="file">` element, so we remove it if it exists.
Expand Down Expand Up @@ -88,10 +87,7 @@ protected function getTag(): VoidInterface
*/
protected function loadDefault(): array
{
return [
'template' => ['{prefix}\n{unchecked}\n{tag}\n{suffix}'],
'type' => [Type::FILE],
] + parent::loadDefault();
return parent::loadDefault() + ['type' => [Type::FILE]];
}

/**
Expand All @@ -101,22 +97,7 @@ protected function loadDefault(): array
*/
protected function run(): string
{
$uncheckedValue = $this->getUncheckedValue();

if ($uncheckedValue !== null && $uncheckedValue !== '') {
$unchecked = InputHidden::tag()
->id(null)
->name($this->generateNameWithMultiple())
->value($uncheckedValue)
->render();
}

return $this->buildElement(
'',
[
'{unchecked}' => $unchecked ?? '',
],
);
return $this->buildElement();
}

/**
Expand Down
41 changes: 35 additions & 6 deletions src/Form/InputRadio.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

namespace UIAwesome\Html\Form;

use UIAwesome\Html\Attribute\Form\CanBeRequired;
use UIAwesome\Html\Attribute\Global\{CanBeAutofocus, HasTabindex};
use UIAwesome\Html\Attribute\HasValue;
use UIAwesome\Html\Attribute\Values\Type;
use UIAwesome\Html\Form\Base\BaseChoice;
use UIAwesome\Html\Core\Element\BaseInput;
use UIAwesome\Html\Form\Mixin\HasCheckedState;
use UIAwesome\Html\Interop\{VoidInterface, Voids};

/**
Expand All @@ -28,8 +32,26 @@
* @copyright Copyright (C) 2026 Terabytesoftw.
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
*/
final class InputRadio extends BaseChoice
final class InputRadio extends BaseInput
{
use CanBeAutofocus;
use CanBeRequired;
use HasCheckedState;
use HasTabindex;
use HasValue;

/**
* Returns the array of HTML attributes for the element.
*
* @return array Attributes array assigned to the element.
*
* @phpstan-return mixed[]
*/
public function getAttributes(): array
{
return $this->buildAttributes(parent::getAttributes());
}

/**
* Returns the tag enumeration for the `<input>` element.
*
Expand All @@ -49,9 +71,16 @@ protected function getTag(): VoidInterface
*/
protected function loadDefault(): array
{
return [
'template' => ['{prefix}\n{unchecked}\n{tag}\n{label}\n{suffix}'],
'type' => [Type::RADIO],
] + parent::loadDefault();
return parent::loadDefault() + ['type' => [Type::RADIO]];
}

/**
* Renders the `<input>` element with its attributes.
*
* @return string Rendered HTML for the `<input>` element.
*/
protected function run(): string
{
return $this->buildElement();
}
}
39 changes: 0 additions & 39 deletions src/Form/Mixin/CanBeEnclosedByLabel.php

This file was deleted.

Loading
Loading