question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to add a custom dropdown aka picker to the quill toolbar?

See original GitHub issue

Okay so I spent quite some time researching this question and trying various solutions - without success.

How can I add my custom dropdown menu (aka “picker”) to the quill toolbar?

Here are some - all non-working - approaches I tried so far:

1. Using HTML

<div id="toolbar">
	<select class="ql-myDropdown">
		<option value="1">Option 1</option>
		<option value="2">Option 2</option>
		<option value="3">Option 3</option>
		<option value="4">Option 4</option>
		<option value="5">Option 5</option>
	</select>
</div>
<div id="editor">
</div>

2. Using JavScript in a new Quill instance

var quill = new Quill('#editor', {
    modules: {
        toolbar:
        [
          [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
          [{ 'size': ['small', false, 'large', 'huge'] }],
          ['bold', 'italic', 'underline', 'strike',],
          [{ 'myDropdown': ['Option 1', 'Option 2', 'Option 3', 'Option 4', 'Option 5'] }],
    	  ['clean']
        ]
    },
    theme: 'snow'
});

3. Using a quill import

var myDropdown = quill.import('ui/picker');
myDropdown = ['Option 1', 'Option 2', 'Option 3', 'Option 4', 'Option 5'];
quill.register(myDropdown, true);

While 2. is the most promising solution - as it does add a picker at the right place and inside Quill; but the heck - it’s just an empty dropdown list?

quill toolbar custom dropdown struggles

So honestly I think it would be great, if adding custom dropdowns to Quill would also be explicitely covered in the quill docs. Same as for regular click-buttons.

Thanks for any help! Oliver

P.s. a related question has been closed without any insights #1543

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:13

github_iconTop GitHub Comments

28reactions
oliveratgithubcommented, Nov 13, 2017

So a good soul @quannt over here provided me a jsfiddle demonstrating, what one needs in order to add a custom dropdown picker in Quill: https://jsfiddle.net/q7jferw3/

Basically quilljs can create the dropdown list for you but you need to manually supply the HTML content (which is not the clearest thing in the world)

Thanks again!!

17reactions
RockStanleycommented, Jun 7, 2018

Quill uses CSS pseudo class to specify content for each toolbar dropdown menu, so do the menu label.

For example:

/* static label */
.ql-picker.ql-customoption .ql-picker-label:before {
    content: "Select Language";     /* never changes its content as this menu's label changes */
}
/* dynamic label */
.ql-picker.ql-customoption .ql-picker-label:before[data-value="en"]:before {
    content: "English";
}
/* options */
.ql-picker.ql-customoption .ql-picker-item[data-value="en"]:before {
    content: "English";
}
.ql-picker.ql-customoption .ql-picker-item[data-value="zh"]:before {
    content: "中文";
}
/* you need to specify rules as many as your options */

then for the easy part, define the handler:

new Quill(selector, {
  modules: {
    toolbar: {
      /* ... */
      handlers: {
        'customoption': function(lang: string) {
          /* do something with lang */
        }
      }
    }
  }
}

addition: maybe you need to manually specify a padding for the picker label, otherwise it will overlap the pseudo class content.

.ql-picker.ql-customoption .ql-picker-label {
    padding-right: 18px;
}

I traced through the source code to derive this solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot Get Custom Dropdown to Work in QuillJS Editor
Any help would be appreciated. Ideally, I want the dropdown to show up in the toolbar and add the select option text as...
Read more >
Adding a custom drop-down toolbar to react-quill
It is surprisingly unintuitive to add a custom drop-down toolbar to `quilljs`. ... 'react-quill/dist/quill.snow.css'; import ReactQuill from 'react-quill'; ...
Read more >
Toolbar Module - Quill Rich Text Editor
Quill is a free, open source WYSIWYG editor built for the modern web. Completely customize it for any need with its modular architecture...
Read more >
Add Custom Button In Footer Ngx-Quill - ADocLib
How to add a custom dropdown aka picker to the quill toolbar ? hot 2. quill npm install quill emoji Configure for CSS...
Read more >
A look at Quill.js
Quill provides a simple framework for adding buttons to your toolbars just add them to your toolbar configuration and style them with css,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found