1
+ import * as _ from "lodash-es" ;
1
2
import { html , LitElement , TemplateResult } from "lit" ;
2
- import { property , state } from "lit/decorators.js" ;
3
+ import { property , state , query } from "lit/decorators.js" ;
3
4
import { repeat } from "lit/directives/repeat.js" ;
4
- import { renderInTooltip , toCamelCase , noKeyWarning } from "./utils.js" ;
5
+ import { renderInTooltip , noKeyWarning } from "./utils.js" ;
5
6
import "@shoelace-style/shoelace/dist/components/alert/alert.js" ;
6
7
import "@shoelace-style/shoelace/dist/components/icon/icon.js" ;
7
8
import "@shoelace-style/shoelace/dist/components/input/input.js" ;
@@ -44,23 +45,24 @@ export default class EccUtilsDesignFormInput extends LitElement {
44
45
@property ( { type : String , reflect : true } ) default = "" ;
45
46
@property ( { type : Boolean , reflect : true } ) checked = false ;
46
47
@property ( { type : Boolean , reflect : true } ) multiple = false ;
48
+ @property ( { type : String , reflect : true } ) value : any ;
47
49
@property ( { type : String , reflect : true } ) accept = "*" ;
48
- @property ( { type : String , attribute : "tus- endpoint" } ) tusEndpoint = "" ;
50
+ @property ( { type : String , attribute : "endpoint" } ) tusEndpoint = "" ;
49
51
@property ( { type : String , reflect : true } ) protocol : "native" | "tus" =
50
52
"native" ;
51
53
52
- @property ( { type : String , reflect : true } ) value : any ;
53
-
54
54
@state ( ) private alertText = "Something went wrong" ;
55
55
@state ( ) private alertType : AlertType = "info" ;
56
56
@state ( ) private showAlert = false ;
57
57
@state ( ) path = "" ;
58
58
59
+ @query ( "sl-input" ) input ! : HTMLInputElement ;
60
+
59
61
connectedCallback ( ) : void {
60
62
super . connectedCallback ( ) ;
61
63
if ( ! this . key ) {
62
64
noKeyWarning ( "ecc-d-form-group" , this . label ) ;
63
- this . key = toCamelCase ( this . label ) ;
65
+ this . key = _ . camelCase ( this . label ) ;
64
66
}
65
67
66
68
this . findNearestFormGroup ( ) ;
@@ -88,10 +90,12 @@ export default class EccUtilsDesignFormInput extends LitElement {
88
90
const parentPath = parentElement . getAttribute ( "path" ) ;
89
91
this . path = parentPath ? `${ parentPath } .${ this . key } ` : this . key ;
90
92
}
93
+
94
+ this . findNearestFormGroup ( parentElement ) ;
91
95
}
92
96
93
97
private handleDismissAlert ( ) {
94
- this . alertText = "" ; // reset error text
98
+ this . alertText = "" ;
95
99
this . showAlert = false ;
96
100
this . requestUpdate ( ) ;
97
101
}
@@ -103,6 +107,18 @@ export default class EccUtilsDesignFormInput extends LitElement {
103
107
this . requestUpdate ( ) ;
104
108
}
105
109
110
+ validity ( ) {
111
+ return this . input . validity ;
112
+ }
113
+
114
+ checkValidity ( ) {
115
+ return this . input . checkValidity ( ) ;
116
+ }
117
+
118
+ reportValidity ( ) {
119
+ return this . input . reportValidity ( ) ;
120
+ }
121
+
106
122
private handleFireChangeEvent ( ) {
107
123
this . dispatchEvent (
108
124
new CustomEvent ( "ecc-utils-change" , {
@@ -121,10 +137,7 @@ export default class EccUtilsDesignFormInput extends LitElement {
121
137
const target = e . target as HTMLInputElement ;
122
138
this . value = this . type === "switch" ? target . checked : target . value ;
123
139
124
- // fire change event
125
140
this . handleFireChangeEvent ( ) ;
126
-
127
- // update
128
141
this . requestUpdate ( ) ;
129
142
}
130
143
0 commit comments