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

Changed: Placeholder text should not be hidden if element has only ui elements. #1019

Merged
merged 1 commit into from
Jul 18, 2017
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
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