Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Nov 11, 2019
1 parent cdfb88f commit ba7fb6a
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions packages/rich-text/src/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,35 @@ const INSERTION_INPUT_TYPES_TO_IGNORE = new Set( [
'insertLink',
] );

// In HTML, leading and trailing spaces are not visible, and multiple spaces
// elsewhere are visually reduced to one space. This rule prevents spaces from
// collapsing so all space is visible in the editor and can be removed. It also
// prevents some browsers from inserting non-breaking spaces at the end of a
// line to prevent the space from visually disappearing. Sometimes these non
// breaking spaces can linger in the editor causing unwanted non breaking spaces
// in between words. If also prevent Firefox from inserting a trailing `br` node
// to visualise any trailing space, causing the element to be saved.
//
// > Authors are encouraged to set the 'white-space' property on editing hosts
// > and on markup that was originally created through these editing mechanisms
// > to the value 'pre-wrap'. Default HTML whitespace handling is not well
// > suited to WYSIWYG editing, and line wrapping will not work correctly in
// > some corner cases if 'white-space' is left at its default value.
// >
// > https://html.spec.whatwg.org/multipage/interaction.html#best-practices-for-in-page-editors
/**
* In HTML, leading and trailing spaces are not visible, and multiple spaces
* elsewhere are visually reduced to one space. This rule prevents spaces from
* collapsing so all space is visible in the editor and can be removed. It also
* prevents some browsers from inserting non-breaking spaces at the end of a
* line to prevent the space from visually disappearing. Sometimes these non
* breaking spaces can linger in the editor causing unwanted non breaking spaces
* in between words. If also prevent Firefox from inserting a trailing `br` node
* to visualise any trailing space, causing the element to be saved.
*
* > Authors are encouraged to set the 'white-space' property on editing hosts
* > and on markup that was originally created through these editing mechanisms
* > to the value 'pre-wrap'. Default HTML whitespace handling is not well
* > suited to WYSIWYG editing, and line wrapping will not work correctly in
* > some corner cases if 'white-space' is left at its default value.
*
* https://html.spec.whatwg.org/multipage/interaction.html#best-practices-for-in-page-editors
*
* @type {string}
*/
const whiteSpace = 'pre-wrap';

/**
* Default style object for the editable element.
*
* @type {Object}
*/
const defaultStyle = { whiteSpace };

/**
* Global stylesheet.
*/
Expand Down Expand Up @@ -993,7 +1004,7 @@ class RichText extends Component {
Editable( props ) {
const {
tagName: TagName = 'div',
style = {},
style,
className,
placeholder,
forwardedRef,
Expand All @@ -1003,10 +1014,14 @@ class RichText extends Component {

return (
<TagName
// Overridable props.
role="textbox"
aria-multiline
aria-label={ placeholder }
{ ...props }
{ ...ariaProps }
ref={ forwardedRef }
style={ { ...style, whiteSpace } }
style={ style ? { ...style, whiteSpace } : defaultStyle }
className={ classnames( 'rich-text', className ) }
onPaste={ this.onPaste }
onInput={ this.onInput }
Expand All @@ -1026,9 +1041,6 @@ class RichText extends Component {
onKeyUp={ this.onSelectionChange }
onMouseUp={ this.onSelectionChange }
onTouchEnd={ this.onSelectionChange }
role="textbox"
aria-multiline
aria-label={ placeholder }
contentEditable
suppressContentEditableWarning
/>
Expand Down

0 comments on commit ba7fb6a

Please sign in to comment.