Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a custom blot with button on toolbar opens a strange popup (v1.3.6) #4359

Closed
64jcl opened this issue Aug 6, 2024 · 1 comment
Closed

Comments

@64jcl
Copy link

64jcl commented Aug 6, 2024

So I created the simplest blot to insert a HR based on code examples I found, added it too my toolbar (and styled its appearance using css). This works fine but when I click the button a strange popup asks me to write the name of the blot in order for it to actually add the HR tag. I also tried adding my own click listener but that seems then to be called after this popup is shown. I have tried debugging and it seems to come from the quilljs handler that it adds to this button for some reason.

	class Divider extends BlockEmbed {
		static blotName = 'divider';
		static tagName = 'hr';
	}
	Quill.register(Divider);

Here is an image of the popup that it shows.

image

@64jcl
Copy link
Author

64jcl commented Aug 6, 2024

Ok I found the solution to this here:

https://stackoverflow.com/questions/37525867/how-can-i-add-a-new-format-hr-tag-to-quill-js

From that I learned that you can add a custom handler for a toolbar button like this (assuming this.quill is the quill instance):

const tb = this.quill.getModule('toolbar');
tb.addHandler('divider', this.dividerHandler.bind(this));

and then in my dividerhandler I have this:

dividerHandler() {
	const range = this.quill.getSelection(true);
	this.quill.insertText(range.index, '\n', Quill.sources.USER);
	this.quill.insertEmbed(range.index + 1, 'divider', true, Quill.sources.USER);
	this.quill.setSelection(range.index + 2, Quill.sources.SILENT);
}

@64jcl 64jcl closed this as completed Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant