Ask A Question

Notifications

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

Reply

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.

Reply
Join the discussion
Create an account Log in

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

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

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

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

    © 2023 GoRails, LLC. All rights reserved.