Skip to content

Commit e5bc31f

Browse files
committed
Add onChange prop to LiveEditor
1 parent 1b8c7c1 commit e5bc31f

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ It accepts these props for styling:
111111
|className|PropTypes.string|An additional class that is added to the Content Editable
112112
|ignoreTabKey|PropTypes.bool|Makes the editor ignore tab key presses so that keyboard users can tab past the editor without getting stuck
113113
|style|PropTypes.object|Additional styles for the Content Editable
114+
|onChange|PropTypes.function|Accepts a callback that is called when the user makes changes
114115

115116
This component renders a Prism.js editor underneath it and also renders all of Prism’s
116117
styles inside a `style` tag.

src/components/Live/LiveEditor.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
import React from 'react'
2+
import PropTypes from 'prop-types'
23
import { LiveContextTypes } from './LiveProvider'
34
import Editor from '../Editor'
45

56
const LiveEditor = (props, { live }) => (
67
<Editor
78
{...props}
89
code={live.code}
9-
onChange={live.onChange}
10+
onChange={code => {
11+
live.onChange(code)
12+
13+
if (typeof props.onChange === 'function') {
14+
props.onChange(code)
15+
}
16+
}}
1017
/>
1118
)
1219

1320
LiveEditor.contextTypes = LiveContextTypes
21+
LiveEditor.propTypes = { onChange: PropTypes.function }
1422

1523
export default LiveEditor
1624

0 commit comments

Comments
 (0)