New Discussion

Notifications

You’re not receiving notifications from this thread.

How do i can add text-alignment to trix ?

1
Rails

Hello. Im trying to add text-alignment functionnality to a trix rich-text editor in a rails 6 app (its for a blog).

I find somes example on stack overflow or trix github about adding colors, h tags or underline. everything works, but nothing for text align.

From my understanding of trix this, in the javascript file, should work

Trix.config.textAttributes.alignLeft = {
style: { textAlign: "left" },
parser: function(element) {
    return element.style.alignLeft === "left"
},
inheritable: true

and after i add a button in the toolbar with data-trix-attribute="alignLeft"
This format worked for colors or underline but not for text-align.
Im struggling for few days with this issue, if you have any idea dont hesite :-).
thanks a lot

Is it perhaps because textAttributes are inline items and so don't support text alignment?

Also this bit seems wrong: return element.style.alignLeft === "left" as I think you'd be wanting to target element.style.textAlign.

Join the discussion
Create an account Log in

Learning Ruby on Rails? Join our newsletter.

We won't send you spam. Unsubscribe at any time.