Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Changed: Placeholder text should not be hidden if element has only ui…
Browse files Browse the repository at this point in the history
… elements.
  • Loading branch information
scofalik committed Jul 18, 2017
1 parent e91db91 commit 6a66f6e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/view/placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,19 @@ function updateSinglePlaceholder( element, checkFunction ) {
return;
}

// Element is empty for placeholder purposes when it has no children or only ui elements.
// This check is taken from `view.ContainerElement#getFillerOffset`.
const isEmptyish = !Array.from( element.getChildren() ).some( element => !element.is( 'uiElement' ) );

// If element is empty and editor is blurred.
if ( !document.isFocused && !element.childCount ) {
if ( !document.isFocused && isEmptyish ) {
element.addClass( 'ck-placeholder' );

return;
}

// It there are no child elements and selection is not placed inside element.
if ( !element.childCount && anchor && anchor.parent !== element ) {
if ( isEmptyish && anchor && anchor.parent !== element ) {
element.addClass( 'ck-placeholder' );
} else {
element.removeClass( 'ck-placeholder' );
Expand Down
10 changes: 10 additions & 0 deletions tests/view/placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ describe( 'placeholder', () => {
expect( element.hasClass( 'ck-placeholder' ) ).to.be.false;
} );

it( 'if element has only ui elements, set CSS class and data attribute', () => {
setData( viewDocument, '<div><ui:span></ui:span><ui:span></ui:span></div><div>{another div}</div>' );
const element = viewRoot.getChild( 0 );

attachPlaceholder( element, 'foo bar baz' );

expect( element.getAttribute( 'data-placeholder' ) ).to.equal( 'foo bar baz' );
expect( element.hasClass( 'ck-placeholder' ) ).to.be.true;
} );

it( 'if element has selection inside set only data attribute', () => {
setData( viewDocument, '<div>[]</div><div>another div</div>' );
const element = viewRoot.getChild( 0 );
Expand Down

0 comments on commit 6a66f6e

Please sign in to comment.