ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

Integrating custom dropdown list in ckeditor5 not working

Open premsanth-rajamani opened this issue 7 years ago • 6 comments

💻 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

Screenshot 2019-04-10 at 4 57 05 PM

❎ Actual result

Screenshot 2019-04-10 at 4 59 11 PM

📃 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;
});

} }`

premsanth-rajamani avatar Apr 10 '19 11:04 premsanth-rajamani

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 ;)

jodator avatar Apr 10 '19 12:04 jodator

Oh!!!!.. that's it you saved my hours of research and exhaustion.. Thanks a lot Jodator..

premsanth-rajamani avatar Apr 10 '19 14:04 premsanth-rajamani

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 .....

Syfele avatar Nov 26 '21 13:11 Syfele

where we can add this line? editor.ui.componentFactory.add( "InsertDropDown", ... );

alimughal007 avatar Jul 13 '23 13:07 alimughal007

@alimughal007 usually this line is added to a plugin that is later on added to an editor during initialization.

Witoso avatar Jul 17 '23 07:07 Witoso

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

codeonprod avatar Aug 20 '24 11:08 codeonprod