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
Changes from 1 commit
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
14 changes: 12 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,17 @@ export class RichText extends Component {
}

setRef( node ) {
this.editableRef = node;
if ( node ) {
const computedStyle = getComputedStyle( node );
ellatrix marked this conversation as resolved.
Show resolved Hide resolved

if ( computedStyle.display === 'inline' ) {
window.console.warn( 'RichText cannot be used with an inline container. Please use a different tagName.' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the use of window.console.warn is to get around the lint rule? In other places I noticed the rule is specifically disabled:

// eslint-disable-next-line no-console
console.warn( // ... );

I think it'd be better to follow that convention—if the eslint rule is updated in the future to cover window.console there would lint failures that need to be fixed.

Copy link
Member

@aduth aduth Feb 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the eslint rule is updated in the future to cover window.console there would lint failures that need to be fixed.

This conversation makes me want to update that rule now 😅 Ideally we'd abstract our logging in a way where we could provide some more consistency / meaningful information anyways, for these legitimate usages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder, now that we add the environment check, if we cannot just stop RichText from doing anything further. It will still work in production, but if you're trying to develop with RichText and inline elements, it just won't work. I think a lot of people will just ignore or be blind to the warning.

}

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

setFocusedElement() {
Expand Down