Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RichText: warn when using inline container #13921

Merged
merged 3 commits into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/editor/src/components/rich-text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Render a rich [`contenteditable` input](https://developer.mozilla.org/en-US/docs

### `tagName: String`

*Default: `div`.* The [tag name](https://www.w3.org/TR/html51/syntax.html#tag-name) of the editable element.
*Default: `div`.* The [tag name](https://www.w3.org/TR/html51/syntax.html#tag-name) of the editable element. Elements that display inline are not supported.

### `placeholder: String`

Expand Down
17 changes: 15 additions & 2 deletions packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import { RemoveBrowserShortcuts } from './remove-browser-shortcuts';
* Browser dependencies
*/

const { getSelection } = window;
const { getSelection, getComputedStyle } = window;

export class RichText extends Component {
constructor( { value, onReplace, multiline } ) {
Expand Down Expand Up @@ -136,7 +136,20 @@ export class RichText extends Component {
}

setRef( node ) {
this.editableRef = node;
if ( node ) {
if ( process.env.NODE_ENV === 'development' ) {
const computedStyle = getComputedStyle( node );

if ( computedStyle.display === 'inline' ) {
// eslint-disable-next-line no-console
console.warn( 'RichText cannot be used with an inline container. Please use a different tagName.' );
}
}

this.editableRef = node;
} else {
delete this.editableRef;
}
}

setFocusedElement() {
Expand Down