diff --git a/src/component/base/DraftEditor.react.js b/src/component/base/DraftEditor.react.js index 33b84db7aa..a2732d706f 100644 --- a/src/component/base/DraftEditor.react.js +++ b/src/component/base/DraftEditor.react.js @@ -283,6 +283,7 @@ class DraftEditor extends React.Component { editorKey={this._editorKey} editorState={this.props.editorState} key={'contents' + this.state.contentsKey} + textDirectionality={this.props.textDirectionality} /> @@ -355,8 +356,8 @@ class DraftEditor extends React.Component { this.update( EditorState.forceSelection( editorState, - editorState.getSelection() - ) + editorState.getSelection(), + ), ); } } diff --git a/src/component/base/DraftEditorProps.js b/src/component/base/DraftEditorProps.js index 0ccded7219..d0f327cfbc 100644 --- a/src/component/base/DraftEditorProps.js +++ b/src/component/base/DraftEditorProps.js @@ -12,6 +12,7 @@ 'use strict'; +import type {BidiDirection} from 'UnicodeBidiDirection'; import type ContentBlock from 'ContentBlock'; import type {DraftBlockRenderMap} from 'DraftBlockRenderMap'; import type {DraftDragType} from 'DraftDragType'; @@ -42,6 +43,10 @@ export type DraftEditorProps = { // regardless of input characters. textAlignment?: DraftTextAlignment, + // Specify whether text directionality should be forced in a direction + // regardless of input characters. + textDirectionality?: BidiDirection, + // For a given `ContentBlock` object, return an object that specifies // a custom block component and/or props. If no object is returned, // the default `TextEditorBlock` is used. diff --git a/src/component/contents/DraftEditorContents.react.js b/src/component/contents/DraftEditorContents.react.js index 1066de85c6..6ead414019 100644 --- a/src/component/contents/DraftEditorContents.react.js +++ b/src/component/contents/DraftEditorContents.react.js @@ -29,6 +29,7 @@ type Props = { blockRendererFn: Function, blockStyleFn: (block: ContentBlock) => string, editorState: EditorState, + textDirectionality?: BidiDirection, }; /** @@ -123,7 +124,10 @@ class DraftEditorContents extends React.Component { customEditable = customRenderer.editable; } - const direction = directionMap.get(key); + const {textDirectionality} = this.props; + const direction = textDirectionality + ? textDirectionality + : directionMap.get(key); const offsetKey = DraftOffsetKey.encode(key, 0, 0); const componentProps = { contentState: content, @@ -161,7 +165,7 @@ class DraftEditorContents extends React.Component { ); className = joinClasses( className, - getListItemClasses(blockType, depth, shouldResetCount, direction) + getListItemClasses(blockType, depth, shouldResetCount, direction), ); } @@ -221,7 +225,7 @@ class DraftEditorContents extends React.Component { key: info.key + '-wrap', 'data-offset-key': info.offsetKey, }, - blocks + blocks, ); outputBlocks.push(wrapperElement); } else { @@ -244,7 +248,7 @@ function getListItemClasses( type: string, depth: number, shouldResetCount: boolean, - direction: BidiDirection + direction: BidiDirection, ): string { return cx({ 'public/DraftStyleDefault/unorderedListItem':