Skip to content

Commit

Permalink
Merge pull request #16 from portavice/fixes
Browse files Browse the repository at this point in the history
Fix display of disabled navigation items and value of disabled form fields
  • Loading branch information
patrickrobrecht authored Mar 20, 2024
2 parents 4603418 + e8d122b commit 4114892
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Move PHPDoc comments outside of `@props` block
- Display of disabled navigation items (`<x-bs::nav.item :disabled="true">`)
- Set the value of disabled form fields even if the value is not contained in the old values


## Version 1.1.1 (2024-01-05)
Expand Down
4 changes: 3 additions & 1 deletion resources/views/components/form/field.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@
}
// Override selected value and apply cast.
$value = ValueHelper::value($name, $value, $fromQuery, $cast);
if (!$disabled) {
$value = ValueHelper::value($name, $value, $fromQuery, $cast);
}
$showFeedback = true;
@endphp
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/nav/item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
->class([
'nav-link',
'active' => $active,
'disabled' => $disabled,
'dropdown-toggle' => $hasDropdown,
])
->merge([
'aria-current' => $active ? 'page' : null,
'aria-disabled' => $disabled ? 'true' : null,
'disabled' => $disabled,
]) }}>{{ $slot }}</a>
@if($hasDropdown)
<ul {{ $dropdown->attributes
Expand Down
15 changes: 15 additions & 0 deletions tests/Feature/Form/FormField/FormFieldValuesFilledFromOldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ public function testFormFieldFilledWithOldValue(array $old, string $html, string
$this->assertBladeRendersToHtml($html, $this->bladeView($blade, $data));
}

/**
* @dataProvider formDataProvider
*/
public function testDisabledFormFieldHasValueEvenIfNotInOldValues(array $old): void
{
$this->mockOld($old);
$this->assertBladeRendersToHtml(
'<div class="mb-3">
<label for="count" class="form-label">Count</label>
<input id="count" name="count" type="number" value="42" class="form-control" disabled/>
</div>',
'<x-bs::form.field name="count" type="number" :disabled="true" value="42">Count</x-bs::form.field>'
);
}

public static function formDataProvider(): array
{
return [
Expand Down
12 changes: 11 additions & 1 deletion tests/Feature/NavTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,22 @@ public function testNavItemRendersCorrectlyForCurrentPage(): void
$this->mockRequest('http://localhost/current-page');
$this->assertBladeRendersToHtml(
'<li class="nav-item">
<a aria-current="page" class="nav-link active" href="http://localhost/current-page">Current Page</a>
<a aria-current="page" class="nav-link active" href="http://localhost/current-page">Current Page</a>
</li>',
$this->bladeView('<x-bs::nav.item href="http://localhost/current-page">Current Page</x-bs::nav.item>')
);
}

public function testDisabledNavItemRendersCorrectly(): void
{
$this->assertBladeRendersToHtml(
'<li class="nav-item">
<a aria-disabled="true" class="nav-link disabled" href="http://localhost/">Page</a>
</li>',
$this->bladeView('<x-bs::nav.item href="http://localhost/" :disabled="true">Page</x-bs::nav.item>')
);
}

public function testNavDropdownRendersCorrectly(): void
{
$this->assertBladeRendersToHtml(
Expand Down

0 comments on commit 4114892

Please sign in to comment.