Text Direction

Adds a toolbar button for block text direction (left-to-right or right-to-left). Sets the dir attribute on editable blocks in the selection. Not available for code (pre) blocks.

Select a paragraph, click RTL-LTR in the toolbar (after Format), and choose Left to Right or Right to Left.

Load the bundle

<script src="/assets/redactor/redactor.js"></script>
<script src="/assets/redactor/plugins/text-direction/text-direction.js"></script>

Initialization

const app = Redactor('#entry', {
    plugins: ['textDirection']
});

Options

  • context (boolean)
    • default false
    • When true, adds the direction button to the context toolbar as well.
  • icon (string)
    • SVG icon HTML for the toolbar button.
Redactor('#entry', {
    plugins: ['textDirection'],
    textDirection: {
        context: false
    }
});

Language strings

en: {
    textDirection: {
        title: 'RTL-LTR',
        ltr: 'Left to Right',
        rtl: 'Right to Left'
    }
}

Events

This plugin does not emit events.

API

set

Applies text direction to editable block(s) in the selection and closes the dropdown. When the chosen direction matches the editor dir option, the dir attribute is removed from the block.

Parameters:

  • dir (string) — 'ltr' or 'rtl'.
app.textDirection.set({ dir: 'rtl' });