🔥 Meet Our New Project: t0ggles - Your Ultimate Project Management Tool!

Text Editor Svelte Component

Text Editor Svelte component represents Text Editor component.

Text Editor Components

There are following components included:

Text Editor Properties

<TextEditor> properties

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)

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.

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
imageUrlTextstringInsert image URLPrompt text that appears on image url request
linkUrlTextstringInsert link URLPrompt text that appears on link url request
clearFormattingOnPastebooleantrueWhen enabled it will clear any formatting on paste from clipboard

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:

    // property key is the button id
    hr: {
      // button html content
      content: '&lt;hr&gt;',
      // button click handler
      onClick(event, buttonEl) {
        document.execCommand('insertHorizontalRule', false);
  buttons={['bold', 'italic', 'hr']}

Text Editor Events

<TextEditor> events
textEditorChange(value)Event will be triggered when editor value has been changed
textEditorInputEvent will be triggered on editor's content "input" event
textEditorFocusEvent will be triggered on editor's content focus
textEditorBlurEvent will be triggered on editor's content blur
textEditorButtonClick(buttonId)Event will be triggered on editor button click
textEditorKeyboardOpenEvent will be triggered when editor keyboard toolbar appears
textEditorKeyboardCloseEvent will be triggered when editor keyboard toolbar disappears
textEditorPopoverOpenEvent will be triggered on editor popover open
textEditorPopoverCloseEvent will be triggered on editor popover close
textEditorBeforeDestroyEvent 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 calling .instance() component's method. For example:

<TextEditor bind:this={component}>...</TextEditor>

  let component;

  // to get instance in some method


  import {
  } from 'framework7-svelte';

  const customButtons = {
    hr: {
      content: '<hr>',
      // eslint-disable-next-line
      onClick(editor, buttonEl) {
        document.execCommand('insertHorizontalRule', false);

  let customValue = `<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Consequatur sunt, sapiente quis eligendi consectetur hic asperiores assumenda quidem dolore quasi iusto tenetur commodi qui ullam sint sed alias! Consequatur, dolor!</p>
      <p>Provident reiciendis exercitationem reprehenderit amet repellat laborum, sequi id quam quis quo quos facere veniam ad libero dolorum animi. Nobis, illum culpa explicabo dolorem vitae ut dolor at reprehenderit magnam?</p>
      <p>Qui, animi. Dolores dicta, nobis aut expedita enim eum assumenda modi, blanditiis voluptatibus excepturi non pariatur. Facilis fugit facere sequi molestias nemo in, suscipit inventore consequuntur, repellat perferendis, voluptas odit.</p>
      <p>Tempora voluptates, doloribus architecto eligendi numquam facilis perspiciatis autem quam voluptas maxime ratione harum laudantium cum deleniti. In, alias deserunt voluptatibus eligendi libero nobis est unde et perspiciatis cumque voluptatum.</p>
      <p>Quam error doloribus qui laboriosam eligendi. Aspernatur quam pariatur perspiciatis reprehenderit atque dicta culpa, aut rem? Assumenda, quibusdam? Reprehenderit necessitatibus facere nemo iure maiores porro voluptates accusamus quibusdam. Nesciunt, assumenda?</p>`;

  let listEditorValue = '';

  <Navbar title="Text Editor" />

      Framework7 comes with a touch-friendly Rich Text Editor component. It is based on modern
      "contenteditable" API so it should work everywhere as is.
      It comes with the basic set of formatting features. But its functionality can be easily
      extended and customized to fit any requirements.

  <BlockTitle>Default Setup</BlockTitle>
  <TextEditor />

  <BlockTitle>With Placeholder</BlockTitle>
  <TextEditor placeholder="Enter text..." />

  <BlockTitle>With Default Value</BlockTitle>
    placeholder="Enter text..."
    onTextEditorChange={(value) => (customValue = value)}

  <BlockTitle>Specific Buttons</BlockTitle>
  <BlockHeader>It is possible to customize which buttons (commands) to show.</BlockHeader>
    placeholder="Enter text..."
      ['bold', 'italic', 'underline', 'strikeThrough'],
      ['orderedList', 'unorderedList'],

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

  <BlockHeader>Editor will be resized based on its content.</BlockHeader>
    placeholder="Enter text..."
    buttons={['bold', 'italic', 'underline', 'strikeThrough']}

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

  <BlockTitle>Keyboard Toolbar Mode</BlockTitle>
    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.
    placeholder="Enter text..."
    style="--f7-text-editor-height: 150px"

  <BlockTitle>As List Input</BlockTitle>
    Text editor can be used in list with other inputs. In this example it is enabled with
    "keyboard-toolbar"/"popover" type for "About" field.
  <List strongIos dividersIos outlineIos>
    <ListInput type="text" label="Name" placeholder="Your name" />
        mode: 'popover',
        buttons: ['bold', 'italic', 'underline', 'strikeThrough'],
      onTextEditorChange={(value) => (listEditorValue = value)}