Integrating custom dropdown list in ckeditor5 not working
💻 CKEditor - 5
I'm not able to add a new dropdown list menu toolbar within ckeditor5.
I have used exactly what is mentioned in their documentation, not sure what am i missing.
The editor loads but, not the dropdown plugin. I have tried adding custom buttons within editor and it worked, but integrating dropdown is not working.
This is the link i used as reference, https://ckeditor.com/docs/ckeditor5/latest/framework/guides/architecture/ui-library.html#adding-a-list-to-a-dropdown
✅ Expected result
❎ Actual result
📃 Other details that might be useful
This is the code i used, `//-- file 1 --// // import InsertDropDown from "../libraries/dropDownButton";
export function loadEditor(){ const promise = ClassicEditor.create(editor, { extraPlugins: [InsertDropDown], toolbar: [ "bold", "italic", "heading", "bulletedList", "numberedList", "link", "undo", "redo" ] }); return promise; }
//-- file 2 --//
import Plugin from "@ckeditor/ckeditor5-core/src/plugin"; import Model from "@ckeditor/ckeditor5-ui/src/model"; import Collection from "@ckeditor/ckeditor5-utils/src/collection"; import { addListToDropdown, createDropdown } from "@ckeditor/ckeditor5-ui/src/dropdown/utils"; import SplitButtonView from "@ckeditor/ckeditor5-ui/src/dropdown/button/splitbuttonview"; import imageIcon from "../libraries/svg/user.svg";
export default class InsertDropDown extends Plugin { init() { const editor = this.editor; editor.ui.componentFactory.add("InsertDropDown", locale => { const dropdownView = createDropdown(locale, SplitButtonView); dropdownView.buttonView.actionView.set({ withText: true, label: "choose variable", icon: imageIcon, tooltip: true });
const items = new Collection();
items.add({
type: "button",
model: new Model({
withText: true,
label: "Foo"
})
});
items.add({
type: "button",
model: new Model({
withText: true,
label: "Bar"
})
});
addListToDropdown(dropdownView, items);
return dropdownView;
});
} }`
You must add it to the toolbar configuration also:
// ...
ClassicEditor.create(editor, {
extraPlugins: [InsertDropDown],
toolbar: [
"bold",
"italic",
"heading",
"bulletedList",
"numberedList",
"link",
"undo",
"redo",
"InsertDropDown" // <--- add this
]
} );
// ...
The name of component should match the add() call:
editor.ui.componentFactory.add( "InsertDropDown", ... );
ps.: we'd use insertDropdown name for our compoent or even dynamicFields but this is of course up to you ;)
Oh!!!!.. that's it you saved my hours of research and exhaustion.. Thanks a lot Jodator..
I just want to do the same thing and changing items.add with my list But I fail and I have this error ClassicEditor is not defined
When I try it with import ClassicEditor from '@ckeditor/ckeditor5-build-classic'; or import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'; I have : ckeditorerror.js:64 Uncaught CKEditorError: ckeditor-duplicated-modules I have read the link CKEditor duplicated modules But still not understanding what going wrong I m usin the last version of CK and I installed it with yarn yarn add ckeditor5 Idem pour core, ui, utils .....
where we can add this line? editor.ui.componentFactory.add( "InsertDropDown", ... );
@alimughal007 usually this line is added to a plugin that is later on added to an editor during initialization.
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
Instead of this, import from ckeditor5 as below:
import { ClassicEditor } from 'ckeditor5';
Infact, try to import everything from ckeditor5