Skip to content

Commit 5677482

Browse files
committed
Add option to ignore editor tab key handling
1 parent 2af7eef commit 5677482

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ It accepts these props for styling:
109109
|Name|PropType|Description|
110110
|---|---|---|
111111
|className|PropTypes.string|An additional class that is added to the Content Editable
112+
|ignoreTabKey|PropTypes.bool|Makes the editor ignore tab key presses so that keyboard users can tab past the editor without getting stuck
112113
|style|PropTypes.object|Additional styles for the Content Editable
113114

114115
This component renders a Prism.js editor underneath it and also renders all of Prism’s

src/components/Editor/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Editor extends Component {
102102
if (this.props.onKeyDown) {
103103
this.props.onKeyDown(evt)
104104
}
105-
if (evt.keyCode === 9) { // Tab Key
105+
if (evt.keyCode === 9 && !this.props.ignoreTabKey) { // Tab Key
106106
document.execCommand('insertHTML', false, '&#009')
107107
evt.preventDefault()
108108
} else if (evt.keyCode === 13) { // Enter Key

typings/react-live.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export function LiveEditor(props: HTMLAttributes<HTMLElement>): JSX.Element
1515
export function LiveError(props: HTMLAttributes<HTMLElement>): JSX.Element
1616
export function LivePreview(props: HTMLAttributes<HTMLElement>): JSX.Element
1717

18-
export class Editor extends Component<HTMLAttributes<HTMLElement>, {}>{}
18+
export type EditorProps = HTMLAttributes<HTMLElement> & {
19+
ignoreTabKey?: boolean;
20+
}
21+
22+
export class Editor extends Component<EditorProps, {}>{}
1923

2024
export function withLive<T>(wrappedComponent: T): Component<any, {}>

0 commit comments

Comments
 (0)