@neo4j-ndl/react 5.6.3 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/icons/index.js +1 -1
- package/lib/cjs/index.js +4 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/search-field/SearchField.js +94 -0
- package/lib/cjs/search-field/SearchField.js.map +1 -0
- package/lib/cjs/search-field/index.js +30 -0
- package/lib/cjs/search-field/index.js.map +1 -0
- package/lib/cjs/side-navigation/SideNavigation.js +1 -1
- package/lib/cjs/side-navigation/SideNavigation.js.map +1 -1
- package/lib/cjs/text-input/TextInput.js +1 -1
- package/lib/cjs/text-input/TextInput.js.map +1 -1
- package/lib/esm/icons/index.mjs +1 -1
- package/lib/esm/index.mjs +4 -3
- package/lib/esm/index.mjs.map +1 -1
- package/lib/esm/search-field/SearchField.mjs +89 -0
- package/lib/esm/search-field/SearchField.mjs.map +1 -0
- package/lib/esm/search-field/index.mjs +24 -0
- package/lib/esm/search-field/index.mjs.map +1 -0
- package/lib/esm/side-navigation/SideNavigation.mjs +1 -1
- package/lib/esm/side-navigation/SideNavigation.mjs.map +1 -1
- package/lib/esm/text-input/TextInput.mjs +1 -1
- package/lib/esm/text-input/TextInput.mjs.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/search-field/SearchField.d.ts +52 -0
- package/lib/types/search-field/SearchField.d.ts.map +1 -0
- package/lib/types/search-field/index.d.ts +22 -0
- package/lib/types/search-field/index.d.ts.map +1 -0
- package/package.json +7 -2
- package/skills/ndl-react/SKILL.md +3 -2
- package/skills/ndl-react/components/search-field.md +254 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
[//]: # (This file is auto-generated by the docs:generate-skills script, do not edit it manually)
|
|
2
|
+
|
|
3
|
+
# SearchField
|
|
4
|
+
|
|
5
|
+
Import: `import { SearchField } from '@neo4j-ndl/react'`
|
|
6
|
+
|
|
7
|
+
## Props
|
|
8
|
+
|
|
9
|
+
### SearchField
|
|
10
|
+
|
|
11
|
+
| Prop | Type | Required | Default | Description |
|
|
12
|
+
|------|------|----------|---------|-------------|
|
|
13
|
+
| `debounceDelay` | `number` | | `500` | Delay in milliseconds before calling `onSearch` after the query changes. |
|
|
14
|
+
| `errorText` | `ReactNode` | | | Error message displayed below the input. When provided, it overrides `helpText` and shows an error icon |
|
|
15
|
+
| `helpText` | `ReactNode` | | | Assistive text displayed below the input |
|
|
16
|
+
| `isDisabled` | `boolean` | | | Whether the input is disabled |
|
|
17
|
+
| `isFluid` | `boolean` | | | Whether the input should take the full available width |
|
|
18
|
+
| `isLoading` | `boolean` | | | Whether to show the loading spinner |
|
|
19
|
+
| `isReadOnly` | `boolean` | | | Whether the input is read-only |
|
|
20
|
+
| `isSkeletonLoading` | `boolean` | | | Whether to render skeletons instead of content |
|
|
21
|
+
| `label` | `string` | ✅ | | Accessible name for the search field. The label is announced by assistive technologies but is not rendered visually. |
|
|
22
|
+
| `onChange` | `ChangeEventHandler<HTMLInputElement, HTMLInputElement>` | | | Callback function triggered when the input value changes |
|
|
23
|
+
| `onSearch` | `((query: string) => void)` | | | Called with the search query after typing pauses for `debounceDelay`, and immediately when the user presses Enter or clears the field. |
|
|
24
|
+
| `placeholder` | `string` | | | Placeholder text displayed when the input is empty |
|
|
25
|
+
| `ref` | `Ref<HTMLInputElement>` | | | A ref to apply to the root element. |
|
|
26
|
+
| `size` | `'large' \| 'medium' \| 'small'` | | | Size of the input |
|
|
27
|
+
| `skeletonProps` | `(SkeletonProps & { as?: ElementType<any, keyof IntrinsicElements>; } & BaseProps<ElementType<any, keyof IntrinsicElements>>)` | | | Additional props forwarded to the underlying Skeleton components |
|
|
28
|
+
| `value` | `string \| number \| readonly string[]` | | | The current value of the input |
|
|
29
|
+
|
|
30
|
+
SearchField renders a fixed search icon and uses the native `search` input
|
|
31
|
+
type. `onChange` is called immediately, while `onSearch` is debounced until
|
|
32
|
+
typing pauses. Pressing Enter or clearing the field calls `onSearch`
|
|
33
|
+
immediately.
|
|
34
|
+
|
|
35
|
+
## Accessibility
|
|
36
|
+
|
|
37
|
+
## Implementation guidelines
|
|
38
|
+
|
|
39
|
+
### Name and search landmark
|
|
40
|
+
|
|
41
|
+
The required `label` prop provides the search field's accessible name through `aria-label`; it is not displayed visually. Use a concise label that identifies the search scope or purpose, such as “Search documentation” rather than only “Search,” when context is needed. Do not pass a separate `aria-label` through `htmlAttributes`.
|
|
42
|
+
|
|
43
|
+
SearchField uses the native `search` input type and is exposed with the `searchbox` role.
|
|
44
|
+
|
|
45
|
+
Wrap the field in an element with `role="search"` when it provides page- or site-wide search. If a page has multiple search landmarks, give each landmark a distinct accessible name with `aria-label` or `aria-labelledby`.
|
|
46
|
+
|
|
47
|
+
### Results and status messages
|
|
48
|
+
|
|
49
|
+
Present results with appropriate page structure, such as a heading followed by a list of links. Keep focus in the search field when results update; do not automatically move focus into the results. This lets keyboard and screen reader users decide when to navigate to them.
|
|
50
|
+
|
|
51
|
+
Announce the completed result count in a persistent, polite live region, for example, “7 results for Neo4j” or “No results for Neo4j.” A `role="status"` region with `aria-atomic="true"` supports WCAG 2.2 SC 4.1.3 Status Messages (Level AA). Mount the empty status region before a search starts, update only its text, and do not place interactive content inside it.
|
|
52
|
+
|
|
53
|
+
For asynchronous searches, set `aria-busy="true"` on the results container while it is updating and remove it when the update completes. Communicate loading, failure, and recovery without clearing existing results prematurely. Avoid having multiple live regions announce the same update.
|
|
54
|
+
|
|
55
|
+
SearchField is not an autocomplete or combobox. If typing opens a selectable suggestions popup, use Combobox or implement the complete combobox keyboard and ARIA pattern rather than adding only `aria-expanded` to SearchField.
|
|
56
|
+
|
|
57
|
+
### Interaction
|
|
58
|
+
|
|
59
|
+
SearchField is always clearable. Pressing Escape clears a non-empty search field without moving focus. The same action is available with a pointer from the clear button.
|
|
60
|
+
|
|
61
|
+
`onChange` runs immediately so controlled fields can update their visible value as the user types. `onSearch` is debounced while typing, but runs immediately when the field is cleared or the user presses Enter.
|
|
62
|
+
|
|
63
|
+
If a consumer prevents the default Enter key behavior in `htmlAttributes.onKeyDown`, `onSearch` is not called.
|
|
64
|
+
|
|
65
|
+
## Examples
|
|
66
|
+
|
|
67
|
+
### Default
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import '@neo4j-ndl/base/lib/neo4j-ds-styles.css';
|
|
71
|
+
|
|
72
|
+
import { SearchField } from '@neo4j-ndl/react';
|
|
73
|
+
|
|
74
|
+
const Component = () => {
|
|
75
|
+
return <SearchField label="Search" placeholder="Search for something" />;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export default Component;
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Debounced
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
import '@neo4j-ndl/base/lib/neo4j-ds-styles.css';
|
|
85
|
+
|
|
86
|
+
import { SearchField, Typography } from '@neo4j-ndl/react';
|
|
87
|
+
import { useState } from 'react';
|
|
88
|
+
|
|
89
|
+
const Component = () => {
|
|
90
|
+
const [query, setQuery] = useState('');
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<div>
|
|
94
|
+
<SearchField
|
|
95
|
+
label="Search"
|
|
96
|
+
placeholder="Search for something"
|
|
97
|
+
onSearch={setQuery}
|
|
98
|
+
/>
|
|
99
|
+
<Typography as="p" variant="body-medium">
|
|
100
|
+
Latest query: {query || 'None'}
|
|
101
|
+
</Typography>
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export default Component;
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Results
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
import '@neo4j-ndl/base/lib/neo4j-ds-styles.css';
|
|
113
|
+
|
|
114
|
+
import { SearchField, Typography } from '@neo4j-ndl/react';
|
|
115
|
+
import { useEffect, useState } from 'react';
|
|
116
|
+
|
|
117
|
+
const documentationPages = [
|
|
118
|
+
{
|
|
119
|
+
description: 'Connect an application and run your first query.',
|
|
120
|
+
href: '#getting-started',
|
|
121
|
+
title: 'Getting started',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
description: 'Learn how nodes, relationships, and properties work.',
|
|
125
|
+
href: '#graph-data-model',
|
|
126
|
+
title: 'Graph data model',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
description: 'Read and write graph data with the Cypher query language.',
|
|
130
|
+
href: '#cypher-manual',
|
|
131
|
+
title: 'Cypher manual',
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
description: 'Configure drivers, authentication, and connection pooling.',
|
|
135
|
+
href: '#drivers',
|
|
136
|
+
title: 'Neo4j drivers',
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
description: 'Deploy and operate Neo4j in production.',
|
|
140
|
+
href: '#operations',
|
|
141
|
+
title: 'Operations manual',
|
|
142
|
+
},
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
const Component = () => {
|
|
146
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
147
|
+
const [query, setQuery] = useState<string | null>(null);
|
|
148
|
+
const [resultMessage, setResultMessage] = useState(
|
|
149
|
+
`${documentationPages.length} results`,
|
|
150
|
+
);
|
|
151
|
+
const [results, setResults] = useState(documentationPages);
|
|
152
|
+
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
if (query === null) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
setIsLoading(true);
|
|
159
|
+
|
|
160
|
+
const timeout = window.setTimeout(() => {
|
|
161
|
+
const normalizedQuery = query.trim().toLocaleLowerCase();
|
|
162
|
+
const nextResults = documentationPages.filter(({ description, title }) =>
|
|
163
|
+
`${title} ${description}`.toLocaleLowerCase().includes(normalizedQuery),
|
|
164
|
+
);
|
|
165
|
+
const querySuffix = query ? ` for ${query}` : '';
|
|
166
|
+
|
|
167
|
+
setResults(nextResults);
|
|
168
|
+
setResultMessage(
|
|
169
|
+
nextResults.length === 0
|
|
170
|
+
? `No results${querySuffix}`
|
|
171
|
+
: `${nextResults.length} ${
|
|
172
|
+
nextResults.length === 1 ? 'result' : 'results'
|
|
173
|
+
}${querySuffix}`,
|
|
174
|
+
);
|
|
175
|
+
setIsLoading(false);
|
|
176
|
+
}, 400);
|
|
177
|
+
|
|
178
|
+
return () => {
|
|
179
|
+
window.clearTimeout(timeout);
|
|
180
|
+
};
|
|
181
|
+
}, [query]);
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<main
|
|
185
|
+
style={{
|
|
186
|
+
display: 'grid',
|
|
187
|
+
gap: '24px',
|
|
188
|
+
maxWidth: '640px',
|
|
189
|
+
width: '100%',
|
|
190
|
+
}}
|
|
191
|
+
>
|
|
192
|
+
<div role="search" aria-label="Documentation">
|
|
193
|
+
<SearchField
|
|
194
|
+
label="Search documentation"
|
|
195
|
+
placeholder="Search documentation"
|
|
196
|
+
isLoading={isLoading}
|
|
197
|
+
onSearch={setQuery}
|
|
198
|
+
/>
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
<section aria-labelledby="search-results-heading">
|
|
202
|
+
<Typography
|
|
203
|
+
as="h2"
|
|
204
|
+
variant="title-3"
|
|
205
|
+
htmlAttributes={{ id: 'search-results-heading' }}
|
|
206
|
+
>
|
|
207
|
+
Documentation
|
|
208
|
+
</Typography>
|
|
209
|
+
<Typography
|
|
210
|
+
as="p"
|
|
211
|
+
variant="body-medium"
|
|
212
|
+
htmlAttributes={{ 'aria-atomic': 'true', role: 'status' }}
|
|
213
|
+
>
|
|
214
|
+
{resultMessage}
|
|
215
|
+
</Typography>
|
|
216
|
+
<div aria-busy={isLoading || undefined}>
|
|
217
|
+
{results.length > 0 ? (
|
|
218
|
+
<ul
|
|
219
|
+
style={{
|
|
220
|
+
display: 'grid',
|
|
221
|
+
gap: '16px',
|
|
222
|
+
listStyle: 'none',
|
|
223
|
+
margin: '16px 0 0',
|
|
224
|
+
padding: 0,
|
|
225
|
+
}}
|
|
226
|
+
>
|
|
227
|
+
{results.map(({ description, href, title }) => (
|
|
228
|
+
<li key={href}>
|
|
229
|
+
<Typography
|
|
230
|
+
as="a"
|
|
231
|
+
variant="body-medium"
|
|
232
|
+
htmlAttributes={{ href }}
|
|
233
|
+
>
|
|
234
|
+
{title}
|
|
235
|
+
</Typography>
|
|
236
|
+
<Typography
|
|
237
|
+
as="p"
|
|
238
|
+
variant="body-small"
|
|
239
|
+
style={{ margin: '4px 0 0' }}
|
|
240
|
+
>
|
|
241
|
+
{description}
|
|
242
|
+
</Typography>
|
|
243
|
+
</li>
|
|
244
|
+
))}
|
|
245
|
+
</ul>
|
|
246
|
+
) : null}
|
|
247
|
+
</div>
|
|
248
|
+
</section>
|
|
249
|
+
</main>
|
|
250
|
+
);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export default Component;
|
|
254
|
+
```
|