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

Commit 299628b

Browse files
author
Piotr Jasiun
authored
Merge pull request #1019 from ckeditor/t/1018
Fix: Placeholder text now will not be hidden if the element has only ui elements. Closes #1018.
2 parents e91db91 + 6a66f6e commit 299628b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/view/placeholder.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,19 @@ function updateSinglePlaceholder( element, checkFunction ) {
110110
return;
111111
}
112112

113+
// Element is empty for placeholder purposes when it has no children or only ui elements.
114+
// This check is taken from `view.ContainerElement#getFillerOffset`.
115+
const isEmptyish = !Array.from( element.getChildren() ).some( element => !element.is( 'uiElement' ) );
116+
113117
// If element is empty and editor is blurred.
114-
if ( !document.isFocused && !element.childCount ) {
118+
if ( !document.isFocused && isEmptyish ) {
115119
element.addClass( 'ck-placeholder' );
116120

117121
return;
118122
}
119123

120124
// It there are no child elements and selection is not placed inside element.
121-
if ( !element.childCount && anchor && anchor.parent !== element ) {
125+
if ( isEmptyish && anchor && anchor.parent !== element ) {
122126
element.addClass( 'ck-placeholder' );
123127
} else {
124128
element.removeClass( 'ck-placeholder' );

tests/view/placeholder.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ describe( 'placeholder', () => {
4747
expect( element.hasClass( 'ck-placeholder' ) ).to.be.false;
4848
} );
4949

50+
it( 'if element has only ui elements, set CSS class and data attribute', () => {
51+
setData( viewDocument, '<div><ui:span></ui:span><ui:span></ui:span></div><div>{another div}</div>' );
52+
const element = viewRoot.getChild( 0 );
53+
54+
attachPlaceholder( element, 'foo bar baz' );
55+
56+
expect( element.getAttribute( 'data-placeholder' ) ).to.equal( 'foo bar baz' );
57+
expect( element.hasClass( 'ck-placeholder' ) ).to.be.true;
58+
} );
59+
5060
it( 'if element has selection inside set only data attribute', () => {
5161
setData( viewDocument, '<div>[]</div><div>another div</div>' );
5262
const element = viewRoot.getChild( 0 );

0 commit comments

Comments
 (0)