Issue #1999Opened May 6, 2019by acamenhas0 reactions

Trait extends

Question

Hi,

I need to extends the video type, just to add a new trait/property: muted There is any documentation that can tell me how can i extend an existing type?

Thanks

Answers (3)

artfMay 11, 20190 reactions

To learn more about how to extend components start from here: https://grapesjs.com/docs/modules/Components.html

The problem with the Video Component that its traits are handled a bit differently so in this case, I'd suggest looking at its source to get a better idea of how they work, but I think at the end this will work for you:

const dc = editor.DomComponents;
dc.addType('video', {
	extendFn: ['updateTraits'],
	model: {
		init() {
			this.addMutedTrait();
		},

		updateTraits() {
			this.addMutedTrait();
		},

		addMutedTrait() {
			if (!this.getTrait('muted')) {
				this.addTrait({
					type: 'checkbox',
					name: 'muted',
				})
			}
		},
	},
})
lock[bot]May 21, 20200 reactions

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot]May 21, 20200 reactions

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.