File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,11 @@ export class LionTextarea extends LionField {
1919 type : Number ,
2020 reflect : true ,
2121 } ,
22+ readOnly : {
23+ type : Boolean ,
24+ attribute : 'readonly' ,
25+ reflect : true ,
26+ } ,
2227 } ;
2328 }
2429
@@ -42,6 +47,7 @@ export class LionTextarea extends LionField {
4247 super ( ) ;
4348 this . rows = 2 ;
4449 this . maxRows = 6 ;
50+ this . readOnly = false ;
4551 }
4652
4753 connectedCallback ( ) {
@@ -63,6 +69,13 @@ export class LionTextarea extends LionField {
6369 }
6470 }
6571
72+ if ( changedProperties . has ( 'readOnly' ) ) {
73+ const native = this . inputElement ;
74+ if ( native ) {
75+ native . readOnly = this . readOnly ;
76+ }
77+ }
78+
6679 if ( changedProperties . has ( 'modelValue' ) ) {
6780 this . resizeTextarea ( ) ;
6881 }
Original file line number Diff line number Diff line change @@ -22,12 +22,14 @@ describe('<lion-textarea>', () => {
2222 expect ( el . maxRows ) . to . equal ( 6 ) ;
2323 } ) ;
2424
25- it ( 'has .rows=2 and rows="2" by default' , async ( ) => {
25+ it ( 'has .readOnly=false . rows=2 and rows="2" by default' , async ( ) => {
2626 const el = await fixture ( `<lion-textarea>foo</lion-textarea>` ) ;
2727 expect ( el . rows ) . to . equal ( 2 ) ;
2828 expect ( el . getAttribute ( 'rows' ) ) . to . be . equal ( '2' ) ;
2929 expect ( el . inputElement . rows ) . to . equal ( 2 ) ;
3030 expect ( el . inputElement . getAttribute ( 'rows' ) ) . to . be . equal ( '2' ) ;
31+ expect ( el . readOnly ) . to . be . false ;
32+ expect ( el . inputElement . hasAttribute ( 'readonly' ) ) . to . be . false ;
3133 } ) ;
3234
3335 it ( 'sync rows down to the native textarea' , async ( ) => {
@@ -38,6 +40,12 @@ describe('<lion-textarea>', () => {
3840 expect ( el . inputElement . getAttribute ( 'rows' ) ) . to . be . equal ( '8' ) ;
3941 } ) ;
4042
43+ it ( 'sync readOnly to the native textarea' , async ( ) => {
44+ const el = await fixture ( `<lion-textarea readonly>foo</lion-textarea>` ) ;
45+ expect ( el . readOnly ) . to . be . true ;
46+ expect ( el . querySelector ( 'textarea' ) . readOnly ) . to . be . true ;
47+ } ) ;
48+
4149 it ( 'disables user resize behavior' , async ( ) => {
4250 if ( ! hasBrowserResizeSupport ( ) ) {
4351 return ;
You can’t perform that action at this time.
0 commit comments