@@ -57,6 +57,11 @@ export interface FormLabelMixinProperties {
57
57
*/
58
58
describedBy ?: string ;
59
59
60
+ /**
61
+ * ID of a form element associated with the form field
62
+ */
63
+ formId ?: string ;
64
+
60
65
/**
61
66
* Indicates the value entered in the form field is invalid
62
67
*/
@@ -118,7 +123,7 @@ const labelDefaults = {
118
123
/**
119
124
* Allowed attributes for a11y
120
125
*/
121
- const allowedAttributes = [ 'checked' , 'describedBy' , 'disabled' , 'invalid' , 'maxLength' , 'minLength' , 'multiple' , 'name' , 'placeholder' , 'readOnly' , 'required' , 'type' , 'value' ] ;
126
+ const allowedFormFieldAttributes = [ 'checked' , 'describedBy' , 'disabled' , 'invalid' , 'maxLength' , 'minLength' , 'multiple' , 'name' , 'placeholder' , 'readOnly' , 'required' , 'type' , 'value' ] ;
122
127
123
128
function getFormFieldA11yAttributes ( instance : FormLabel ) {
124
129
const { properties, type } = instance ;
@@ -130,7 +135,7 @@ function getFormFieldA11yAttributes(instance: FormLabel) {
130
135
131
136
const nodeAttributes : any = { } ;
132
137
133
- for ( const key of allowedAttributes ) {
138
+ for ( const key of allowedFormFieldAttributes ) {
134
139
135
140
if ( attributeKeys . indexOf ( key ) === - 1 ) {
136
141
continue ;
@@ -168,8 +173,14 @@ const createFormLabelMixin = compose<FormLabelMixin, {}>({})
168
173
. aspect ( {
169
174
after : {
170
175
render ( this : FormLabel , result : DNode ) : DNode {
176
+ const labelNodeAttributes : any = { } ;
171
177
if ( isHNode ( result ) ) {
172
178
assign ( result . properties , getFormFieldA11yAttributes ( this ) ) ;
179
+
180
+ // move classes to label node
181
+ const { classes } = result . properties ;
182
+ const { formId } = this . properties ;
183
+ assign ( labelNodeAttributes , { classes, 'form' : formId } ) ;
173
184
}
174
185
175
186
if ( this . properties . label ) {
@@ -194,7 +205,7 @@ const createFormLabelMixin = compose<FormLabelMixin, {}>({})
194
205
children . reverse ( ) ;
195
206
}
196
207
197
- result = v ( 'label' , children ) ;
208
+ result = v ( 'label' , labelNodeAttributes , children ) ;
198
209
}
199
210
200
211
return result ;
0 commit comments