浏览代码

Merge pull request #84 from ckeditor/t/ckeditor5/1517

Internal: The editor placeholder configuration using the `placeholder` attribute should be restricted to `<textarea>` only (see [ckeditor/ckeditor5#1517](https://github.com/ckeditor/ckeditor5/issues/1517)).
Piotrek Koszuliński 6 年之前
父节点
当前提交
6ceefbb461

+ 2 - 1
packages/ckeditor5-editor-classic/src/classiceditorui.js

@@ -167,9 +167,10 @@ export default class ClassicEditorUI 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.getAttribute( 'placeholder' );
+			sourceElement && sourceElement.tagName.toLowerCase() === 'textarea' && sourceElement.getAttribute( 'placeholder' );
 
 		if ( placeholderText ) {
 			enablePlaceholder( {

+ 4 - 4
packages/ckeditor5-editor-classic/tests/classiceditorui.js

@@ -126,8 +126,8 @@ describe( 'ClassicEditorUI', () => {
 					} );
 			} );
 
-			it( 'sets placeholder from "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.setAttribute( 'placeholder', 'placeholder-text' );
 
@@ -144,8 +144,8 @@ describe( 'ClassicEditorUI', () => {
 					} );
 			} );
 
-			it( 'uses editor.config.placeholder rather than "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.setAttribute( 'placeholder', 'placeholder-text' );
 

+ 3 - 3
packages/ckeditor5-editor-classic/tests/manual/placeholder.html

@@ -1,5 +1,5 @@
-<div id="editor-1" 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" placeholder="Placeholder from the attribute"></div>
+<div id="editor-2" data-placeholder="Placeholder from the attribute"></div>