{"id":15048067,"url":"https://github.com/github/filter-input-element","last_synced_at":"2025-04-05T18:05:50.501Z","repository":{"id":37541656,"uuid":"224030701","full_name":"github/filter-input-element","owner":"github","description":"Display elements in a subtree that match filter input text.","archived":false,"fork":false,"pushed_at":"2025-03-29T04:08:27.000Z","size":559,"stargazers_count":52,"open_issues_count":0,"forks_count":10,"subscribers_count":250,"default_branch":"main","last_synced_at":"2025-03-29T05:19:36.974Z","etag":null,"topics":["custom-elements","web-components"],"latest_commit_sha":null,"homepage":"https://github.github.io/filter-input-element/examples/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/github.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-25T19:58:25.000Z","updated_at":"2025-03-29T04:08:30.000Z","dependencies_parsed_at":"2025-03-29T05:19:20.208Z","dependency_job_id":null,"html_url":"https://github.com/github/filter-input-element","commit_stats":{"total_commits":29,"total_committers":6,"mean_commits":4.833333333333333,"dds":0.3793103448275862,"last_synced_commit":"719a14660d95cc1dd980f24d1ec8c31ff3029d7a"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":"github/custom-element-boilerplate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Ffilter-input-element","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Ffilter-input-element/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Ffilter-input-element/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Ffilter-input-element/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/github","download_url":"https://codeload.github.com/github/filter-input-element/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247378138,"owners_count":20929296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["custom-elements","web-components"],"created_at":"2024-09-24T21:07:37.372Z","updated_at":"2025-04-05T18:05:50.479Z","avatar_url":"https://github.com/github.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u0026lt;filter-input\u0026gt; element ![](https://github.com/github/filter-input-element/workflows/Node%20CI/badge.svg)\n\nDisplay elements in a subtree that match filter input text.\n\n## Installation\n\n```\n$ npm install @github/filter-input-element\n```\n\n## Usage\n\n```html\n\u003cfilter-input aria-owns=\"robots\"\u003e\n  \u003clabel\u003e\n    Filter robots\n    \u003cinput type=\"text\" autofocus autocomplete=\"off\"\u003e\n  \u003c/label\u003e\n\u003c/filter-input\u003e\n\u003cdiv id=\"robots\"\u003e\n  \u003cul data-filter-list\u003e\n    \u003cli\u003eBender\u003c/li\u003e\n    \u003cli\u003eHubot\u003c/li\u003e\n    \u003cli\u003eWall-E\u003c/li\u003e\n    \u003cli\u003eBB-8\u003c/li\u003e\n    \u003cli\u003eR2-D2\u003c/li\u003e\n  \u003c/ul\u003e\n  \u003cp data-filter-empty-state hidden\u003e0 robots found.\u003c/p\u003e\n\u003c/div\u003e\n```\n\n## Elements and attributes\n\n### Required\n\n- `filter-input[aria-owns]` should point to the container ID that wraps all `\u003cfilter-input\u003e` related elements.\n- `filter-input` should have one `input` child element that is used to filter.\n- `[id]` should be set on a container that either contains or has `[data-filter-list]` attribute.\n- `[data-filter-list]` should be set on the element whose **direct child elements** are to be filtered.\n\n### Optional\n\n#### Specify filter text\n\nUse `[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.\n\n```html\n\u003cdiv data-filter-list\u003e\n  \u003ca href=\"/bender\"\u003eBender\u003c/a\u003e\n  \u003ca href=\"/hubot\"\u003e\n    \u003cspan data-filter-item-text\u003eHubot\u003c/span\u003e\n    (current)\n  \u003c/a\u003e\n\u003c/div\u003e\n```\n\n#### Blankslate\n\nUse `[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.\n\n```html\n\u003cdiv id=\"filter-list\"\u003e\n  \u003cdiv data-filter-list\u003e\n    \u003ca href=\"/bender\"\u003eBender\u003c/a\u003e\n    \u003ca href=\"/hubot\"\u003eHubot\u003c/a\u003e\n  \u003c/div\u003e\n  \u003cdiv data-filter-empty-state hidden\u003eNo results found.\u003c/div\u003e\n\u003c/div\u003e\n```\n\n#### Create new item\n\nUse `[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.\n\n```html\n\u003cdiv id=\"filter-list\"\u003e\n  \u003cdiv data-filter-list\u003e\n    \u003ca href=\"/bender\"\u003eBender\u003c/a\u003e\n    \u003ca href=\"/hubot\"\u003eHubot\u003c/a\u003e\n  \u003c/div\u003e\n  \u003cform action=\"/new\" data-filter-new-item hidden\u003e\n    \u003cbutton name=\"robot\" data-filter-new-item-value\u003e\n      Create robot \"\u003cspan data-filter-new-item-text\u003e\u003c/span\u003e\"\n    \u003c/button\u003e\n  \u003c/form\u003e\n\u003c/div\u003e\n```\n\n## Methods\n\n`filterInputElement.filter` can be optionally set to provide an alternative filtering logic. The default is substring.\n\n```js\nconst fuzzyFilterInput = document.querySelector('.js-fuzzy-filter-input')\nfuzzyFilterInput.filter = (element, elementText, query) =\u003e {\n  // fuzzy filtering logic\n  return {match: boolean, hideNew: boolean}\n}\n```\n\n`match`(required) indicates whether the item should be shown. `hideNew` (optional) will determine whether the \"Create new item\" element should be hidden. For example, when an exact match is found, the \"create new item\" option should be hidden.\n\n## Events\n\n- `filter-input-start` (bubbles) - fired on `\u003cfilter-input\u003e` when a filter action is about to start.\n- `filter-input-updated` (bubbles) - fired on `\u003cfilter-input\u003e` when filter has finished. `event.detail.count` is the number of matches found, and `event.detail.total` is the total number of elements.\n\nTo ensure that the client side update is communicated to assistive technologies, `filter-input-updated` event can be used to update filter results to screen readers. For example:\n\n```js\nconst ariaLiveContainer = document.querySelector('[aria-live=\"assertive\"]')\ndocument.addEventListener('filter-input-updated', event =\u003e {\n  ariaLiveContainer.textContent = `${event.detail.count} results found.`\n})\n```\n\nFor more details on this technique, check out [Improving accessibility on GOV.UK search](https://technology.blog.gov.uk/2014/08/14/improving-accessibility-on-gov-uk-search/).\n\n## Browser support\n\nBrowsers without native [custom element support][support] require a [polyfill][].\n\n- Chrome\n- Firefox\n- Safari\n- Microsoft Edge\n\n[support]: https://caniuse.com/#feat=custom-elementsv1\n[polyfill]: https://github.com/webcomponents/custom-elements\n\n## Development\n\n```\nnpm install\nnpm test\n```\n\n## License\n\nDistributed under the MIT license. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Ffilter-input-element","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithub%2Ffilter-input-element","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Ffilter-input-element/lists"}