diff --git a/src/component/base/DraftEditor.react.js b/src/component/base/DraftEditor.react.js index 1136279587..cb5060eb0e 100644 --- a/src/component/base/DraftEditor.react.js +++ b/src/component/base/DraftEditor.react.js @@ -328,6 +328,7 @@ class DraftEditor extends React.Component { customStyleFn, customStyleMap, editorState, + preventScroll, readOnly, textAlignment, textDirectionality, @@ -369,6 +370,7 @@ class DraftEditor extends React.Component { customStyleFn, editorKey: this._editorKey, editorState, + preventScroll, textDirectionality, }; diff --git a/src/component/base/DraftEditorProps.js b/src/component/base/DraftEditorProps.js index bd96b1f344..910db8a83e 100644 --- a/src/component/base/DraftEditorProps.js +++ b/src/component/base/DraftEditorProps.js @@ -76,6 +76,10 @@ export type DraftEditorProps = { // or null if no command should be invoked. keyBindingFn: (e: SyntheticKeyboardEvent<>) => ?string, + // Set whether the editor should prevent scrolling into view on mount + // if it happens offscreen. By default, `false` to match the native behavior. + preventScroll?: boolean, + // Set whether the `DraftEditor` component should be editable. Useful for // temporarily disabling edit behavior or allowing `DraftEditor` rendering // to be used for consumption purposes. diff --git a/src/component/contents/DraftEditorBlock.react.js b/src/component/contents/DraftEditorBlock.react.js index 62e2924dd0..5f04540330 100644 --- a/src/component/contents/DraftEditorBlock.react.js +++ b/src/component/contents/DraftEditorBlock.react.js @@ -49,6 +49,7 @@ type Props = { direction: BidiDirection, forceSelection: boolean, offsetKey: string, + preventScroll?: boolean, selection: SelectionState, startIndent?: boolean, tree: List, @@ -96,6 +97,9 @@ class DraftEditorBlock extends React.Component { * scroll parent. */ componentDidMount(): void { + if (this.props.preventScroll) { + return; + } const selection = this.props.selection; const endKey = selection.getEndKey(); if (!selection.getHasFocus() || endKey !== this.props.block.getKey()) { diff --git a/src/component/contents/DraftEditorContents-core.react.js b/src/component/contents/DraftEditorContents-core.react.js index 39cb1a770c..8ded1dc14f 100644 --- a/src/component/contents/DraftEditorContents-core.react.js +++ b/src/component/contents/DraftEditorContents-core.react.js @@ -36,6 +36,7 @@ type Props = { customStyleMap?: Object, editorKey?: string, editorState: EditorState, + preventScroll?: boolean, textDirectionality?: BidiDirection, }; @@ -132,6 +133,7 @@ class DraftEditorContents extends React.Component { customStyleFn, editorState, editorKey, + preventScroll, textDirectionality, } = this.props; @@ -175,6 +177,7 @@ class DraftEditorContents extends React.Component { direction, forceSelection, offsetKey, + preventScroll, selection, tree: editorState.getBlockTree(key), };