This repository was archived by the owner on Jun 26, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff 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' ) ;
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments