Search code examples
javascriptquill

Is it possible to display toolbar options below textarea in Quilljs editor?


How to display toolbar below textarea.

My code:

var quill = new Quill('#txtMessage', {
  theme: 'snow',
  modules: {
    toolbar: {
      container: [
        ['bold', 'italic', 'underline'],
        [{
          'list': 'ordered'
        }, {
          'list': 'bullet'
        }],
        ['clean'],
        ['code-block'],
        [{
          'variables': ['{Name}', '{Email}']
        }],
      ],
      handlers: {
        "variables": function(value) {
          if (value) {
            const cursorPosition = this.quill.getSelection().index;
            this.quill.insertText(cursorPosition, value);
            this.quill.setSelection(cursorPosition + value.length);
          }
        }
      }
    }
  }
});

// Variables
const placeholderPickerItems = Array.prototype.slice.call(document.querySelectorAll('.ql-variables .ql-picker-item'));
placeholderPickerItems.forEach(item => item.textContent = item.dataset.value);
document.querySelector('.ql-variables .ql-picker-label').innerHTML = 'Variables' + document.querySelector('.ql-variables .ql-picker-label').innerHTML;
<script src="//cdn.quilljs.com/1.3.6/quill.js"></script>
<link href="//cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet"/>
<link href="//cdn.quilljs.com/1.3.6/quill.bubble.css" rel="stylesheet"/>

<div id="txtMessage"></div>

Output for the above code: enter image description here

I want output as follows: enter image description here How to accomplish above result.


Solution

  • I can't see why not use only css.

    Something like this:

    var quill = new Quill('#editor-container', {
      modules: {
        toolbar: [
          [{
            header: [1, 2, false]
          }],
          ['bold', 'italic', 'underline'],
          ['image', 'code-block']
        ]
      },
      placeholder: 'Compose an epic...',
      theme: 'snow' // or 'bubble'
    });
    #editor-container {
      height: 375px;
    }
    
    .editor-wrapper {
      position: relative;
    }
    
    .ql-toolbar {
      position: absolute;
      bottom: 0;
      width: 100%;
      transform: translateY(100%);
    }
    <script src="//cdn.quilljs.com/1.3.6/quill.js"></script>
    <link href="//cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet"/>
    <link href="//cdn.quilljs.com/1.3.6/quill.bubble.css" rel="stylesheet"/>
    <div class="editor-wrapper">
      <div id="editor-container">
      </div>
    </div>

    https://codepen.io/moshfeu/pen/wXwqmg