Issue #2311๐Ÿ’ฌ AnsweredOpened Oct 6, 2019by gabrielbitencourt0 reactions

Set href for link component

Quick answerby artf

@gabrielbitencourt Link Component doesn't have the href property, so add it directly to attributes

Read full answer below โ†“

Question

Hello guys. I'm trying to modify the native link component, so far I have a modal that opens on the dblclick event and the user may choose between some pre defined links. The problem is, when I have the chosen link I'm not able to set it to the component. It works fine when I type the link in the Trait Manager. Here's the code I tried: domc.addType('link', { view: { events: { dblclick: 'linkModalPicker', }, async linkModalPicker(ev: MouseEvent) { ev.preventDefault(); const ref = modal.open(LinkModalComponent, { width: '70%', height: '70%' }); const link = await ref.afterClosed().pipe(first())...

Answers (3)

artfโ€ข Oct 6, 2019

@gabrielbitencourt Link Component doesn't have the href property, so add it directly to attributes

if (link) {
	this.model.addAttributes({ href: link.url });
}
gabrielbitencourtโ€ข Oct 6, 2019

thank you for the response @artf I tried that but it didn't work either, I could see (in the trait manager) that the href had been set using model.addAttributes({ href: link.url }) but it did not persist when I deselected and selected the component again, neither in the resulting editor.getHtml() t...

artfโ€ข Oct 6, 2019

but it did not persist when I deselected and selected the component again

maybe because you're still reading from this.model.get('href')... btw I can't help you more than this without a reproducible demo

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

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins โ†’
Premium option

Premium plugins ship with support, regular updates, and production-ready features โ€” save days of integration work.

Browse premium plugins โ†’

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.