Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Add text directionality override prop to DraftEditor #1034

Merged
merged 3 commits into from
Mar 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/component/base/DraftEditor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
/>
</div>
</div>
Expand Down Expand Up @@ -355,8 +356,8 @@ class DraftEditor extends React.Component {
this.update(
EditorState.forceSelection(
editorState,
editorState.getSelection()
)
editorState.getSelection(),
),
);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/component/base/DraftEditorProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 8 additions & 4 deletions src/component/contents/DraftEditorContents.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Props = {
blockRendererFn: Function,
blockStyleFn: (block: ContentBlock) => string,
editorState: EditorState,
textDirectionality?: BidiDirection,
};

/**
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -161,7 +165,7 @@ class DraftEditorContents extends React.Component {
);
className = joinClasses(
className,
getListItemClasses(blockType, depth, shouldResetCount, direction)
getListItemClasses(blockType, depth, shouldResetCount, direction),
);
}

Expand Down Expand Up @@ -221,7 +225,7 @@ class DraftEditorContents extends React.Component {
key: info.key + '-wrap',
'data-offset-key': info.offsetKey,
},
blocks
blocks,
);
outputBlocks.push(wrapperElement);
} else {
Expand All @@ -244,7 +248,7 @@ function getListItemClasses(
type: string,
depth: number,
shouldResetCount: boolean,
direction: BidiDirection
direction: BidiDirection,
): string {
return cx({
'public/DraftStyleDefault/unorderedListItem':
Expand Down