Jelajahi Sumber

Added integration with EditorConfig#placeholder.

Oskar Wróbel 6 tahun lalu
induk
melakukan
9b818839db

+ 3 - 1
packages/ckeditor5-heading/src/title.js

@@ -327,6 +327,8 @@ export default class Title extends Plugin {
 		const view = editor.editing.view;
 		const viewRoot = view.document.getRoot();
 
+		const bodyPlaceholder = editor.config.get( 'placeholder' ) || 'Body';
+
 		// Attach placeholder to the view title element.
 		editor.editing.downcastDispatcher.on( 'insert:title-content', ( evt, data, conversionApi ) => {
 			enablePlaceholder( {
@@ -354,7 +356,7 @@ export default class Title extends Plugin {
 					writer.removeAttribute( 'data-placeholder', oldBody );
 				}
 
-				writer.setAttribute( 'data-placeholder', 'Body', body );
+				writer.setAttribute( 'data-placeholder', bodyPlaceholder, body );
 				oldBody = body;
 				hasChanged = true;
 			}

+ 22 - 0
packages/ckeditor5-heading/tests/title.js

@@ -589,6 +589,28 @@ describe( 'Title', () => {
 			expect( bodyDomElement.dataset.placeholder ).to.equal( 'Body' );
 			expect( bodyDomElement.classList.contains( 'ck-placeholder' ) ).to.be.false;
 		} );
+
+		it( 'should use placeholder defined through EditorConfig as a Body placeholder', () => {
+			const element = document.createElement( 'div' );
+			document.body.appendChild( element );
+
+			return ClassicTestEditor.create( element, {
+				plugins: [ Title ],
+				placeholder: 'Custom editor placeholder'
+			} ).then( editor => {
+				const viewRoot = editor.editing.view.document.getRoot();
+				const title = viewRoot.getChild( 0 );
+				const body = viewRoot.getChild( 1 );
+
+				expect( title.getAttribute( 'data-placeholder' ) ).to.equal( 'Title' );
+				expect( title.hasClass( 'ck-placeholder' ) ).to.equal( true );
+
+				expect( body.getAttribute( 'data-placeholder' ) ).to.equal( 'Custom editor placeholder' );
+				expect( body.hasClass( 'ck-placeholder' ) ).to.equal( true );
+
+				return editor.destroy().then( () => element.remove() );
+			} );
+		} );
 	} );
 
 	describe( 'Tab press handling', () => {