Skip to content

Commit 87fb7d9

Browse files
committed
Imporove readme
1 parent 10c965a commit 87fb7d9

File tree

1 file changed

+72
-4
lines changed

1 file changed

+72
-4
lines changed

README.md

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ $ npm install @github/filter-input-element
1010

1111
## Usage
1212

13-
```js
14-
import '@github/filter-input-element'
15-
```
16-
1713
```html
1814
<filter-input aria-owns="robots">
1915
<label>
@@ -33,6 +29,78 @@ import '@github/filter-input-element'
3329
</div>
3430
```
3531

32+
## Elements and attributes
33+
34+
### Required
35+
36+
- `filter-input[aria-owns]` should point to the container ID that wraps all `<filter-input>` related elements.
37+
- `filter-input` should have one `input` child element that is used to filter.
38+
- `[id]` should be set on a container that either contains or has `[data-filter-list]` attribute.
39+
- `[data-filter-list]` should be set on the element whose **direct child elements** are to be filtered.
40+
41+
### Optional
42+
43+
#### Specify filter text
44+
45+
Use `[data-filter-item-text]` to specify an element whose text should be used for filtering. In the following example, the text `(current)` would not be matched.
46+
47+
```html
48+
<div data-filter-list>
49+
<a href="/bender">Bender</a>
50+
<a href="/hubot">
51+
<span data-filter-item-text>Hubot</span>
52+
(current)
53+
</a>
54+
</div>
55+
```
56+
57+
#### Blankslate
58+
59+
Use `[data-filter-empty-state]` to specify an element to be displayed when no results were found. This element must be inside of the container `aria-owns` points to.
60+
61+
```html
62+
<div id="filter-list">
63+
<div data-filter-list>
64+
<a href="/bender">Bender</a>
65+
<a href="/hubot">Hubot</a>
66+
</div>
67+
<div data-filter-empty-state hidden>No results found.</div>
68+
</div>
69+
```
70+
71+
#### Create new actions
72+
73+
Use `[data-filter-new-item]` to include an item to create a new instance when no exact match were found. The element with `[data-filter-new-text]`'s text content will be set to the input value. You can also use `[data-filter-new-value]` to set an input value to the query param.
74+
75+
```html
76+
<div id="filter-list">
77+
<div data-filter-list>
78+
<a href="/bender">Bender</a>
79+
<a href="/hubot">Hubot</a>
80+
</div>
81+
<a href="/new" data-filter-new-item hidden>
82+
Create new robot named "<span data-filter-new-item-text></span>"
83+
</a>
84+
</div>
85+
```
86+
87+
## Methods
88+
89+
`filterInputElement.filter` can be optionally set to provide an alternative filtering logic. The default is substring.
90+
91+
```js
92+
const fuzzyFilterInput = document.querySelector('.js-fuzzy-filter-input')
93+
fuzzyFilterInput.filter = (element, elementText, query) => {
94+
// fuzzy filtering logic
95+
return {match: boolean, hideNew: boolean}
96+
}
97+
```
98+
99+
## Events
100+
101+
- `filter-input-start` (bubbles) - fired on `<filter-input>` when a filter action is about to start.
102+
- `filter-input-updated` (bubbles) - fired on `<filter-input>` when filter has finished. `event.detail.count` is the number of matches found, and `event.detail.total` is the total number of elements.
103+
36104
## Browser support
37105

38106
Browsers without native [custom element support][support] require a [polyfill][].

0 commit comments

Comments
 (0)