Skip to content

Commit c2b3088

Browse files
committed
feat: add back to top and autocomplete
1 parent 3e29923 commit c2b3088

File tree

8 files changed

+618
-66
lines changed

8 files changed

+618
-66
lines changed

content/en/patterns/content-management/modal.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ import { Callout } from "nextra/components";
1212
[contributing](https://github.com/thedaviddias/ux-patterns-for-developers/blob/main/.github/CONTRIBUTING.md)
1313
to add content.
1414
</Callout>
15+
16+
**_(Also called dialg, dialog box, overlay, popup)_**

content/en/patterns/forms/autocomplete.mdx

Lines changed: 92 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
---
22
description: "Suggest options as users type"
33
icon: Search
4-
status: draft
4+
status: complete
55
---
66

77
import { BrowserSupport } from "@app/_components/browser-support";
8-
import { Callout } from "nextra/components";
98

109
# Autocomplete
1110

12-
**_(Also called )_**
13-
14-
- Autosuggest
15-
16-
<Callout type="warning">
17-
This page is a work in progress. Don't consider it complete yet.
18-
</Callout>
11+
**_(Also called Autosuggest)_**
1912

2013
## Overview
2114

22-
The **Autocomplete** is an interactive input component that help users quickly find and select values from a predefined list of options as they type.
15+
The **autocomplete** is an interactive input component that helps users quickly find and select values from a predefined list of options as they type.
2316

2417
They combine the flexibility of text input with dropdown-style selection, providing suggestions that match the user's input in real-time. This pattern reduces errors, speeds up data entry, and improves the overall form completion experience.
2518

@@ -43,110 +36,160 @@ They combine the flexibility of text input with dropdown-style selection, provid
4336

4437
### Common scenarios and examples
4538

46-
- [Example 1]
47-
- [Example 2]
48-
- [Example 3]
39+
- **Searching for products** in an e-commerce catalog
40+
- **Entering city names** for travel or weather applications
41+
- **Looking up user or contact names** in a messaging or collaboration tool
4942

5043
## Benefits
5144

52-
- [Benefit 1]
53-
- [Benefit 2]
54-
- [Benefit 3]
45+
- **Speeds up data entry** by narrowing down possible options in real-time
46+
- **Reduces user frustration** and guesswork by guiding them to valid options
47+
- **Minimizes mistakes** and typos, as suggestions can be confirmed or chosen from a list
5548

5649
## Anatomy
5750

5851
### Component Structure
5952

6053
1. **Container**
6154

55+
- Wraps the entire autocomplete area, including the input and dropdown
56+
- Handles positioning, sizing, and possible floating layers for the suggestions
57+
6258
2. **Input**
6359

60+
- The text field where users type their query
61+
- Provides real-time updates and triggers suggestion fetching
62+
6463
3. **Label**
6564

65+
- Optional text label describing the input’s purpose
66+
- Provides clarity for screen readers and visible context for users
67+
6668
4. **Clear Button**
6769

70+
- Allows users to quickly clear the input field
71+
- Often represented by an “X” or “✕” icon
72+
6873
## Best Practices
6974

7075
### Content
7176

7277
**Do's ✅**
7378

74-
- [Best practice 1]
75-
- [Best practice 2]
79+
- Provide a descriptive label that indicates the purpose of the Autocomplete field
80+
- Use placeholder text to show example input (e.g., "Start typing a country...")
7681

7782
**Don'ts ❌**
7883

79-
- [Anti-pattern 1]
80-
- [Anti-pattern 2]
84+
- Don’t rely on placeholder text as a replacement for a label
85+
- Don’t make your suggestions so vague that it’s unclear what the user is selecting
8186

8287
### Accessibility & UX
8388

8489
**Do's ✅**
8590

86-
- [Best practice 1]
87-
- [Best practice 2]
91+
- Use `aria-controls`, `aria-autocomplete`, and other relevant ARIA attributes to help screen readers
92+
- Include a visually hidden label or descriptive text if you rely on an icon-only clear button
93+
- Add a debounce delay to the input field to avoid triggering a fetch request too often
8894

8995
**Don'ts ❌**
9096

91-
- [Anti-pattern 1]
92-
- [Anti-pattern 2]
97+
- Don’t remove focus outlines without providing alternative focus indicators
98+
- Don’t assume all users can use a mouse; ensure keyboard navigation works properly
9399

94100
### Visual Design
95101

96102
**Do's ✅**
97103

98-
- [Best practice 1]
99-
- [Best practice 2]
104+
- Keep the suggestion list clearly delineated, with sufficient contrast and spacing
105+
- Highlight hovered or focused suggestion items with a distinct visual state
100106

101107
**Don'ts ❌**
102108

103-
- [Anti-pattern 1]
104-
- [Anti-pattern 2]
109+
- Don’t display an overly large list of suggestions (limit it to a reasonable number), use a scroll bar to allow users to scroll through the list.
110+
- Don’t create a cluttered or confusing interface by mixing too many design elements
105111

106112
### Layout & Positioning
107113

108114
**Do's ✅**
109115

110-
- [Best practice 1]
111-
- [Best practice 2]
116+
- Position the dropdown list immediately below the input field
117+
- Ensure suggestions list appears in front of other page elements when open
112118

113119
**Don'ts ❌**
114120

115-
- [Anti-pattern 1]
116-
- [Anti-pattern 2]
121+
- Don’t hide the list behind overlays or modals
122+
- Don’t move the dropdown to a completely different area away from the input
117123

118124
## Code Examples
119125

120126
### Basic Implementation
121127

122128
```html
123-
<!-- Basic implementation example -->
129+
<!-- Basic Autocomplete Markup -->
130+
<div>
131+
<label for="autocompleteInput">Search for an option</label>
132+
<input
133+
type="text"
134+
id="autocompleteInput"
135+
name="autocompleteInput"
136+
aria-autocomplete="list"
137+
aria-controls="suggestions-list"
138+
autocomplete="off"
139+
placeholder="Type to search..."
140+
/>
141+
<button type="button" aria-label="Clear input">✕</button>
142+
<ul id="suggestions-list" role="listbox">
143+
<!-- Dynamically generated suggestions go here -->
144+
</ul>
145+
</div>
124146
```
125147

126-
## SEO
127-
128-
- [SEO consideration 1]
129-
- [SEO consideration 2]
130-
131-
## Testing Guidelines
132-
133-
### Functional Testing
134-
135-
**Should ✓**
136-
137-
- [Test case 1]
138-
- [Test case 2]
139-
140148
## Design Tokens
141149

142150
These design tokens follow the [Design Tokens Format](https://design-tokens.github.io/community-group/format/) specification and can be used with various token transformation tools to generate platform-specific variables.
143151

144152
### Autocomplete Tokens in DTF Format
145153

146-
```json:.json
154+
```json
147155
{
148156
"$schema": "https://design-tokens.org/schema.json",
149-
"Autocomplete": {}
157+
"Autocomplete": {
158+
"container": {
159+
"borderRadius": {
160+
"value": "0.25rem",
161+
"type": "dimension"
162+
},
163+
"background": {
164+
"value": "{color.white}",
165+
"type": "color"
166+
}
167+
},
168+
"input": {
169+
"fontSize": {
170+
"value": "1rem",
171+
"type": "dimension"
172+
},
173+
"padding": {
174+
"value": "0.5rem",
175+
"type": "dimension"
176+
}
177+
},
178+
"suggestionsList": {
179+
"maxHeight": {
180+
"value": "200px",
181+
"type": "dimension"
182+
},
183+
"background": {
184+
"value": "{color.gray.50}",
185+
"type": "color"
186+
},
187+
"itemHoverBg": {
188+
"value": "{color.gray.100}",
189+
"type": "color"
190+
}
191+
}
192+
}
150193
}
151194
```
152195

@@ -160,8 +203,3 @@ These design tokens follow the [Design Tokens Format](https://design-tokens.gith
160203
## Documentation
161204

162205
- [WAI-ARIA: Combobox Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/)
163-
164-
### Libraries
165-
166-
- [Library 1]
167-
- [Library 2]

content/en/patterns/forms/checkbox.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ import { Callout } from "nextra/components";
1212
[contributing](https://github.com/thedaviddias/ux-patterns-for-developers/blob/main/.github/CONTRIBUTING.md)
1313
to add content.
1414
</Callout>
15+
16+
## Related components
17+
18+
- Only one selection: [Radio button](/patterns/forms/radio)
19+
- More compact with only one selection [dropdown menu](/patterns/forms/dropdown)
20+
- On and Off option [Toggle](/patterns/forms/toggle)

0 commit comments

Comments
 (0)