Skip to content
LIBRARYForms

Composer ​

Included in RC.12

Available in Mavis 0.1.0-rc.12 for Vue + Vite, Nuxt and NativeScript. Keep the Mavis packages at the same version.

Web preview
Open example ↗
vue
<MComposer
  v-model="draft"
  v-model:attachments="attachments"
  label="Your message"
  @attach="chooseFiles"
  @submit="send"
/>
PropTypeDefaultContract
modelValue / attachmentsstring / ComposerAttachment[]empty / []Controlled draft and unique attachment ids/names.
label / placeholder / errorstring—Editor name, hint and validation message.
rows / maxLengthnumber2 / unlimitedInitial editor lines and optional character limit.
counter / counterLabelboolean / stringfalse / characters leftOpt-in count of the characters left before maxLength.
loading / disabled / readonlybooleanfalseExplicit editing and submission states.
followKeyboard / keyboardOffset / shortcutboolean / number / booleanfalse / 0 / trueOverlay keyboard following and Web Ctrl/Cmd+Enter.
attachable / attachLabel / removeLabel / sendLabel / sendingLabelboolean / stringtrue / English labelsAttachment affordance and translatable controls.

A controlled multiline editor with removable attachment names. The application chooses files, sends messages and clears the draft after success; the component never uploads or clears it automatically. The submit event receives { text, attachments }. Ctrl/Cmd+Enter submits on Web while Enter keeps its newline and IME composition is preserved. loading locks editing and actions. followKeyboard is opt-in for a dedicated overlay; leave it off inside a resizing Screen or Sheet to avoid duplicate adjustments. Web keyboard geometry is estimated; native timing is supplied by Jolt. Slots: default for supporting content. focus()/blur() target the editor.

A resizing Web Screen and a Sheet own keyboard placement for their contents. An overlay Composer outside these containers can opt into Jolt keyboard following. A cached or detached Composer releases its follower. On Android, when a docked keyboard leaves very little space in a sheet, the heading scrolls with the form so the focused editor stays in view.

Motion stays decoration and follows reduced motion. The send button lifts when the draft becomes sendable, and shakes on Web when Ctrl/Cmd+Enter has nothing to send; focus stays in the editor. A ring spreads behind the button when a message is sent, without moving the button. Attachments pop in and leave through the row. With counter and maxLength, the count turns to a warning tone and bumps in the last tenth, and shakes when the limit is reached. Its accessible name joins the number and counterLabel.

On iPad, a standalone Composer with followKeyboard stays at rest when the keyboard floats. It follows the keyboard again when it docks at the bottom.

Editing in a sheet ​

iPhone Simulator. The on-screen keyboard edits the draft. Closing and reopening the sheet preserves it.

Android emulator. Gboard edits the sheet draft. The text survives keyboard dismissal and reopening the sheet.

Desktop Chromium. Keyboard input updates the controlled draft, which remains available when the sheet reopens.

vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import type { ComposerAttachment, ComposerMessage } 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 draft = ref(''),
  attachments = ref<ComposerAttachment[]>([]),
  messages = ref<string[]>([]),
  loading = ref(false)
const sheetOpen = ref(false)
let serial = 0
function attach() {
  attachments.value.push({ id: String(++serial), name: `field-notes-${serial}.pdf` })
}
async function send(message: ComposerMessage) {
  if (loading.value) return
  loading.value = true
  await new Promise((resolve) => setTimeout(resolve, 450))
  messages.value.push(message.text || message.attachments[0]?.name || '')
  draft.value = ''
  attachments.value = []
  loading.value = false
}
</script>
<template>
  <MColumn gap="lg">
    <MRow gap="md" align="center"
      ><MAvatar name="Clara" /><MColumn gap="xs"
        ><MText text="FIELD NOTES" variant="overline" tone="primary" /><MText
          :text="t('Good ideas start here.', 'Boas ideias começam aqui.')"
          variant="heading" /></MColumn
    ></MRow>
    <MCard gap="sm"
      ><MText text="Clara" variant="caption" tone="primary" /><MText
        :text="
          t(
            'What if we took the scenic route this time?',
            'E se dessa vez a gente fosse pelo caminho mais bonito?',
          )
        "
    /></MCard>
    <MCard v-for="(message, i) in messages" :key="i" gap="xs"
      ><MText :text="t('You', 'Você')" variant="caption" tone="primary" /><MText :text="message"
    /></MCard>
    <MComposer
      v-model="draft"
      v-model:attachments="attachments"
      :label="t('Your message', 'Sua mensagem')"
      :placeholder="t('Add a thought…', 'Compartilhe uma ideia…')"
      :maxLength="140"
      counter
      :counterLabel="t('characters left', 'caracteres restantes')"
      :loading="loading"
      :attachLabel="t('Add attachment', 'Adicionar anexo')"
      :removeLabel="t('Remove attachment', 'Remover anexo')"
      :sendLabel="t('Send message', 'Enviar mensagem')"
      :sendingLabel="t('Sending', 'Enviando')"
      @attach="attach"
      @submit="send"
    />
    <MButton
      variant="secondary"
      :text="t('Edit in sheet', 'Editar na folha')"
      @click="sheetOpen = true"
    />
    <MSheet
      v-model:open="sheetOpen"
      :title="t('Edit draft', 'Editar rascunho')"
      :closeLabel="t('Close draft', 'Fechar rascunho')"
    >
      <MComposer
        v-model="draft"
        :attachable="false"
        followKeyboard
        :label="t('Draft in sheet', 'Rascunho na folha')"
        @submit="send"
      />
    </MSheet>
    <MText id="composer-sent" :text="String(messages.length)" variant="caption" tone="muted" />
  </MColumn>
</template>

Desktop ​

On the desktop Command-Return on the Mac and Control-Enter on Windows send the message while anything in the composer has the keyboard. There is no software keyboard to follow, so followKeyboard and keyboardOffset have no effect; see Desktop components.

Components for NativeScript and Web. Starting with Vue.