{"id":15048173,"url":"https://github.com/github/combobox-nav","last_synced_at":"2025-04-05T01:04:46.313Z","repository":{"id":37502585,"uuid":"152649727","full_name":"github/combobox-nav","owner":"github","description":"Attach combobox navigation behavior to \u003cinput\u003e or \u003ctextarea\u003e.","archived":false,"fork":false,"pushed_at":"2025-03-11T18:47:09.000Z","size":1023,"stargazers_count":125,"open_issues_count":5,"forks_count":20,"subscribers_count":238,"default_branch":"main","last_synced_at":"2025-04-03T00:03:39.487Z","etag":null,"topics":["autocomplete","combobox","decorator"],"latest_commit_sha":null,"homepage":"https://github.github.io/combobox-nav/examples/index.html","language":"JavaScript","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":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-11T20:10:35.000Z","updated_at":"2025-03-23T04:14:05.000Z","dependencies_parsed_at":"2024-01-11T06:45:07.083Z","dependency_job_id":"c5e0bc97-bbe4-4388-b554-5d9fd7ceb98a","html_url":"https://github.com/github/combobox-nav","commit_stats":{"total_commits":149,"total_committers":15,"mean_commits":9.933333333333334,"dds":0.5234899328859061,"last_synced_commit":"8f17b1ee0de8151ab54077a06678c8c411a0c9ce"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fcombobox-nav","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fcombobox-nav/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fcombobox-nav/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fcombobox-nav/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/github","download_url":"https://codeload.github.com/github/combobox-nav/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271519,"owners_count":20911587,"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":["autocomplete","combobox","decorator"],"created_at":"2024-09-24T21:08:56.333Z","updated_at":"2025-04-05T01:04:46.295Z","avatar_url":"https://github.com/github.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Combobox Navigation\n\nAttach [combobox navigation behavior (ARIA 1.2)](https://www.w3.org/TR/wai-aria-1.2/#combobox) to `\u003cinput\u003e`.\n\n## Installation\n\n```\n$ npm install @github/combobox-nav\n```\n\n## Usage\n\n### HTML\n\n```html\n\u003clabel\u003e\n  Robot\n  \u003cinput id=\"robot-input\" type=\"text\" /\u003e\n\u003c/label\u003e\n\u003cul role=\"listbox\" id=\"list-id\" hidden\u003e\n  \u003cli id=\"baymax\" role=\"option\"\u003eBaymax\u003c/li\u003e\n  \u003cli\u003e\u003cdel\u003eBB-8\u003c/del\u003e\u003c/li\u003e\n  \u003c!-- `role=option` needs to be present for item to be selectable --\u003e\n  \u003cli id=\"hubot\" role=\"option\"\u003eHubot\u003c/li\u003e\n  \u003cli id=\"r2-d2\" role=\"option\"\u003eR2-D2\u003c/li\u003e\n\u003c/ul\u003e\n```\n\nMarkup requirements:\n\n- Each option needs to have `role=\"option\"` and a unique `id`\n- The list should have `role=\"listbox\"`\n\n### JS\n\n```js\nimport Combobox from '@github/combobox-nav'\nconst input = document.querySelector('#robot-input')\nconst list = document.querySelector('#list-id')\n\n// install combobox pattern on a given input and listbox\nconst combobox = new Combobox(input, list)\n// when options appear, start intercepting keyboard events for navigation\ncombobox.start()\n// when options disappear, stop intercepting keyboard events for navigation\ncombobox.stop()\n\n// move selection to the nth+1 item in the list\ncombobox.navigate(1)\n// reset selection\ncombobox.clearSelection()\n// uninstall combobox pattern from the input\ncombobox.destroy()\n```\n\n## Events\n\nA bubbling `combobox-commit` event is fired on the list element when an option is selected via keyboard or click.\n\nFor example, autocomplete when an option is selected:\n\n```js\nlist.addEventListener('combobox-commit', function (event) {\n  console.log('Element selected: ', event.target)\n})\n```\n\n\u003e **Note** When using `\u003clabel\u003e` + `\u003cinput\u003e` as options, please listen on `change` instead of `combobox-commit`.\n\nWhen a label is clicked on, `click` event is fired from both `\u003clabel\u003e` and its associated input `label.control`. Since combobox does not know about the control, `combobox-commit` cannot be used as an indicator of the item's selection state.\n\nA bubbling `combobox-select` event is fired on the list element when an option is selected but not yet committed.\n\nFor example, autocomplete when an option is selected but not yet committed:\n\n```js\nlist.addEventListener('combobox-select', function (event) {\n  console.log('Element selected : ', event.target)\n})\n```\n\n## Settings\n\nFor advanced configuration, the constructor takes an optional third argument. For example:\n\n```js\nconst combobox = new Combobox(input, list, {tabInsertsSuggestions: true})\n```\n\nThese settings are available:\n\n- `tabInsertsSuggestions: boolean = true` - Control whether the highlighted suggestion is inserted when \u003ckbd\u003eTab\u003c/kbd\u003e is pressed (\u003ckbd\u003eEnter\u003c/kbd\u003e will always insert a suggestion regardless of this setting). When `true`, tab-navigation will be hijacked when open (which can have negative impacts on accessibility) but the combobox will more closely imitate a native IDE experience.\n- `firstOptionSelectionMode: FirstOptionSelectionMode = 'none'` - This option dictates the default behaviour when no options have been selected yet and the user presses \u003ckbd\u003eEnter\u003c/kbd\u003e. The following values of `FirstOptionSelectionMode` will do the following:\n   - `'none'`: Don't auto-select the first option at all.\n   - `'active'`: Place the first option in an 'active' state where it is not selected (is not the `aria-activedescendant`) but will still be applied if the user presses `Enter`. To select the second item, the user would need to press the down arrow twice. This approach allows quick application of selections without disrupting screen reader users.\n   \u003e **Warning** Screen readers will not announce that the first item is the default. This should be announced explicitly with the use of `aria-live` status \n   - `'selected'`: Select the first item by navigating to it. This allows quick application of selections and makes it faster to select the second item, but can be disruptive or confusing for screen reader users.\n- `scrollIntoViewOptions?: boolean | ScrollIntoViewOptions = undefined` - When\n  controlling the element marked `[aria-selected=\"true\"]` with keyboard navigation, the selected element will be scrolled into the viewport by a call to [Element.scrollIntoView][]. Configure this value to control the scrolling behavior (either with a `boolean` or a [ScrollIntoViewOptions][] object.\n\n[Element.scrollIntoView]: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView\n[ScrollIntoViewOptions]: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView#sect1\n\n\n## Development\n\n```\nnpm install\nnpm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Fcombobox-nav","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithub%2Fcombobox-nav","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Fcombobox-nav/lists"}