test(actions): cover native modals for actions with fields
This commit is contained in:
3 files changed
+44
No files matched your search
@@ -67,6 +67,25 @@ public function actions(NovaRequest $request): array
|
||||
`exceptInline()` leaves actions available in Nova's bulk selector and detail
|
||||
view while removing them from the row ellipsis.
|
||||
|
||||
### Actions with form fields
|
||||
|
||||
Actions that define fields use Nova's native action modal automatically. Leave
|
||||
`confirm` unset so the action's own confirmation strategy, fields, validation,
|
||||
file uploads, and dependent-field behavior are preserved.
|
||||
|
||||
```php
|
||||
RowActions::make('Actions')
|
||||
->add(
|
||||
Reject::make(),
|
||||
icon: 'x-mark',
|
||||
color: 'danger',
|
||||
);
|
||||
```
|
||||
|
||||
Do not set `confirm: false` on a field-bearing action unless it is intentionally
|
||||
safe to execute with the fields' default values. That option maps directly to
|
||||
Nova's `withoutConfirmation` behavior and bypasses the entire action modal.
|
||||
|
||||
## Button options
|
||||
|
||||
`add()` accepts the following named arguments:
|
||||
|
||||
@@ -34,6 +34,7 @@ class RowActions extends Field
|
||||
*
|
||||
* Callbacks receive the row model, current Nova request, and action instance.
|
||||
* A null confirmation value preserves the action's native confirmation setting.
|
||||
* A false value bypasses Nova's modal, including any fields defined by the action.
|
||||
*
|
||||
* @param Closure(Model, NovaRequest, Action): (Stringable|string|null)|Stringable|string|null $label
|
||||
* @param Closure(Model, NovaRequest, Action): (Stringable|string|null)|Stringable|string|null $tooltip
|
||||
|
||||
@@ -131,6 +131,30 @@ class RowActionsTest extends TestCase
|
||||
$this->assertFalse($actions[0]['action']['withoutConfirmation']);
|
||||
}
|
||||
|
||||
public function test_field_actions_preserve_novas_native_modal_strategy_by_default(): void
|
||||
{
|
||||
$field = RowActions::make()
|
||||
->add(ConfigurableAction::make());
|
||||
|
||||
$action = $this->serialize($field, $this->model())['actions'][0]['action'];
|
||||
|
||||
$this->assertSame('confirm-action-modal', $action['component']);
|
||||
$this->assertFalse($action['withoutConfirmation']);
|
||||
$this->assertSame('reason', $action['fields'][0]['attribute']);
|
||||
$this->assertSame('text-field', $action['fields'][0]['component']);
|
||||
}
|
||||
|
||||
public function test_confirm_false_explicitly_bypasses_the_native_action_modal(): void
|
||||
{
|
||||
$field = RowActions::make()
|
||||
->add(ConfigurableAction::make(), confirm: false);
|
||||
|
||||
$action = $this->serialize($field, $this->model())['actions'][0]['action'];
|
||||
|
||||
$this->assertNotEmpty($action['fields']);
|
||||
$this->assertTrue($action['withoutConfirmation']);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function serialize(RowActions $field, RowActionModel $model): array
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user