# Confirmation Dialog

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="success" %}
* **Do&#x20;**<mark style="color:red;">**not**</mark>**&#x20;need to add a&#x20;**<mark style="color:red;">**cancel button**</mark>, the confirmation dialog includes a standard <mark style="color:orange;">**dismiss**</mark> action <mark style="color:orange;">by default</mark>.
* <mark style="color:red;">**All actions**</mark>**&#x20;in the confirmation dialog&#x20;**<mark style="color:red;">**dismiss**</mark>**&#x20;the dialog**, do <mark style="color:orange;">**not**</mark> need to manually dismiss the dialog by setting the <mark style="color:orange;">**boolean state**</mark> variable to <mark style="color:orange;">**false**</mark>.
{% endhint %}
{% endtab %}

{% tab title="💾 程式" %}
![](https://1830103165-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5-JmwCZMKh_d7RfBaN%2Fuploads%2FQn6nb7iWMbEgxS8zjhYV%2Fconfirm%20dialog.png?alt=media\&token=28fd67f7-adf8-46aa-a229-7aa2c8255f11)

```swift
struct ConfirmView: View {
    
    // ⭐️ confirmation dialog on/off switch
    @State private var isShowingDialog = false
    
    var body: some View {
        Button("Delete", role: .destructive) {
            isShowingDialog = true                // ⭐️ show dialog
        }
        .buttonStyle(.borderedProminent)
        
        // ------------------------------
        //     ⭐️ confirmation dialog
        // ------------------------------
        .confirmationDialog(
            "Are you sure to delete the data?",    // title
            isPresented: $isShowingDialog,         // on/off
            titleVisibility: .visible
        ) {
            Button("confirm", role: .destructive) {
                print("data deleted ...")
            }
        }
    }
}
```
{% endtab %}

{% tab title="📘 手冊" %}
* SwiftUI ⟩ View ⟩ [Presentation Modifiers](https://developer.apple.com/documentation/swiftui/view-presentation) ⟩
  * [.confirmationDialog(\_:isPresented:titleVisibility:actions:)](https://developer.apple.com/documentation/swiftui/view/confirmationdialog\(_:ispresented:titlevisibility:actions:\)-46zbb) - title
  * [.confirmationDialog(\_:isPresented:titleVisibility:presenting:actions:)](https://developer.apple.com/documentation/swiftui/view/confirmationdialog\(_:ispresented:titlevisibility:presenting:actions:\)-9ibgk) - data
  * [.confirmationDialog(\_:isPresented:titleVisibility:actions:message:)](https://developer.apple.com/documentation/swiftui/view/confirmationdialog\(_:ispresented:titlevisibility:actions:message:\)-2s7pz) - message
{% endtab %}

{% tab title="📗 參考" %}
* [x] Use Your Loaf ⟩ SwiftUI Confirmation Dialogs
{% endtab %}

{% tab title="👥 相關" %}
* use [roles](../control/button/roles "mention").
{% endtab %}
{% endtabs %}
