Skip to content

Commit bc70f6c

Browse files
authored
Maintenance - PR#6 from glenn2223
- Updated dependencies - Converted eslint to the new format - Test formatting - Updated README
2 parents 0e940c4 + ff69f38 commit bc70f6c

16 files changed

+2068
-5639
lines changed

.eslintrc.json

Lines changed: 0 additions & 115 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212
with:
1313
node-version: '20.x'
1414
registry-url: 'https://registry.npmjs.org'
15-
- run: npm i tslib -g
1615
- run: npm ci --no-optional
1716
- run: npm publish --scope=@topmarksdevelopment --access public
1817
env:

README.md

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,54 @@
22

33
A small package to provide an autocomplete list as a user is typing.
44

5-
### Links
5+
### Contents
66

7+
- [Features](#features)
8+
- [Usage](#usage)
9+
- [Strong Types](#strong-types)
710
- [Options](#options)
811
- [Option Methods](#option-methods)
912
- [Change log](./CHANGELOG.md)
1013
- [License (MIT)](./LICENSE)
1114

15+
### Features
16+
17+
- Supports different sources; whether `string`, `object`, `array` or callback
18+
- Allows specification of the source type with strong types
19+
- Complete control over construction, with custom renderers
20+
- Option to automatically focus on the first element when the menu opens
21+
- Configurable delay between keystrokes and source calls
22+
- Supports a minimum term, before querying the source
23+
- Custom mapping of object properties to the generic type
24+
- Flexible positioning of the autocomplete box
25+
- Ability to append the menu to a specific element
26+
- Event callbacks for menu interactions and lifecycle events
27+
1228
## Usage
1329

1430
### Basic usage
1531

16-
To add autocomplete to an input with the class "`autocomplete`", use the sample code below - which will query the specified source URL and expect a JSON response.
17-
18-
Without specifying a type, autocomplete defaults to the generic type:
19-
`{ label: string; value: string }`
32+
> ℹ️ Without specifying a type, autocomplete defaults to the generic type:
33+
> `{ label: string; value: string }`
2034
2135
```TS
2236
// Using the default options (source is always required)
2337
new Autocomplete(
2438
'.autocomplete',
2539
{
40+
// Query this source & expect a JSON response
2641
source: './relative-folder/query.html'
2742
}
2843
)
2944
// Don't forget to start it
3045
.start();
3146
```
3247

33-
<details><summary>
34-
<h3>Custom source type</h3>
35-
</summary>
48+
### Strong Types
3649

37-
You can also specify the source type for some strong types!
50+
As the package is written in TypeScript, you can specify the `source`'s type.
51+
52+
With the type specified you can write your TypeScript with strong type definitions!
3853

3954
In this example I've provided an array of inputs (that will always be returned) - this is also strongly typed!
4055

@@ -44,7 +59,7 @@ type MyType = {
4459
myCustomValue: string;
4560
}
4661

47-
// Using the custom MyType (which is now tightly-bound)
62+
// Specifying MyType means "source" is now tightly-bound
4863
new Autocomplete<MyType>(
4964
'.autocomplete',
5065
{
@@ -69,7 +84,9 @@ new Autocomplete<MyType>(
6984

7085
li.dataset.value = item.myCustomName;
7186

72-
//li.innerText = item.detail; <-- This isn't in `MyType`
87+
// li.innerText = item.detail;
88+
// The above would now throw:
89+
// "Property 'detail' does not exist on type 'MyType'"
7390

7491
li.innerText = item.myCustomValue;
7592

@@ -81,8 +98,6 @@ new Autocomplete<MyType>(
8198
.start();
8299
```
83100

84-
</details>
85-
86101
## Options
87102

88103
### source: `SourceTypes<T>`
@@ -165,11 +180,12 @@ Called as soon as an item is focused, but before changing its state
165180
**Call:**
166181

167182
```TS
183+
// T is your generic type, if specified
168184
onItemFocus: (
169185
ev: Event,
170186
data: {
171187
ul: HTMLUListElement
172-
item: <T>, // Your generic type, if specified
188+
item: <T>,
173189
input: HTMLInputElement
174190
}
175191
) => {}
@@ -181,11 +197,12 @@ Called as soon as an item is selecetd, but before changing any state
181197
**Call:**
182198

183199
```TS
200+
// T is your generic type, if specified
184201
onItemSelect: (
185202
ev: Event,
186203
data: {
187204
ul: HTMLUListElement
188-
item: <T>, // Your generic type, if specified
205+
item: <T>,
189206
input: HTMLInputElement
190207
}
191208
) => {}
@@ -216,7 +233,6 @@ Called before processing the search
216233
**Call:**
217234

218235
```TS
219-
// T is your generic type, if specified
220236
onSearch: (ev: Event, data: { term: string }) => {}
221237
```
222238

@@ -226,7 +242,6 @@ A method called after events have been added
226242
**Call:**
227243

228244
```TS
229-
// T is your generic type, if specified
230245
onStart: () => {}
231246
```
232247

@@ -236,6 +251,5 @@ A method called after events have been removed
236251
**Call:**
237252

238253
```TS
239-
// T is your generic type, if specified
240254
onStop: () => {}
241255
```

0 commit comments

Comments
 (0)