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 #267 from ckeditor/t/266
Browse files Browse the repository at this point in the history
Feature: Added `TextInputView#isReadOnly` and `LabeledInputView#isReadOnly`  states. Closes #266. Closes #268.
  • Loading branch information
oleq committed Jul 13, 2017
2 parents eb4caab + 623ee76 commit 111a728
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/inputtext/inputtextview.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ export default class InputTextView extends View {
*/
this.set( 'placeholder' );

/**
* Controls whether the input view is in read-only mode.
*
* @observable
* @member {Boolean} #isReadOnly
*/
this.set( 'isReadOnly', false );

const bind = this.bindTemplate;

this.template = new Template( {
Expand All @@ -57,7 +65,8 @@ export default class InputTextView extends View {
'ck-input-text'
],
id: bind.to( 'id' ),
placeholder: bind.to( 'placeholder' )
placeholder: bind.to( 'placeholder' ),
readonly: bind.to( 'isReadOnly' )
}
} );

Expand Down
17 changes: 16 additions & 1 deletion src/labeledinput/labeledinputview.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ export default class LabeledInputView extends View {
*/
this.set( 'value' );

/**
* Controls whether the component is in read-only mode.
*
* @observable
* @member {Boolean} #isReadOnly
*/
this.set( 'isReadOnly', false );

/**
* The label view.
*
Expand All @@ -60,9 +68,15 @@ export default class LabeledInputView extends View {
*/
this.inputView = this._createInputView( InputView, id );

const bind = this.bindTemplate;

this.template = new Template( {
tag: 'div',

attributes: {
class: [
bind.if( 'isReadOnly', 'ck-disabled' )
]
},
children: [
this.labelView,
this.inputView
Expand Down Expand Up @@ -99,6 +113,7 @@ export default class LabeledInputView extends View {

inputView.id = id;
inputView.bind( 'value' ).to( this );
inputView.bind( 'isReadOnly' ).to( this );

return inputView;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/inputtext/inputtextview.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ describe( 'InputTextView', () => {
expect( view.element.placeholder ).to.equal( 'baz' );
} );
} );

describe( 'isReadOnly', () => {
it( 'should react on view#isReadOnly', () => {
expect( view.element.readOnly ).to.false;

view.isReadOnly = true;

expect( view.element.readOnly ).to.true;
} );
} );
} );

describe( 'select()', () => {
Expand Down
22 changes: 22 additions & 0 deletions tests/labeledinput/labeledinputview.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ describe( 'LabeledInputView', () => {
it( 'should have input view', () => {
expect( view.template.children.get( 1 ) ).to.equal( view.inputView );
} );

describe( 'DOM bindings', () => {
describe( 'class', () => {
it( 'should react on view#isReadOnly', () => {
view.isReadOnly = false;
expect( view.element.classList.contains( 'ck-disabled' ) ).to.be.false;

view.isReadOnly = true;
expect( view.element.classList.contains( 'ck-disabled' ) ).to.be.true;
} );
} );
} );
} );

describe( 'binding', () => {
Expand All @@ -58,6 +70,16 @@ describe( 'LabeledInputView', () => {

expect( view.inputView.value ).to.equal( 'Lorem ipsum' );
} );

it( 'should bind view#isreadOnly to view.inputView#isReadOnly', () => {
view.isReadOnly = false;

expect( view.inputView.isReadOnly ).to.false;

view.isReadOnly = true;

expect( view.inputView.isReadOnly ).to.true;
} );
} );

describe( 'select()', () => {
Expand Down

0 comments on commit 111a728

Please sign in to comment.