{"id":13437093,"url":"https://github.com/ezequiel/react-typeahead-component","last_synced_at":"2025-03-19T06:30:37.049Z","repository":{"id":32196275,"uuid":"35769847","full_name":"ezequiel/react-typeahead-component","owner":"ezequiel","description":"Typeahead, written using the React.js library.","archived":true,"fork":false,"pushed_at":"2016-04-26T02:17:48.000Z","size":2240,"stargazers_count":221,"open_issues_count":24,"forks_count":76,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-12T03:42:12.554Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/ezequiel.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":null,"security":null,"support":null}},"created_at":"2015-05-17T14:46:18.000Z","updated_at":"2025-03-05T07:05:22.000Z","dependencies_parsed_at":"2022-07-16T00:30:35.744Z","dependency_job_id":null,"html_url":"https://github.com/ezequiel/react-typeahead-component","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezequiel%2Freact-typeahead-component","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezequiel%2Freact-typeahead-component/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezequiel%2Freact-typeahead-component/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezequiel%2Freact-typeahead-component/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ezequiel","download_url":"https://codeload.github.com/ezequiel/react-typeahead-component/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243790982,"owners_count":20348379,"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":[],"created_at":"2024-07-31T03:00:54.287Z","updated_at":"2025-03-19T06:30:37.040Z","avatar_url":"https://github.com/ezequiel.png","language":"JavaScript","funding_links":[],"categories":["Uncategorized","UI Components","Demos","\u003csummary\u003eUI Components\u003c/summary\u003e"],"sub_categories":["Uncategorized","Form Components"],"readme":"Typeahead, written using the React.js library.\r\n==============================================\r\n\r\n**NOTE: No longer in development. Please fork.**\r\n\r\nFeatures\r\n========\r\n* Accessibility.\r\n* BiDi support for RTL languages.\r\n* Keyboard navigation.\r\n* Hinting support for the current input value.\r\n* Autocompletion of the hint when possible.\r\n* Custom templates for each option.\r\n* Auto-closing dropdown for the options list.\r\n* **5KB minified+gzipped!**\r\n\r\nDemo\r\n=============\r\n**YouTube**\r\nhttp://ezequiel.github.io/react-typeahead-component/youtube\r\n\r\n**Netflix**\r\nhttp://ezequiel.github.io/react-typeahead-component/netflix\r\n\r\nExamples\r\n--------\r\n\r\n**A Netflix autocomplete widget**.\r\n\r\nIt uses the [`RxJs`](http://reactive-extensions.github.io/RxJS/) in conjunction with Netflix's API. It also takes from Netflix's newest layout redesign.\r\n\r\n![netflix](https://cloud.githubusercontent.com/assets/368069/8123520/ed4419e8-107f-11e5-8134-d13c22fcf5d2.gif)\r\n\r\n**YouTube's Autocomplete widget**. It uses the [Flux application architecture](https://facebook.github.io/flux/) in conjunction with YouTube's API.\r\n\r\n![youtube11](https://cloud.githubusercontent.com/assets/368069/7670388/3ab8d8ae-fc57-11e4-8fc1-7ff020e76bf1.gif)\r\n\r\n**Yahoo Mail** (this component is used in production by Yahoo Mail).\r\n\r\n![mail11](https://cloud.githubusercontent.com/assets/368069/7670476/137c5960-fc5b-11e4-9b9f-6d125a532239.gif)\r\n\r\n\r\nGetting started\r\n---------------\r\n\r\nIf you're developing using npm and CommonJS modules:\r\n```\r\nnpm i react-typeahead-component\r\n```\r\n```jsx\r\nvar React = require('react'),\r\n    Typeahead = require('react-typeahead-component');\r\n\r\nReact.render(\r\n    // Pass in the desired props\r\n    \u003cTypeahead\r\n        placeholder='Search'\r\n        ...\r\n    /\u003e,\r\n\r\n    // Render Typeahead into the container of your choice.\r\n    document.body\r\n);\r\n```\r\n\r\nYou may also want to download one of the distributions from the `dist` folder, and load it in the browser that way. A global variable named `Typeahead` will be available to use.\r\n\r\nClass names\r\n-----------\r\n\r\nThese are some default classes names provided by the component. You may override and provide your own styling.\r\n\r\n**react-typeahead-container**\r\n  * A `div` element containing the entire Typeahead.\r\n\r\n**react-typeahead-input-container**\r\n  * A `div` element containing the usertext and hint.\r\n\r\n**react-typeahead-usertext**\r\n  * An `input` element containing the usertext.\r\n\r\n**react-typeahead-hint**\r\n  * An `input` element containing the hint.\r\n\r\n**react-typeahead-options**\r\n  * A `ul` element containing the rendered list of options.\r\n\r\nAvailable props:\r\n----------------\r\n\r\n#### *ReactElement* optionTemplate ***required***\r\nThis determines how to render each option. It is required. It should a reference to a ReactElement. It is instantiated for every item in `options`.\r\n\r\nWhen instantiated, it is passed these props:\r\n\r\n * `index` - The position of this option in the `options` list.\r\n * `data` - The raw data of this option.\r\n * `userInputValue` - The value the user has **actually typed**.\r\n * `inputValue` - Typeahead's current input value. Note: this may be different than `userInputValue`.\r\n * `isSelected` - Is this option currently selected? This will be `true` on when hovered over, or arrowed to.\r\n\r\n**Example**:\r\n\r\n```jsx\r\n// OptionTemplate.jsx\r\nmodule.exports = React.createClass({\r\n    render: function() {\r\n        var bgColor = null;\r\n\r\n        // If this option is currently selected, render it with a green background.\r\n        if (this.props.isSelected) {\r\n            bgColor = {\r\n                color: 'green'\r\n            };\r\n        }\r\n\r\n        return (\r\n            \u003cdiv style={bgColor}\u003e\r\n                \u003cp\u003eMy name is {this.props.data.name}!\u003c/p\u003e\r\n            \u003c/div\u003e\r\n        );\r\n    }\r\n});\r\n\r\n// Then in your main app...\r\nvar OptionTemplate = require('./OptionTemplate.jsx');\r\n\r\n\u003cTypeahead\r\n    optionTemplate={OptionTemplate}\r\n/\u003e\r\n```\r\n#### *string* inputId ***optional***\r\nThis input id is used for the Typeahead's input element.\r\n\r\nFor example, this allows us to associate a label with the Typeahead's input element. Screen readers will then be able to read the label once the Typeahead is focused.\r\n\r\n```jsx\r\n\u003clabel for=\"message-to-field\"\u003eTo\u003c/label\u003e\r\n\r\n\u003cTypeahead\r\n    inputId=\"message-to-field\"\r\n    ...\r\n/\u003e\r\n```\r\n\r\n#### *string* inputName ***optional***\r\n* This input name is used for the Typeahead's input element. Useful if the Typeahead happens to be inside of a `form` element.\r\n\r\n#### *string* className ***optional***\r\n* This class name is used for the Typeahead's container.\r\n\r\n#### *string* inputValue ***optional***\r\n* The input element's `value` attribute. **NOTE**: You must pass this prop to Typeahead display the value. You have control of the current input value.\r\n\r\n#### *array* options ***optional***\r\n* These options are used when rendering the options list. It can contain data of any type.\r\n\r\n#### *boolean* autoFocus ***optional***\r\n* If true, the input element is focused on the initial render.\r\n\r\n#### *string* placeholder ***optional***\r\n* The input element's `placeholder` attribute.\r\n\r\n#### *string* hoverSelect ***optional***\r\n* By default, hovering over an option causes it to be selected.\r\n\r\n#### *function* onComplete(*event*, *completedInputValue*) ***optional***\r\nFires when the user is attempting to complete the input element's hint. If there is no hint, it will not be called.\r\n\r\nThis function is called when the user presses the `ArrowRight`, `Tab`, or `End` keys. `ArrowLeft` is used instead of `ArrowRight` **if** the input value is RTL.\r\n\r\n**Example**:\r\n\r\n```jsx\r\nhandleComplete: function(event, completedInputValue) {\r\n    this.setState({\r\n        inputValue: completedInputValue\r\n    });\r\n}\r\n\r\n\u003cTypeahead\r\n    inputValue={this.state.inputValue}\r\n    onComplete={this.handleComplete}\r\n/\u003e\r\n```\r\n\r\n#### *function* onDropdownOpen() ***optional***\r\n* Fires when the dropdown is opened. The dropdown opens as soon as something is typed, or up/down arrow keys are pressed, or when the input is focused.\r\n\r\n#### *function* onDropdownClose() ***optional***\r\n* Fires when the dropdown is closed. The dropdown may be closed when `Escape` or `Enter` is pressed, or if any option is clicked on, or if anywhere outside the Typeahead is clicked.\r\n\r\n#### *function* onChange(*event*) ***optional***\r\n* Fires when a change occurs on the input element.\r\n\r\n#### *function* onInputClick(*event*) ***optional***\r\n* Fires when the input element is clicked.\r\n\r\n#### *function* onKeyDown(*event*, optionData, selectedIndex) ***optional***\r\nFires when a key down occurs on the input element.\r\nIt is also passed the currently selected option, and its index.\r\nIf no option is selected, `optionData` is the input value, and `selectedIndex` is `-1`.\r\n\r\n#### *function* onKeyPress(*event*) ***optional***\r\n* Fires when a key press occurs on the input element.\r\n\r\n#### *function* onKeyUp(*event*) ***optional***\r\n* Fires when a key up occurs on the input element.\r\n\r\n#### *function* onFocus(*event*) ***optional***\r\n* Fires when the input element is focused.\r\n\r\n#### *function* onBlur(*event*) ***optional***\r\n* Fires when the input element is blurred.\r\n\r\n#### *function* onSelect(*event*) ***optional***\r\n* Fires when the input element's text is selected.\r\n\r\n#### *function* onOptionClick(*event*, optionData, index) ***optional***\r\n* Fires when an option is clicked. `optionData` is the option that was clicked.\r\n\r\n#### *function* onOptionChange(*event*, optionData, index) ***optional***\r\n* Fires when the user arrows up or down to an option. It is also called if the user arrows back to the input element, and in that case `index` is `-1`. `optionData` is the option, or input text, data that has been navigated to.\r\n\r\n#### *function* handleHint(inputValue, options) ***optional***\r\nThis function determines what the hint is. It is called whenever the input has changed. If a hint is considered available, it should return the entire string, otherwise return a default string.\r\n\r\n**Example**:\r\n\r\n```jsx\r\nhandleHint: function(inputValue, options) {\r\n    // If the current input value matches the first option,\r\n    // return that option. It will be used to display the hint.\r\n    if (new RegExp('^' + inputValue).test(options[0].first_name)) {\r\n\r\n        // This must return a string!\r\n        return options[0].first_name;\r\n    }\r\n\r\n    // No hint is available.\r\n    return '';\r\n}\r\n\r\n// Now pass it as a prop...\r\n\u003cTypeahead\r\n    handleHint={this.handleHint}\r\n/\u003e\r\n```\r\n\r\n#### *function* getMessageForOption(*optionData*) ***optional***\r\nThis is for accessibility. It is called when an option is clicked or arrowed to. `optionData` is the option we're currently on. The return value is then read by the screen reader. It is also called if the user arrows back to the input element. The string returned should be localized so it is read in the correct language.\r\n\r\n```js\r\ngetMessageForOption: function(optionData) {\r\n\r\n    switch (optionData.type) {\r\n    case 'PERSON':\r\n        return 'Search for the person ' + optionData.name;\r\n\r\n    case 'PLACE':\r\n        return 'Search for the place ' + optionData.name;\r\n\r\n    default:\r\n        return 'Search for the thing ' + optionData.name;\r\n    }\r\n}\r\n```\r\n\r\n#### *function* getMessageForIncomingOptions() ***optional***\r\nThis is for accessibility. It is called when a new set of options is passed into Typeahead. The return value is then read by the screen reader. The string returned should be localized so it is read in the correct language.\r\n\r\n```js\r\ngetMessageForIncomingOptions: function() {\r\n    return 'There are new options available. Use the up and down arrows to navigate.';\r\n}\r\n```\r\n\r\nDon't see your prop? [Create an issue](https://github.com/ezequiel/react-typeahead-component/issues/new?title=Missing%20prop) explaining your use case, and I will add it.\r\n\r\nTesting\r\n-------\r\nThe tests are written using [mocha](https://github.com/mochajs/mocha), and ran using [Karma](https://github.com/karma-runner/karma). Run the command `npm test` to perform a single run of the tests in PhantomJS, and `npm run test:dev` to debug the tests in Chrome.\r\n\r\nIssues\r\n------\r\nPlease [file an issue](https://github.com/ezequiel/react-typeahead-component/issues/new) if you find a bug, or need help.\r\n\r\nLicense\r\n-------\r\nThe MIT License (MIT)\r\nCopyright (c) 2015 Ezequiel Rodriguez\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezequiel%2Freact-typeahead-component","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fezequiel%2Freact-typeahead-component","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezequiel%2Freact-typeahead-component/lists"}