Parcourir la source

The editor placeholder configuration using the placeholder attribute should be restricted to <textarea> only.

Aleksander Nowodzinski il y a 6 ans
Parent
commit
f711e1475e

+ 2 - 1
packages/ckeditor5-editor-inline/src/inlineeditorui.js

@@ -161,9 +161,10 @@ export default class InlineEditorUI extends EditorUI {
 		const editor = this.editor;
 		const editingView = editor.editing.view;
 		const editingRoot = editingView.document.getRoot();
+		const sourceElement = editor.sourceElement;
 
 		const placeholderText = editor.config.get( 'placeholder' ) ||
-			editor.sourceElement && editor.sourceElement.dataset.placeholder;
+			sourceElement && sourceElement.tagName.toLowerCase() === 'textarea' && sourceElement.getAttribute( 'placeholder' );
 
 		if ( placeholderText ) {
 			enablePlaceholder( {

+ 6 - 6
packages/ckeditor5-editor-inline/tests/inlineeditorui.js

@@ -148,10 +148,10 @@ describe( 'InlineEditorUI', () => {
 					} );
 			} );
 
-			it( 'sets placeholder from the "data-placeholder" attribute of a passed element', () => {
-				const element = document.createElement( 'div' );
+			it( 'sets placeholder from the "placeholder" attribute of a passed <textarea>', () => {
+				const element = document.createElement( 'textarea' );
 
-				element.dataset.placeholder = 'placeholder-text';
+				element.setAttribute( 'placeholder', 'placeholder-text' );
 
 				return VirtualInlineTestEditor
 					.create( element, {
@@ -166,10 +166,10 @@ describe( 'InlineEditorUI', () => {
 					} );
 			} );
 
-			it( 'uses editor.config.placeholder rather than the "data-placeholder" attribute of a passed element', () => {
-				const element = document.createElement( 'div' );
+			it( 'uses editor.config.placeholder rather than the "placeholder" attribute of a passed <textarea>', () => {
+				const element = document.createElement( 'textarea' );
 
-				element.dataset.placeholder = 'placeholder-text';
+				element.setAttribute( 'placeholder', 'placeholder-text' );
 
 				return VirtualInlineTestEditor
 					.create( element, {

+ 2 - 2
packages/ckeditor5-editor-inline/tests/manual/placeholder.html

@@ -1,5 +1,5 @@
-<div id="editor-1" data-placeholder="Placeholder from the attribute">
+<textarea id="editor-1" placeholder="Placeholder from the attribute">
 	<p>Remove this text to see the placeholder.</p>
-</div>
+</textarea>
 <br />
 <div id="editor-2" data-placeholder="Placeholder from the attribute"></div>