diff --git a/src/Options/StateOptions.php b/src/Options/StateOptions.php index 9e880fc..8962aa5 100644 --- a/src/Options/StateOptions.php +++ b/src/Options/StateOptions.php @@ -70,8 +70,8 @@ public function reactive(): static /** * Indicate the state should be tracked in the URL. */ - public function url(?string $as = null, ?bool $history = null, ?bool $keep = null): static + public function url(?string $as = null, ?bool $history = null, ?bool $keep = null, ?string $except = null): static { - return $this->attribute(Url::class, as: $as, history: $history, keep: $keep); + return $this->attribute(Url::class, as: $as, history: $history, keep: $keep, except: $except); } } diff --git a/tests/Feature/Compiler/UrlTest.php b/tests/Feature/Compiler/UrlTest.php index 006bad1..aa5001a 100644 --- a/tests/Feature/Compiler/UrlTest.php +++ b/tests/Feature/Compiler/UrlTest.php @@ -15,10 +15,12 @@ state('searchOne')->url(); state('searchTwo')->url(as: 'search', history: true); state('searchThree')->url(keep: true); + state('searchFour')->url(keep: true, except: ''); $code = Compiler::contextToString(CompileContext::instance()); - expect($code)->toContain(<<<'PHP' + expect($code)->toContain( + <<<'PHP' #[\Livewire\Attributes\Url()] public $searchOne; @@ -27,6 +29,9 @@ #[\Livewire\Attributes\Url(keep: true)] public $searchThree; + + #[\Livewire\Attributes\Url(keep: true, except: '')] + public $searchFour; PHP ); }); diff --git a/tests/Feature/CompilerContext/UrlTest.php b/tests/Feature/CompilerContext/UrlTest.php index 184178c..a8ff9b4 100644 --- a/tests/Feature/CompilerContext/UrlTest.php +++ b/tests/Feature/CompilerContext/UrlTest.php @@ -13,8 +13,9 @@ state(searchOne: 1)->url(); state(searchTwo: 2)->url(as: 'search', history: true); state(searchThree: 3)->url(keep: true); + state(searchFour: 4)->url(keep: true, except: ''); - expect($context->state)->toHaveKeys(['name', 'searchOne', 'searchTwo', 'searchThree']) + expect($context->state)->toHaveKeys(['name', 'searchOne', 'searchTwo', 'searchThree', 'searchFour']) ->sequence( fn (Expectation $property) => $property->attributes->toBe([]), fn (Expectation $property) => $property->attributes->toBe([ @@ -31,5 +32,11 @@ 'keep' => true, ], ]), + fn (Expectation $property) => $property->attributes->toBe([ + Url::class => [ + 'keep' => true, + 'except' => '', + ], + ]), ); });