Issue with toggling actions

I've got two actions on an Infolist Section in the footer, a "Show" and "Hide" for an OAuth secret. When "Show" is clicked it works, except the "Show" button remains. I have to click it again for it to be aware of the state. Same with the "Hide" button. I've attached a video. The code for the actions is simple.
Infolists\Components\Actions\Action::make('Show')
->color('primary')
->hidden($this->showCredentials)
->action(function () {
$this->showCredentials = true;
}),

Infolists\Components\Actions\Action::make('Hide')
->color('primary')
->hidden(! $this->showCredentials)
->action(function () {
$this->showCredentials = false;
}),
Infolists\Components\Actions\Action::make('Show')
->color('primary')
->hidden($this->showCredentials)
->action(function () {
$this->showCredentials = true;
}),

Infolists\Components\Actions\Action::make('Hide')
->color('primary')
->hidden(! $this->showCredentials)
->action(function () {
$this->showCredentials = false;
}),
Solution:
You can use callbacks in the label to change that.
Jump to solution
4 Replies
awcodes
awcodes19h ago
Does this need to be 2 actions?
ollieread
olliereadOP19h ago
Not necessarily, no I'd prefer Show/Hide
Solution
awcodes
awcodes19h ago
You can use callbacks in the label to change that.
ollieread
olliereadOP18h ago
That worked a treat, thanks.

Did you find this page helpful?