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

Commit

Permalink
Merge pull request #10 from ckeditor/t/9
Browse files Browse the repository at this point in the history
Fix: Added initial contenteditable state for editable widget. Closes #9.
  • Loading branch information
Piotr Jasiun authored Jul 19, 2017
2 parents 2726873 + 0cd2a12 commit c6321ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export function getLabel( element ) {
/**
* Adds functionality to provided {module:engine/view/editableelement~EditableElement} to act as a widget's editable:
* * adds `ck-editable` CSS class,
* * sets `contenteditable` as `true` when {module:engine/view/editableelement~EditableElement#isReadOnly} is `false`,
* * sets `contenteditable` as `true` when {module:engine/view/editableelement~EditableElement#isReadOnly} is `false`
* otherwise set `false`,
* * adds `ck-editable_focused` CSS class when editable is focused and removes it when it's blurred.
*
* @param {module:engine/view/editableelement~EditableElement} editable
Expand All @@ -100,6 +101,10 @@ export function getLabel( element ) {
export function toWidgetEditable( editable ) {
editable.addClass( 'ck-editable' );

// Set initial contenteditable value.
editable.setAttribute( 'contenteditable', !editable.isReadOnly );

// Bind contenteditable property to element#isReadOnly.
editable.on( 'change:isReadOnly', ( evt, property, is ) => {
editable.setAttribute( 'contenteditable', !is );
} );
Expand Down
6 changes: 3 additions & 3 deletions tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ describe( 'widget utils', () => {
} );

it( 'should add proper contenteditable value when element is read-only', () => {
element.isReadOnly = true;
expect( element.getAttribute( 'contenteditable' ) ).to.false;

element.isReadOnly = false;
expect( element.getAttribute( 'contenteditable' ) ).to.true;

element.isReadOnly = true;
expect( element.getAttribute( 'contenteditable' ) ).to.false;
} );

it( 'should add proper class when element is focused', () => {
Expand Down

0 comments on commit c6321ff

Please sign in to comment.