This repository was archived by the owner on Jun 26, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +58
-2
lines changed
Expand file tree Collapse file tree 4 files changed +58
-2
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,14 @@ export default class InputTextView extends View {
4646 */
4747 this . set ( 'placeholder' ) ;
4848
49+ /**
50+ * Controls whether the input view is in read-only mode.
51+ *
52+ * @observable
53+ * @member {Boolean} #isReadOnly
54+ */
55+ this . set ( 'isReadOnly' , false ) ;
56+
4957 const bind = this . bindTemplate ;
5058
5159 this . template = new Template ( {
@@ -57,7 +65,8 @@ export default class InputTextView extends View {
5765 'ck-input-text'
5866 ] ,
5967 id : bind . to ( 'id' ) ,
60- placeholder : bind . to ( 'placeholder' )
68+ placeholder : bind . to ( 'placeholder' ) ,
69+ readonly : bind . to ( 'isReadOnly' )
6170 }
6271 } ) ;
6372
Original file line number Diff line number Diff line change @@ -46,6 +46,14 @@ export default class LabeledInputView extends View {
4646 */
4747 this . set ( 'value' ) ;
4848
49+ /**
50+ * Controls whether the component is in read-only mode.
51+ *
52+ * @observable
53+ * @member {Boolean} #isReadOnly
54+ */
55+ this . set ( 'isReadOnly' , false ) ;
56+
4957 /**
5058 * The label view.
5159 *
@@ -60,9 +68,15 @@ export default class LabeledInputView extends View {
6068 */
6169 this . inputView = this . _createInputView ( InputView , id ) ;
6270
71+ const bind = this . bindTemplate ;
72+
6373 this . template = new Template ( {
6474 tag : 'div' ,
65-
75+ attributes : {
76+ class : [
77+ bind . if ( 'isReadOnly' , 'ck-disabled' )
78+ ]
79+ } ,
6680 children : [
6781 this . labelView ,
6882 this . inputView
@@ -99,6 +113,7 @@ export default class LabeledInputView extends View {
99113
100114 inputView . id = id ;
101115 inputView . bind ( 'value' ) . to ( this ) ;
116+ inputView . bind ( 'isReadOnly' ) . to ( this ) ;
102117
103118 return inputView ;
104119 }
Original file line number Diff line number Diff line change @@ -66,6 +66,16 @@ describe( 'InputTextView', () => {
6666 expect ( view . element . placeholder ) . to . equal ( 'baz' ) ;
6767 } ) ;
6868 } ) ;
69+
70+ describe ( 'isReadOnly' , ( ) => {
71+ it ( 'should react on view#isReadOnly' , ( ) => {
72+ expect ( view . element . readOnly ) . to . false ;
73+
74+ view . isReadOnly = true ;
75+
76+ expect ( view . element . readOnly ) . to . true ;
77+ } ) ;
78+ } ) ;
6979 } ) ;
7080
7181 describe ( 'select()' , ( ) => {
Original file line number Diff line number Diff line change @@ -44,6 +44,18 @@ describe( 'LabeledInputView', () => {
4444 it ( 'should have input view' , ( ) => {
4545 expect ( view . template . children . get ( 1 ) ) . to . equal ( view . inputView ) ;
4646 } ) ;
47+
48+ describe ( 'DOM bindings' , ( ) => {
49+ describe ( 'class' , ( ) => {
50+ it ( 'should react on view#isReadOnly' , ( ) => {
51+ view . isReadOnly = false ;
52+ expect ( view . element . classList . contains ( 'ck-disabled' ) ) . to . be . false ;
53+
54+ view . isReadOnly = true ;
55+ expect ( view . element . classList . contains ( 'ck-disabled' ) ) . to . be . true ;
56+ } ) ;
57+ } ) ;
58+ } ) ;
4759 } ) ;
4860
4961 describe ( 'binding' , ( ) => {
@@ -58,6 +70,16 @@ describe( 'LabeledInputView', () => {
5870
5971 expect ( view . inputView . value ) . to . equal ( 'Lorem ipsum' ) ;
6072 } ) ;
73+
74+ it ( 'should bind view#isreadOnly to view.inputView#isReadOnly' , ( ) => {
75+ view . isReadOnly = false ;
76+
77+ expect ( view . inputView . isReadOnly ) . to . false ;
78+
79+ view . isReadOnly = true ;
80+
81+ expect ( view . inputView . isReadOnly ) . to . true ;
82+ } ) ;
6183 } ) ;
6284
6385 describe ( 'select()' , ( ) => {
You can’t perform that action at this time.
0 commit comments