Enforces the use of htmlFor in Fields and matching ids in the internal inputs
This rule suggests the use of htmlFor in Fields and id in inputs, and reinforces that those two props should be the same. Matching the htmlFor and id props improves accessibility - if they don't match, the input is not linked to the label inside Field, and consequently cannot be hovered, focused, or selected when clicking the label.
Severity
Recommended severity: warning
rules:{
'@carta/ink-rules/field-with-htmlfor':1,
}
Components affected by this rule
All ink inputs except the ones that can have multiple instances inside one Field: Checkbox, Radio, NewCheckbox and NewRadio.
Examples
<FieldisStacked>
<NewTextArea/>
</Field>
<FieldisStackedhtmlFor="newinput-id">
<NewInputid="newinput-id"/>
</Field>
Don't
Use Field and inputs without `htmlFor` and `ids`
Do
Use `htmlFor` in your `Field` and matching `id` on your input
<FieldisStacked>
<NewTextArea/>
</Field>
Don't
Use Field and inputs without `htmlFor` and `ids`
<FieldisStackedhtmlFor="newinput-id">
<NewInputid="newinput-id"/>
</Field>
Do
Use `htmlFor` in your `Field` and matching `id` on your input
<Ink.FieldisStacked>
<Ink.NewTextAreaid="newtextarea-id"/>
</Ink.Field>
<Ink.FieldisStackedhtmlFor="ink-field-id">
<Ink.NewDatePicker/>
</Ink.Field>
<Ink.FieldisStackedhtmlFor="newtextarea-id">
<Ink.NewTextAreaid="newtextarea-id"/>
</Ink.Field>
Don't
Use just one or the other
Do
Use both `htmlFor` and `id`
<Ink.FieldisStacked>
<Ink.NewTextAreaid="newtextarea-id"/>
</Ink.Field>
<Ink.FieldisStackedhtmlFor="ink-field-id">
<Ink.NewDatePicker/>
</Ink.Field>
Don't
Use just one or the other
<Ink.FieldisStackedhtmlFor="newtextarea-id">
<Ink.NewTextAreaid="newtextarea-id"/>
</Ink.Field>
Do
Use both `htmlFor` and `id`
<FieldisStackedhtmlFor="fieldid">
<NewInputid="newinputid"/>
</Field>
<FieldisStackedhtmlFor="matchingid">
<NewInputid="matchingid"/>
</Field>
Don't
Use not matching `htmlFor` and `id`
Do
Use matching `htmlFor` and `id`
<FieldisStackedhtmlFor="fieldid">
<NewInputid="newinputid"/>
</Field>
Don't
Use not matching `htmlFor` and `id`
<FieldisStackedhtmlFor="matchingid">
<NewInputid="matchingid"/>
</Field>
Do
Use matching `htmlFor` and `id`
This rule won't trigger
If you're using inputs that can have multiple instances inside of Field (Checkbox, NewCheckbox, Radio, NewRadio), this rule won't be triggered.
<FieldisStacked>
<NewCheckboxid="newcheckbox-01"/>
<NewCheckboxid="newcheckbox-02"/>
</Field>
<Ink.FieldisStacked>
<Ink.NewRadio/>
<Ink.NewRadio/>
</Ink.Field>
Do
This rule won't trigger for inputs that are multiple
<FieldisStacked>
<NewCheckboxid="newcheckbox-01"/>
<NewCheckboxid="newcheckbox-02"/>
</Field>
<Ink.FieldisStacked>
<Ink.NewRadio/>
<Ink.NewRadio/>
</Ink.Field>
Do
This rule won't trigger for inputs that are multiple