funkwhale/front/ui-docs/components/ui/modal.md

6.2 KiB

Modal

Prop Data type Required? Default Description
title string Yes The modal title
v-model true | false Yes Whether the modal is isOpen or not
<Modal v-model="isOpen" title="My modal">
  Modal content
</Modal>

<Button @click="isOpen = true">
  Open modal
</Button>
Modal content Open modal

Modal actions

Use the #actions slot to add actions to a modal. Actions typically take the form of buttons.

Make sure to add autofocus to the preferred button.

<Modal v-model="isOpen" title="My modal">
  Modal content

  <template #actions>
    <Button @click="isOpen = false" color="secondary">
      Cancel
    </Button>

    <Button autofocus @click="isOpen = false">
      Ok
    </Button>
  </template>
</Modal>

<Button @click="isOpen = true">
  Open modal
</Button>
Modal content Cancel Ok Open modal

Confirm a dangerous action

Note that confirmation dialogs interrupt the user's workflow. Consider adding a recovery functionality such as "undo" instead.

::: tip Read more about designing user experiences around dangerous actions:

If you need to implement dangerous actions, make sure to place them apart from other actions to prevent accidental clicks. Add contextual hints and information so that the user understands the consequences of the action.

  1. Let the user confirm potentially destructive actions
  2. Do not use confirmation dialogs for routine tasks
  3. Be specific about the action and its potential consequences
  4. Label the response buttons with their result: "Delete my account" instead of "Yes"
  5. Make sure to give the user all information they need to decide

:::

<Modal v-model="isOpen" title="Delete account?">
  <template #alert>
    <Alert color="red">
1 082 music files that you uploaded will be deleted.<br />
7 879 items in your collections will be unlinked.
    </Alert>
  </template>
Do you want to delete your account forever?

You will not be able to restore your account.
  <template #actions>
    <Button autofocus @click="isOpen = false" color="secondary">
      Keep my account
    </Button>
    <Button color="destructive" @click="isOpen = false">
      I understand. Delete my account now!
    </Button>
  </template>
</Modal>
<Button @click="isOpen = true" color="destructive">
  Delete my account ...
</Button>
1 082 music files that you uploaded will be deleted.
7 879 items in your collections will be unlinked. Do you want to delete your account forever?

You will not be able to restore your account. <template #actions> <Button autofocus @click="isOpen6 = false" color="secondary"> Keep my account <Button color="destructive" @click="isOpen6 = false"> I understand. Delete my account now! <Button @click="isOpen6 = true" color="destructive"> Delete my account ...

Nested modals

You can nest modals to allow users to isOpen a modal from inside another modal. This can be useful when creating a multi-step workflow.

<Modal v-model="isOpen" title="My modal">
  <Modal v-model="isOpenNested" title="My modal">
    Nested modal content
  </Modal>

  <Button autofocus @click="isOpenNested = true">
    Open nested modal
  </Button>
</Modal>

<Button @click="isOpen = true">
  Open modal
</Button>
Nested modal content Open nested modal Open modal

Alert inside modal

You can nest Funkwhale alerts to visually highlight content within the modal.

<Modal v-model="isOpen" title="My modal">
  Modal content

  <template #alert v-if="alertOpen">
    <fw-alert>
      Alert content

      <template #actions>
        <Button autofocus @click="alertOpen = false">Close alert</Button>
      </template>
    </fw-alert>
  </template>
</Modal>

<Button @click="isOpen = true">
  Open modal
</Button>
Modal content Alert content Close alert Cancel Ok Open modal