Skip to content

[ShadcnAdminUi] Add a confirm button to the confirmation modal - #410

Merged
loic425 merged 1 commit into
Sylius:shadcn-admin-uifrom
loic425:shadcn-admin-ui-confirmation-modal-props
Nov 18, 2026
Merged

loic425 merged 1 commit into
Sylius:shadcn-admin-uifrom
loic425:shadcn-admin-ui-confirmation-modal-props

Conversation

@loic425

@loic425 loic425 commented Nov 17, 2026

Copy link
Copy Markdown
Member

Problem

confirmation_modal only renders a Cancel button. To confirm anything that isn't the CSRF form of delete_modal (a Live action, a Stimulus action, a form of the page), the whole footer block has to be overridden: the Cancel button is copied, the confirm button rebuilt with the right classes, and the dialog has to be closed by hand.

<twig:sylius_shadcn_admin_ui:confirmation_modal title="Archive this book?">
    <twig:block name="trigger">…</twig:block>
    <twig:block name="footer">
        <button type="button" class="{{ cancel_class }}" data-action="shadcn--alert-dialog#close">{{ 'sylius.ui.cancel'|trans }}</button>
        <button type="button" class="{{ confirm_class }}" data-action="shadcn--alert-dialog#close live#action" data-live-action-param="archive">Archive</button>
    </twig:block>
</twig:sylius_shadcn_admin_ui:confirmation_modal>

button_class() isn't visible inside the <twig:…> blocks either, so the classes must be computed before the component.

Solution

Three optional props. Without confirm_label, the footer is unchanged.

Prop Default
confirm_label null Adds a confirm button next to Cancel
confirm_variant 'default' Button variant; destructive uses the same solid style as delete_modal
confirm_attributes {} Attributes of the button. Its data-action runs after shadcn--alert-dialog#close, type defaults to button

Live action:

<twig:sylius_shadcn_admin_ui:confirmation_modal
    title="Archive this book?"
    confirm_label="Archive"
    confirm_variant="destructive"
    :confirm_attributes="{'data-action': 'live#action', 'data-live-action-param': 'archive'}"
>
    <twig:block name="trigger">
        <button type="button" {{ trigger_attributes }}>Archive</button>
    </twig:block>
</twig:sylius_shadcn_admin_ui:confirmation_modal>

Form of the page:

<twig:sylius_shadcn_admin_ui:confirmation_modal
    confirm_label="Publish"
    :confirm_attributes="{type: 'submit', form: 'publish-form'}"
>…</twig:sylius_shadcn_admin_ui:confirmation_modal>

The confirm button carries data-test-confirm-button, like the one of delete_modal.

Tests

ConfirmationModalComponentTest: default footer, Live action, destructive variant, form submit. The ShadcnAdminUi suite passes (74 tests) after importmap:install and tailwind:build, as in the CI.

@loic425
loic425 marked this pull request as ready for review November 17, 2026 15:19
@loic425 loic425 mentioned this pull request Nov 17, 2026
4 tasks done
@loic425
loic425 merged commit dd54960 into Sylius:shadcn-admin-ui Nov 18, 2026
6 checks passed
@loic425
loic425 deleted the shadcn-admin-ui-confirmation-modal-props branch November 18, 2026 07:45
loic425 added a commit that referenced this pull request Nov 18, 2026
The main PR with the work from @rem42 @camilleislasse and myself.

Sub tasks:
- [x] #403
- [x] #409
- [x] #410
- [x] #411
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants