@@ -5,13 +5,25 @@ import { LitElement, html, css } from 'lit';
55 * FormInputElement
66 */
77export class FormInputElement extends LitElement {
8+ #internals;
89 constructor ( ) {
910 super ( ) ;
11+
12+ // Attach with the form
13+ this . #internals = this . attachInternals ( ) ;
14+
1015 // Default properties
1116 this . name = 'input' ;
17+ this . value = '' ;
18+ this . placeholder = '' ;
1219 this . required = false ;
20+ this . pattern = '' ;
1321 this . autocomplete = false ;
1422 this . labelabove = false ;
23+ this . rows = 0 ;
24+ }
25+ static get formAssociated ( ) {
26+ return true ;
1527 }
1628 static get properties ( ) {
1729 return {
@@ -57,6 +69,16 @@ export class FormInputElement extends LitElement {
5769 * @type {boolean }
5870 */
5971 labelabove : { type : Boolean } ,
72+
73+ /**
74+ * The number of rows (for textarea)
75+ */
76+ rows : { type : Number } ,
77+
78+ /**
79+ * Whether the control is disabled
80+ */
81+ disabled : { type : Boolean } ,
6082 } ;
6183 }
6284 static get styles ( ) {
@@ -71,43 +93,63 @@ export class FormInputElement extends LitElement {
7193 .labelabove {
7294 flex-direction: column;
7395 }
74- input {
96+ . input {
7597 flex: 1;
7698 background-color: var(--form-input-background-color);
7799 color: var(--form-input-color);
78100 margin: var(--form-input-margin-y) var(--form-input-margin-x) var(--form-input-margin-y) var(--form-input-margin-x);
79101 padding: var(--form-input-padding-y) var(--form-input-padding-x) var(--form-input-padding-y) var(--form-input-padding-x);
102+ font-family: inherit;
80103 font-size: var(--form-input-font-size);
81104 font-weight: var(--form-input-font-weight);
82105 line-height: var(--form-input-line-height);
83106 border: var(--form-input-border);
84107 }
85- input:focus {
86- background-color: var(--form-input-background-color-focus);
87- color: var(--form-input-color-focus);
88- border: var(--form-input-border-focus);
89- }
108+ . input:focus {
109+ background-color: var(--form-input-background-color-focus);
110+ color: var(--form-input-color-focus);
111+ border: var(--form-input-border-focus);
112+ }
90113 label {
91- display: block;
92- min-width: 10em;
93- background-color: var(--form-label-background-color);
94- color: var(--form-label-color);
95- padding: var(--form-label-padding);
96- font-size: var(--form-label-font-size);
97- font-weight: var(--form-label-font-weight);
98- line-height: var(--form-label-line-height);
99- border: var(--form-label-border);
114+ display: block;
115+ min-width: 10em;
116+ background-color: var(--form-label-background-color);
117+ color: var(--form-label-color);
118+ padding: var(--form-label-padding-y) var(--form-label-padding-x) var(--form-label-padding-y) var(--form-label-padding-x );
119+ font-size: var(--form-label-font-size);
120+ font-weight: var(--form-label-font-weight);
121+ line-height: var(--form-label-line-height);
122+ border: var(--form-label-border) solid red ;
100123 }
124+ textarea {
125+ resize: none;
126+ }
101127 ` ;
102128 }
129+ renderInput ( ) {
130+ if ( this . rows > 0 ) {
131+ return html `
132+ < textarea part ="input " class ="input " name ="${ this . name } " placeholder =${ this . placeholder } rows =${ this . rows } ?disabled=${ this . disabled } autocomplete="${ this . autocomplete ? 'on' : 'off' } " pattern="${ this . pattern } "> ${ this . value } </ textarea >
133+ ` ;
134+ } else {
135+ return html `
136+ < input type ="text " class ="input " name ="${ this . name } " value ="${ this . value } " ?required ="${ this . required } " placeholder ="${ this . placeholder } " ?disabled =${ this . disabled } autocomplete ="${ this . autocomplete ? 'on' : 'off' } " pattern="${ this . pattern } "> </ input >
137+ ` ;
138+ }
139+ }
103140 render ( ) {
141+ const renderInput = this . renderInput ( ) ;
104142 return html `
105143 < div class ="${ this . labelabove ? 'labelabove' : 'labelbeside' } ">
106144 < label for ="${ this . name } "> < slot > </ slot > </ label >
107- < input type =" text " name =" ${ this . name } " ?value =" ${ this . value } " ?required =" ${ this . required } " placeholder =" ${ this . placeholder } " autocomplete =" ${ this . autocomplete ? 'on' : 'off' } " ?pattern =" ${ this . pattern } " >
145+ ${ renderInput }
108146 </ div >
109147 ` ;
110148 }
149+ firstUpdated ( ) {
150+ console . log ( 'FormInputElement.firstUpdated' ) ;
151+ console . log ( this . #internals. form ) ;
152+ }
111153}
112154
113155customElements . define ( 'wc-form-input' , FormInputElement ) ;
0 commit comments