Skip to content
LIBRARYBase

SwipeActions ​

Added in RC.11.1

Included in Mavis 0.1.0-rc.11.1 for Vue + Vite, Nuxt and NativeScript iOS/Android. Keep core and renderers on the same version.

Web preview
Open example ↗
vue
<MSwipeActions
  v-model="side"
  label="Message"
  :start="favorites"
  :end="archive"
  @action="handleAction"
>
  <MText text="Weekend plans" />
</MSwipeActions>
PropTypeContract
modelValue'start' | 'end' | nullOpen side; default null.
start / endreadonly SwipeAction[]Actions with unique value, visible label, optional icon, disabled, destructive.
actionWidth / directionnumber / 'ltr' or 'rtl'96 / ltr. Width per action and logical reading direction.
disabled / actionsLabel / closeLabelboolean / string / stringDisable input and localize controls.
gestureMotionGestureExperimental. Receives the row swipe, for gesture relations.

Drag horizontally to reveal actions. Jolt follows the gesture and settles the row; release velocity contributes to choosing a side. Swiping never executes an action automatically. The Actions menu exposes every action to keyboard and assistive input. Escape and Close actions return the row to rest. Supply direction="rtl" to mirror logical start/end.

The action event supplies the selected action. The application owns archiving/deletion and undo; the component closes after an action. Place one or two short actions per side so the row remains usable on narrow screens. Keep complex horizontal controls outside the swipe surface.

While dragging, each action group grows from a faint, smaller pose as the row uncovers it. When a side opens, its actions bump one after another from the edge of the card; on NativeScript the row settles open with a light haptic. Text in the row is not selected while swiping.

Action width ​

Each button occupies one actionWidth in CSS pixels on the Web or device-independent pixels on NativeScript. With the default width, one action opens the row by 96 and two actions on the same side open it by 192. Choose a larger width if your longest translated word needs more room.

Chromium with emulated touch input. Swiping right reveals Star and Unstar. Swiping left reveals Archive. Tapping the exposed buttons updates the message, and Undo archive brings it back.

iOS Simulator, NativeScript catalog. System swipes reveal the two sides of the message. Taps toggle the star, archive the message and restore it.

Android emulator, NativeScript catalog. System swipes expose the full Star, Unstar and Archive buttons. Tapping Undo archive restores the row.

vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import type { SwipeAction, SwipeSide } from '@getcortexlabs/mavis-core'
import { useCatalogLocale } from '../locale'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const t = (en: string, br: string) => (pt.value ? br : en)
const side = ref<SwipeSide>(null)
const result = ref('')
const archived = ref(false)
const favorite = ref(false)
const start = computed<SwipeAction[]>(() => [
  {
    value: 'favorite',
    label: favorite.value ? t('Unstar', 'Desmarcar') : t('Star', 'Favoritar'),
    icon: 'star',
  },
])
const end = computed<SwipeAction[]>(() => [
  { value: 'archive', label: t('Archive', 'Arquivar'), icon: 'archive' },
])
function act(action: SwipeAction) {
  result.value = String(action.value)
  if (action.value === 'archive') archived.value = true
  else favorite.value = !favorite.value
}
</script>
<template>
  <MColumn gap="lg">
    <MColumn gap="xs"
      ><MText text="A GOOD KIND OF INBOX" variant="overline" tone="primary" /><MText
        :text="t('Something worth opening.', 'Uma mensagem que vale abrir.')"
        variant="title" /><MText
        :text="
          t('Slide either way. Keep what matters.', 'Deslize para os lados. Guarde o que importa.')
        "
        tone="muted"
    /></MColumn>
    <MSwipeActions
      v-if="!archived"
      v-model="side"
      :label="t('Weekend plans', 'Planos para o fim de semana')"
      :start="start"
      :end="end"
      :actionsLabel="t('Actions', 'Ações')"
      :closeLabel="t('Close actions', 'Fechar ações')"
      @action="act"
    >
      <MColumn id="swipe-message" gap="md"
        ><MRow justify="between" align="center"
          ><MRow gap="sm" align="center"
            ><MAvatar name="Mia Chen" size="md" /><MColumn
              ><MText text="Mia Chen" weight="600" /><MText
                text="09:41"
                variant="caption"
                tone="muted" /></MColumn></MRow
          ><MIcon v-if="favorite" name="star" tone="primary" /></MRow
        ><MText
          :text="t('The cabin is booked. You in?', 'A cabana está reservada. Bora?')"
          variant="heading" /><MText
          :text="
            t(
              'Fresh air, a long walk, and absolutely no meetings.',
              'Ar puro, uma boa caminhada e nenhuma reunião.',
            )
          "
          tone="muted"
      /></MColumn>
    </MSwipeActions>
    <MEmptyState
      v-else
      :title="t('A little more room.', 'Um pouco mais de espaço.')"
      :description="
        t(
          'Message archived. You can bring it back.',
          'Mensagem arquivada. Você pode trazê-la de volta.',
        )
      "
      icon="check"
      ><template #actions
        ><MButton :text="t('Undo archive', 'Desfazer')" @click="archived = false" /></template
    ></MEmptyState>
    <MText
      id="swipe-result"
      :text="result || t('No action yet', 'Nenhuma ação ainda')"
      variant="caption"
      tone="muted"
    />
  </MColumn>
</template>

Desktop ​

On the Mac and on Windows the row is dragged sideways with the pointer to uncover its actions, and a secondary click on it shows the same actions as a menu, as the actions button does. gesture has no effect on desktop. See Desktop components.

Components for NativeScript and Web. Starting with Vue.