Skip to content

Commit

Permalink
Bind Editable wrapper to class
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Aug 7, 2019
1 parent 67e52a2 commit a412bb3
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/rich-text/src/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class RichText extends Component {
this.valueToEditableHTML = this.valueToEditableHTML.bind( this );
this.onPointerDown = this.onPointerDown.bind( this );
this.formatToValue = this.formatToValue.bind( this );
this.Editable = this.Editable.bind( this );

this.onKeyDown = ( event ) => {
this.handleDelete( event );
Expand Down Expand Up @@ -874,24 +875,19 @@ class RichText extends Component {
return toHTMLString( { value, multilineTag } );
}

render() {
Editable( props ) {
const {
tagName: Tagname = 'div',
style,
className,
placeholder,
__unstableIsSelected: isSelected,
children,
allowedFormats,
withoutInteractiveFormatting,
} = this.props;

// Generating a key that includes `tagName` ensures that if the tag
// changes, we replace the relevant element. This is needed because we
// prevent Editable component updates.
const key = Tagname;

const EditableWrapper = ( props ) => (
return (
<Editable
{ ...props }
tagName={ Tagname }
Expand Down Expand Up @@ -920,6 +916,15 @@ class RichText extends Component {
onTouchEnd={ this.onSelectionChange }
/>
);
}

render() {
const {
__unstableIsSelected: isSelected,
children,
allowedFormats,
withoutInteractiveFormatting,
} = this.props;

return (
<>
Expand All @@ -933,9 +938,9 @@ class RichText extends Component {
isSelected,
value: this.record,
onChange: this.onChange,
Editable: EditableWrapper,
Editable: this.Editable,
} ) }
{ ! children && <EditableWrapper /> }
{ ! children && <this.Editable /> }
</>
);
}
Expand Down

0 comments on commit a412bb3

Please sign in to comment.