grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

[Question] - How we can hide RTE for editable components ?

Open pankajsharma89 opened this issue 5 years ago • 5 comments

HI We have a requirement, where we don't want to show rte on editable components. how we can achieve that ?

pankajsharma89 avatar Jul 22 '21 08:07 pankajsharma89

editor.on('component:selected', cmp => {
  cmp.set({
   editable: false,
   propagate: ['editable']
 })
})

iabhiyaan avatar Jul 25 '21 07:07 iabhiyaan

We don't want to make component non editable, component needs to be editable, we just don't want to show rte tool bar on that component.

pankajsharma89 avatar Jul 25 '21 07:07 pankajsharma89

You can try on these codes

 editor.setCustomRte({
    disable: function(el, rte) {
      el.contentEditable = false;
      if (rte && rte.focusManager) {
        rte.focusManager.blur(true);
      }
    }
  });

iabhiyaan avatar Jul 25 '21 08:07 iabhiyaan

You can also extend the Text component View and change onActive method

editor.Components.addType('text', {
  view: {
    onActive() {} // do nothing
  }
});

artf avatar Jul 31 '21 12:07 artf

I allow myself to add what I think might be closer to what OP's trying to achieve, from @artf's answer:

editor.DomComponents.addType('text', {
    extendFnView: ['onActive'],
    model: {
      defaults: {       
        disableRte: false
      }
    },
    view: {
      onActive() {
        if (this.model.get('disableRte')) {
          this.rte.getToolbarEl().style.display = 'none';
        }
      }
    }
}

Toggling the disableRte property allows to hide the RTE toolbar, while keeping the text editable, on a per-component basis.

Hope this helps :)

mcottret avatar Oct 29 '21 14:10 mcottret