[QUESTION] Selection of custom components not possible from canvas.
Question
Hey,
I tried to figure this out by myself, but I'm feeling I'm going a little bit in circles. So I hope you will have some time to read this through and help me with the problem.
I get an html template with multiple custom component tags => <custom-component-tag></custom-component-tag><custom-component-tag></custom-component-tag><custom-component-tag></custom-component-tag>.
For all of the components I define a new component in grapesjs as described in the documentation. For each component I render just a different view, but I don't manipulate the model, because I want the html to remain the same upon saving.
Even though the components have the following config the selection feature doesn't seem to work with them. An example code can be seen below.
I provided a screen video in which you can see that the component is visible inside the component tree and can be selected from there, but the selection is not possible from the canvas.
PS: This example component which I select in the video is highlighted, but some of the others, have an toolset for dragging etc., but aren't highlighted. This would be the second issue.
private createCustomComponent(editor) {
const comps = editor.DomComponents;
const defaultType = comps.getType('default');
const defaultModel = defaultType.model;
comps.addType('custom-component', {
model: defaultModel.extend({
defaults: Object.assign({}, defaultModel.prototype.defaults, {
removable: true,
draggable: true,
droppable: false,
badgable: true,
stylable: true,
highlightable: true,
copyable: false,
resizable: false,
editable: true,
})
},
{
isComponent: function (el) {
if (el.tagName === 'CUSTOM-COMPONENT-TAG') {
return {type: 'custom-component'};
}
}
}),
// Define the View
view: defaultType.view.extend({
render: function () {
defaultType.view.prototype.render.apply(this, arguments);
const value = document.createElement('div');
this.el.appendChild(value);
console.dir(this.el);
return this;
},
}),
});
}
Thank you in advance :)
Answers (3)
@artf Thank you once again, will debug with this in mind. :)
Hi, I'd say this is the same as #260 so your const value = document.createElement('div'); which is purely a DOM element, without a binded model, is blocking the editor to select its custom-component parent. Solution:
const value = document.createElement('div');
value.style.pointerEvents = 'none';
this.el.appendChild(value);
The highlight is applied via gjs-comp-selected class which uses outline property, so check via inspector what is going on, probably you have some kind of reset property on them (eg. outline: none;)
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1162
[Question]: Editable components in Handlebars rendered template
Hi, I've been using grapes for about a couple of days now. Thanks for the awesome work on this project. I've read through the API docs (hop...
Issue #1875
[QUESTION] ID changes when importing html or passing html in components prop in config.
Hi, I built a component and block that I can drag and drop in the canvas. My issue is that some styles rely on the ID. I know this might no...
Issue #1906
Components & Js - Load Template
Hey, I have a component which has a JS attached to it. Everything is created using the JS. When I drag and drop my block for the first time...
Issue #460
When the component's view modifies the HTML, text components are no longer editable
I'm trying to build a custom component that contains some lorem ipsum text in the content, for editing once it's on the canvas. But I also...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.