1.0.0 • Published 12 months ago

@financial-times/spark-o-autocomplete v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

spark-o-autocomplete

Spark-o-autcomplete is a React based version of the o-autocomplete component.

How to use

To install via npm, run:

npm i @financial-times/spark-o-autocomplete

Example usage:

import Autocomplete from '@financial-times/spark-o-autocomplete';

async function fetchSuggestions(query, populateSuggestions) {
	const results = await fetch(LOOKUP_API); // API call to look up suggestions for query
	populateSuggestions(results);
}

function mapOptionToSuggestedValue(option) {
	// used to convert object to string to display
}

<Autocomplete
	id="spark-admin-user-lookup"
	source={fetchSuggestions}
	mapOptionToSuggestedValue={mapOptionToSuggestedValue}
	onConfirm={onConfirm}
	defaultValue={selectedUser._id}
/>

The <Autocomplete> react component is designed to work with dynamic suggestions.

For more information about the o-autocomplete component, see the Origami docs.

Props

proptyperequireddescription
idstringyesUnique ID for the HTML element
sourcefunctionyessee o-autocomplete docs
mapOptionToSuggestedValuefunctionnosee o-autocomplete docs
onConfirmfunctionnofunction that is called when a suggestion is selected. Takes a single argument of the selected option.
defaultValuestringnovalue to show when the component loads
1.0.0

12 months ago