diff --git a/packages/forms/src/Components/Concerns/HasHint.php b/packages/forms/src/Components/Concerns/HasHint.php index 68393328b6..70da0dd7e4 100644 --- a/packages/forms/src/Components/Concerns/HasHint.php +++ b/packages/forms/src/Components/Concerns/HasHint.php @@ -109,7 +109,10 @@ trait HasHint public function hintIcon(string | BackedEnum | Htmlable | Closure | null $icon, string | Closure | null $tooltip = null): static { $this->hintIcon = $icon; - $this->hintIconTooltip($tooltip); + + if (func_num_args() >= 2) { + $this->hintIconTooltip($tooltip); + } return $this; } diff --git a/packages/infolists/src/Components/Concerns/HasHint.php b/packages/infolists/src/Components/Concerns/HasHint.php index ccbdb392e6..9c66db08ca 100644 --- a/packages/infolists/src/Components/Concerns/HasHint.php +++ b/packages/infolists/src/Components/Concerns/HasHint.php @@ -108,7 +108,10 @@ trait HasHint public function hintIcon(string | BackedEnum | Htmlable | Closure | null $icon, string | Closure | null $tooltip = null): static { $this->hintIcon = $icon; - $this->hintIconTooltip($tooltip); + + if (func_num_args() >= 2) { + $this->hintIconTooltip($tooltip); + } return $this; } diff --git a/tests/src/Forms/HintTest.php b/tests/src/Forms/HintTest.php index 4d13137d22..d6eeda06f3 100644 --- a/tests/src/Forms/HintTest.php +++ b/tests/src/Forms/HintTest.php @@ -77,3 +77,31 @@ class TestComponentWithFormWithTestFieldHint extends Livewire ->statePath('data'); } } + +it('can set a hint icon tooltip via hintIcon second parameter', function (): void { + $field = TextInput::make('test') + ->container(Schema::make(Livewire::make())) + ->hintIcon('heroicon-o-information-circle', 'Example tooltip'); + expect($field->getHintIconTooltip()) + ->toBe('Example tooltip'); +}); + +it('does not clear a previously set hint icon tooltip when calling hintIcon without a tooltip', function (): void { + $field = TextInput::make('test') + ->container(Schema::make(Livewire::make())) + ->hintIconTooltip('Example tooltip') + ->hintIcon('heroicon-o-information-circle'); + + expect($field->getHintIconTooltip()) + ->toBe('Example tooltip'); +}); + +it('can clear a previously set hint icon tooltip by explicitly passing null to hintIcon', function (): void { + $field = TextInput::make('test') + ->container(Schema::make(Livewire::make())) + ->hintIconTooltip('Example tooltip') + ->hintIcon('heroicon-o-information-circle', null); + + expect($field->getHintIconTooltip()) + ->toBeNull(); +}); diff --git a/tests/src/Infolists/EntryTest.php b/tests/src/Infolists/EntryTest.php index 13a4c20fe9..8df5a10579 100644 --- a/tests/src/Infolists/EntryTest.php +++ b/tests/src/Infolists/EntryTest.php @@ -1,6 +1,8 @@ container(Schema::make(Livewire::make())) + ->hintIcon('heroicon-o-information-circle', 'Example tooltip'); + + expect($entry->getHintIconTooltip()) + ->toBe('Example tooltip'); +}); + +it('does not clear a previously set hint icon tooltip when calling hintIcon without a tooltip', function (): void { + $entry = TextEntry::make('test') + ->container(Schema::make(Livewire::make())) + ->hintIconTooltip('Example tooltip') + ->hintIcon('heroicon-o-information-circle'); + + expect($entry->getHintIconTooltip()) + ->toBe('Example tooltip'); +}); + +it('can clear a previously set hint icon tooltip by explicitly passing null to hintIcon', function (): void { + $entry = TextEntry::make('test') + ->container(Schema::make(Livewire::make())) + ->hintIconTooltip('Example tooltip') + ->hintIcon('heroicon-o-information-circle', null); + + expect($entry->getHintIconTooltip()) + ->toBeNull(); +});