Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note on autocomplete attribute #867

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion content/components/text-input.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ The input must have an associated `<label>` to give it an accessible name that i

If the text input's value is invalid, this must be programmatically conveyed, and not solely rely on visual styling (such as a colored border). In addition, the form must show a descriptive error message that provides further information to the user about what the error is, and how to correct it. See [documentation for form validation](https://primer.style/ui-patterns/forms/overview#validation) for further details.

- Text inputs must have a visible label. While the component allows for labels to be visually hidden, this is only permitted if there is equivalent visible text already within the page that acts as a label for the input. [@COMMENT: In limited cases an icon alone could act as the visible label, so not just text.
- Text inputs must have a visible label. While the component allows for labels to be visually hidden, this is only permitted if there is equivalent visible text already within the page that acts as a label for the input. In limited cases an icon alone could act as the visible label, so not just text.
- [Placeholder text](/guides/accessibility/placeholders) is **never** an acceptable substitute for a label because:
- The placeholder text disappears as soon as the input has a value
- Placeholder text colors are typically too light to meet the minimum color contrast ratio required for accessibility
- Do not rely solely on placeholder text as a label. Once a user enters information in a text input, this placeholder text won't be visible anymore, effectively leading to the input lacking a label.
- Text inputs whose value is used to filter a list of results should be paired with an announcement for the effect of the filter. For more information, see the [conveying status (filter results)](/ui-patterns/loading#filter-results) section of the loading state pattern guidelines.
- Text inputs should typically include an `autocomplete` attribute with the appropriate value, as this can help users understand the purpose of text input.
TylerJDev marked this conversation as resolved.
Show resolved Hide resolved

### Built-in accessibility features

Expand All @@ -174,6 +175,8 @@ Rails and React implementations automatically associate input captions and valid

The colors used to visually denote the validation state of the input meet minimum color contrast requirements.

Usage of the `autocomplete` attribute is available in `TextInput` via the `autoComplete` prop in the React version.

### Implementation requirements

When using Octicons for leading and trailing visuals, note that icons don't have any text alternative. They are purely visual, and not conveyed to screen readers. Don't rely on these icons alone to convey meaning – make sure that the text label of the button provides sufficient meaning/context on its own.
Expand All @@ -182,19 +185,24 @@ In the React version, when setting the `loading` property, the component will in

While the Rails version of the component allows for the visible label of the text input to be hidden using `visually_hide_label`, this should only be done if there is an equivalent visible text that acts as the label. In that case, make sure that the actual label / accessible name of the input matches, or is at least contained within, the visible text acting as the label.

If using this component in a way where the input can be mapped to an `autocomplete` value, you should utilize the `autocomplete` attribute with the correct value.

### How to test the component

#### Integration tests

- The text input has a sufficiently descriptive visible label, and does not rely on the use of placeholder text alone to act as the visible label
- If the text input includes icons for its leading or trailing visuals, the input's purpose is clear even without the icons (as these are only decorative and are not conveyed to screen reader users)
- In the React version, when using the `loading` state, this state is conveyed appropriately to screen reader users
- Ensure that the text input has a `autocomplete` attribute attached, if the field can be mapped to an [autocomplete value](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#token_list_tokens).
TylerJDev marked this conversation as resolved.
Show resolved Hide resolved

#### Component tests

The `<label for="…">` attribute must point to the `id` of the `<input>`
- If the component is set to `disabled`, the rendered `<input>` includes the `disabled` HTML attribute
- If the component has a `placeholder` attribute, the rendered `<input>` includes the `placeholder` HTML attribute
- If the component has a `autocomplete` attribute, the rendered `<input>` includes the `autocomplete` HTML attribute
- If the component has a `autocomplete` attribute, the correct value is used for the `autocomplete` HTML attribute.
TylerJDev marked this conversation as resolved.
Show resolved Hide resolved
- In the Rails implementation, if the component has a `caption`, the caption is rendered as an additional container underneath the `<input>`, and the `<input>` has an `aria-describedby="…"` pointing to the `id` attribute of the container
- In the Rails implementation, if the component has a `validationMessage`, the message is rendered as an additional container underneath the `<input>`, and the `<input>` has an `aria-describedby="…"` pointing to the `id` attribute of the container
- In the React implementation, text input fields are composed with the `FormControl` component.
Expand Down
Loading