Skip to content

Commit 554eee8

Browse files
committed
#277 - Fix for crashing on enter in RichText control
1 parent ea70d8d commit 554eee8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/controls/richText/RichText.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Icon } from 'office-ui-fabric-react/lib/Icon';
1717
import { elementContains } from 'office-ui-fabric-react/lib/Utilities';
1818
import * as telemetry from '../../common/telemetry';
1919
import { initializeIcons } from 'office-ui-fabric-react/lib/Icons';
20+
import isEqual = require('lodash/isEqual');
2021

2122

2223
const TOOLBARPADDING: number = 28;
@@ -178,6 +179,21 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
178179
}
179180
}
180181

182+
/**
183+
* shouldComponentUpdate lifecycle hook
184+
*
185+
* @param nextProps
186+
* @param nextState
187+
*/
188+
public shouldComponentUpdate(nextProps: IRichTextProps, nextState: IRichTextState): boolean {
189+
// Checks if the value coming in is the same
190+
if (isEqual(nextState, this.state)) {
191+
return false;
192+
}
193+
194+
return true;
195+
}
196+
181197
/**
182198
* Returns a handle to the Quill editor
183199
*/

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
319319
<DateTimePicker label="DateTime Picker (unspecified = date and time)" value={new Date()} onChange={(value) => console.log("DateTimePicker value:", value)} />
320320
<DateTimePicker label="DateTime Picker (unspecified = date and time)" timeConvention={TimeConvention.Hours24} value={new Date()} onChange={(value) => console.log("DateTimePicker value:", value)} />
321321

322-
<RichText isEditMode={this.props.displayMode === DisplayMode.Edit} onChange={value => { this.richTextValue = value; return value; }} />
322+
{/* <RichText isEditMode={this.props.displayMode === DisplayMode.Edit} onChange={value => { this.richTextValue = value; return value; }} /> */}
323+
<RichText isEditMode={this.props.displayMode === DisplayMode.Edit} onChange={value => { this.setState({richTextValue: value}); return value; }} />
323324

324325
<ListItemAttachments listId='0ffa51d7-4ad1-4f04-8cfe-98209905d6da'
325326
itemId={1}

0 commit comments

Comments
 (0)