Text Editor Vue Component

Text Editor Vue component represents Text Editor component.

Text Editor Components

There are following components included:

  • f7-text-editor

Text Editor Properties

PropTypeDefaultDescription
<f7-text-editor> properties
valuestring

Text editor initial html content value.

placeholderstringEditor placeholder content displayed when it is empty. By default it is not specified
resizablebooleanfalseMakes editor resizable (when its height will fit to its content)
modestringtoolbar

Text editor buttons mode. Can be:

  • toolbar - it will add toolbar with editor buttons in text editor container element
  • popover - it will show popover bubble with editor buttons on top of the selected text in editor
  • keyboard-toolbar - toolbar with editor buttons will appear on top of virtual keyboard when editor is in the focus. It is supported only in iOS, Android cordova apps and in Android Chrome. When not supported it will fallback to popover mode.
buttonsarray

Array with editor buttons, or array of arrays (groups) with editor buttons. By default all buttons enabled and its default value is:

[
  ['bold', 'italic', 'underline', 'strikeThrough'],
  ['orderedList', 'unorderedList'],
  ['link', 'image'],
  ['paragraph', 'h1', 'h2', 'h3'],
  ['alignLeft', 'alignCenter', 'alignRight', 'alignJustify'],
  ['subscript', 'superscript'],
  ['indent', 'outdent'],
]
dividersbooleantrueAdds visual divider between buttons group
image-url-textstringInsert image URLPrompt text that appears on image url request
link-url-textstringInsert link URLPrompt text that appears on link url request
clear-formatting-on-pastebooleantrueWhen enabled it will clear any formatting on paste from clipboard
custom-buttonsobject

Object with custom buttons. Object property key is the button id that should be used in buttons to enable it.

For example to specify custom button that will add <hr> we can use following declaration:

<f7-text-editor
  :custom-buttons="customButtons"
  :buttons="buttons"
/>
{
  customButtons: {
    // property key is the button id
    hr: {
      // button html content
      content: '&lt;hr&gt;',
      // button click handler
      onClick(event, buttonEl) {
        document.execCommand('insertHorizontalRule', false);
      }
    }
  },
  // now we use custom button id "hr" to add it to buttons
  buttons: ['bold', 'italic', 'hr']
}

Text Editor Events

EventArgumentsDescription
<f7-text-editor> events
texteditor:change(value)Event will be triggered when editor value has been changed
texteditor:inputEvent will be triggered on editor's content "input" event
texteditor:focusEvent will be triggered on editor's content focus
texteditor:blurEvent will be triggered on editor's content blur
texteditor:buttonclick(buttonId)Event will be triggered on editor button click
texteditor:keyboardopenEvent will be triggered when editor keyboard toolbar appears
texteditor:keyboardcloseEvent will be triggered when editor keyboard toolbar disappears
texteditor:popoveropenEvent will be triggered on editor popover open
texteditor:popovercloseEvent will be triggered on editor popover close
texteditor:beforedestroyEvent will be triggered right before Text Editor instance will be destroyed

Access To Text Editor Instance

If you need to use Text Editor API you can access its initialized instance by accessing .f7TextEditor component's property.

Examples

<template>
  <f7-page>
    <f7-navbar title="Text Editor"></f7-navbar>

    <f7-block-title>Default Setup</f7-block-title>
    <f7-text-editor />

    <f7-block-title>With Placeholder</f7-block-title>
    <f7-text-editor
      placeholder="Enter text..."
    />

    <f7-block-title>With Default Value</f7-block-title>
    <f7-text-editor
      placeholder="Enter text..."
      :value="customValue"
      @texteditor:change="(v) => customValue = v"
    />

    <f7-block-title>Specific Buttons</f7-block-title>
    <f7-block-header>It is possible to customize which buttons (commands) to show.</f7-block-header>
    <f7-text-editor
      placeholder="Enter text..."
      :buttons="[
        ['bold', 'italic', 'underline', 'strikeThrough'],
        ['orderedList', 'unorderedList']
      ]"
    />

    <f7-block-title>Custom Button</f7-block-title>
    <f7-block-header>It is possible to create custom editor buttons. Here is the custom "hr" button that adds horizontal rule:</f7-block-header>
    <f7-text-editor
      placeholder="Enter text..."
      :customButtons="customButtons"
      :buttons="[
        ['bold', 'italic', 'underline', 'strikeThrough'],
        'hr'
      ]"
    />

    <f7-block-title>Resizable</f7-block-title>
    <f7-block-header>Editor will be resized based on its content.</f7-block-header>
    <f7-text-editor
      placeholder="Enter text..."
      resizable
      :buttons="['bold', 'italic', 'underline', 'strikeThrough']"
    />

    <f7-block-title>Popover Mode</f7-block-title>
    <f7-block-header>In this mode, there is no toolbar with buttons, but they appear as popover when you select any text in editor.</f7-block-header>
    <f7-text-editor
      placeholder="Enter text..."
      mode="popover"
      :buttons="['bold', 'italic', 'underline', 'strikeThrough']"
      style="--f7-text-editor-height: 150px"
    />

    <f7-block-title>Keyboard Toolbar Mode</f7-block-title>
    <f7-block-header>In this mode, toolbar with buttons will appear on top of virtual keyboard when editor is in the focus. It is supported only in iOS, Android cordova apps and in Android Chrome. When not supported it will fallback to "popover" mode.</f7-block-header>
    <f7-text-editor
      placeholder="Enter text..."
      mode="keyboard-toolbar"
      style="--f7-text-editor-height: 150px"
    />

    <f7-block-title>As List Input</f7-block-title>
    <f7-block-header>Text editor can be used in list with other inputs. In this example it is enabled with "keyboard-toolbar"/"popover" type for "About" field.</f7-block-header>
    <f7-list>
      <f7-list-input
        type="text"
        label="Name"
        placeholder="Your name"
      />
      <f7-list-input
        type="texteditor"
        label="About"
        placeholder="About"
        resizable
        :textEditorParams="{
          mode: 'popover',
          buttons: ['bold', 'italic', 'underline', 'strikeThrough']
        }"
        :value="listEditorValue"
        @texteditor:change="(value) => listEditorValue = value"
      />
    </f7-list>
  </f7-page>
</template>
<script>
  export default {
    data() {
      return {
        customButtons: {
          hr: {
            content: '&lt;hr&gt;',
            onClick(editor, buttonEl) {
              document.execCommand('insertHorizontalRule', false);
            },
          },
        },
        customValue: '<p>Lorem, ipsum dolor sit amet ...</p>',
        listEditorValue: '',
      }
    },
  };
</script>