Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
react-typeahead-component
Advanced tools
YouTube http://ezequiel.github.io/react-typeahead-component/youtube
Netflix http://ezequiel.github.io/react-typeahead-component/netflix
A Netflix autocomplete widget.
It uses the RxJs
in conjunction with Netflix's API. It also takes from Netflix's newest layout redesign.
YouTube's Autocomplete widget. It uses the Flux application architecture in conjunction with YouTube's API.
Yahoo Mail (this component is used in production by Yahoo Mail).
If you're developing using npm and CommonJS modules:
npm i react-typeahead-component
var React = require('react'),
Typeahead = require('react-typeahead-component');
React.render(
// Pass in the desired props
<Typeahead
placeholder='Search'
...
/>,
// Render Typeahead into the container of your choice.
document.body
);
You 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.
These are some default classes names provided by the component. You may override and provide your own styling.
react-typeahead-container
div
element containing the entire Typeahead.react-typeahead-input-container
div
element containing the usertext and hint.react-typeahead-usertext
input
element containing the usertext.react-typeahead-hint
input
element containing the hint.react-typeahead-options
ul
element containing the rendered list of options.This determines how to render each option. It is required. It should a reference to a ReactElement. It is instantiated for every item in options
.
When instantiated, it is passed these props:
index
- The position of this option in the options
list.data
- The raw data of this option.userInputValue
- The value the user has actually typed.inputValue
- Typeahead's current input value. Note: this may be different than userInputValue
.isSelected
- Is this option currently selected? This will be true
on when hovered over, or arrowed to.Example:
// OptionTemplate.jsx
module.exports = React.createClass({
render: function() {
var bgColor = null;
// If this option is currently selected, render it with a green background.
if (this.props.isSelected) {
bgColor = {
color: 'green'
};
}
return (
<div style={bgColor}>
<p>My name is {this.props.data.name}!</p>
</div>
);
}
});
// Then in your main app...
var OptionTemplate = require('./OptionTemplate.jsx');
<Typeahead
optionTemplate={OptionTemplate}
/>
This input id is used for the Typeahead's input element.
For 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.
<label for="message-to-field">To</label>
<Typeahead
inputId="message-to-field"
...
/>
form
element.value
attribute. NOTE: You must pass this prop to Typeahead display the value. You have control of the current input value.placeholder
attribute.Fires when the user is attempting to complete the input element's hint. If there is no hint, it will not be called.
This 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.
Example:
handleComplete: function(event, completedInputValue) {
this.setState({
inputValue: completedInputValue
});
}
<Typeahead
inputValue={this.state.inputValue}
onComplete={this.handleComplete}
/>
Escape
or Enter
is pressed, or if any option is clicked on, or if anywhere outside the Typeahead is clicked.Fires when a key down occurs on the input element.
It is also passed the currently selected option, and its index.
If no option is selected, optionData
is the input value, and selectedIndex
is -1
.
optionData
is the option that was clicked.index
is -1
. optionData
is the option, or input text, data that has been navigated to.This 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.
Example:
handleHint: function(inputValue, options) {
// If the current input value matches the first option,
// return that option. It will be used to display the hint.
if (new RegExp('^' + inputValue).test(options[0].first_name)) {
// This must return a string!
return options[0].first_name;
}
// No hint is available.
return '';
}
// Now pass it as a prop...
<Typeahead
handleHint={this.handleHint}
/>
This 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.
getMessageForOption: function(optionData) {
switch (optionData.type) {
case 'PERSON':
return 'Search for the person ' + optionData.name;
case 'PLACE':
return 'Search for the place ' + optionData.name;
default:
return 'Search for the thing ' + optionData.name;
}
}
This 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.
getMessageForIncomingOptions: function() {
return 'There are new options available. Use the up and down arrows to navigate.';
}
Don't see your prop? Create an issue explaining your use case, and I will add it.
The tests are written using mocha, and ran using 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.
Please file an issue if you find a bug, or need help.
The MIT License (MIT) Copyright (c) 2015 Ezequiel Rodriguez
FAQs
Typeahead, written using the React.js library.
We found that react-typeahead-component demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.