All threads / How do i can add text-alignment to trix ?
Ask A Question


You’re not receiving notifications from this thread.

How do i can add text-alignment to trix ?

Bourquardez Joachim asked in 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 === "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

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 68,099+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.