Skip to content

Commit 25d51d7

Browse files
authored
Merge pull request #3039 from salesforce-ux/fix/input-fixed-text-accessibility
Fix/input fixed text accessibility
2 parents 6de28b6 + 5ca99aa commit 25d51d7

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

ui/components/input/_doc.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@
2929
*
3030
* In some cases, the read-only field state is swapped and has no `<input>`. This is called `static` in the examples. In that case, don’t use a `<label>`. This provides better accessibility for screen readers and keyboard navigators. Instead, use a `<span>` with the `.slds-form-element__label` class. Instead of an `<input>`, use the `.slds-form-element__static` class inside the `.slds-form-element__control` wrapper.
3131
*
32+
* ##### Fixed Text
33+
*
34+
* When using the fixed text variants for prepending or appending symbols to inputs,
35+
* please be sure to use `aria-labelledby` on the input, that points to the ids of the label,
36+
* prepended text and appended text as a space separated list. The IDs must appear in that order:
37+
* label, prepended, then appended.
38+
*
39+
* The reason we do this is to create a better association between the input and the supporting labels around it.
40+
* By only using the traditional `label[for]` method, the fixed text is never read out in the context of editing
41+
* the input value. With using the `aria-labelledby` attribute we can create a better label with all the
42+
* visual labels associated with it, in a relevant order, that is read by assistive technology when the user
43+
* needs it; when they're editing the value.
44+
*
3245
* @summary Text inputs are used for freeform data entry
3346
*
3447
* @base

ui/components/input/base/example.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export let FormElementLabel = props => (
2323
<label
2424
className={classNames('slds-form-element__label', props.className)}
2525
htmlFor={props.id || inputId}
26+
id={props.labelID}
2627
>
2728
{props.children}
2829
</label>
@@ -274,12 +275,14 @@ export let examples = [
274275
label: 'Fixed text',
275276
element: (
276277
<FormElement>
277-
<FormElementLabel>Input Label</FormElementLabel>
278+
<FormElementLabel labelID="fixed-text-label">
279+
Input Label
280+
</FormElementLabel>
278281
<FormElementControl className="slds-input-has-fixed-addon">
279282
<span className="slds-form-element__addon" id="fixed-text-addon-pre">
280283
$
281284
</span>
282-
<Input aria-describedby="fixed-text-addon-pre fixed-text-addon-post" />
285+
<Input aria-labelledby="fixed-text-label fixed-text-addon-pre fixed-text-addon-post" />
283286
<span className="slds-form-element__addon" id="fixed-text-addon-post">
284287
euro
285288
</span>

0 commit comments

Comments
 (0)