Comments (2)
The triggerChar is supposed to be a single character, that will fetch and build the autocomplete-list. On pressing the triggerChar, the dataProvider is called, and will get all following characters. The dataProvider could be a Promise, like an api-call, and the result is used to build the list.
Example:
export type AutocompleteListItem = {
name: string;
char: string;
}
export const fetchRecipeList = (searchTerm: string): Promise<Array<AutocompleteListItem>> =>
request()
.get(`${serverURLs.recipe}?search=${searchTerm}`)
.then(res => res.body.results.map((recipe: RecipeDto) => ({ key: recipe.slug, name: recipe.slug, char: recipe.title } as AutocompleteListItem)))
.catch(() => []);
interface IItemProps {
entity: AutocompleteListItem;
}
const Item = ({ entity: { char } }: IItemProps) => <div>{char}</div>;
<ReactTextareaAutocomplete<AutocompleteListItem>
/* ... */
trigger={{
':': {
dataProvider: token => fetchRecipeList(token),
component: Item,
output: item => item.char,
},
}} />
One can then type ':Beet' and the autocomplete-list will show all recipes for 'Beet'.
from react-textarea-autocomplete.
And just some clarification:
Can the trigger be current active word (or partial word), instead of the predefined chars or words?
This is probably undefined behaviour, but you could change the triggerChar dynamically. Just be aware that this package will treat the triggerChar as a single char, so changing the trigger char to a word could cause trouble for the dataProvider-function or whatelse.
Example:
<ReactTextareaAutocomplete<AutocompleteListItem>
/* ... */
trigger={{
'apple': {
dataProvider: token => fetchRecipeList(token),
component: Item,
output: item => item.char,
},
}} />
One can then type 'appleJ' and the fetchRecipeList-function would get passed 'ppleJ'. So... probably shouldn't do that.
from react-textarea-autocomplete.
Related Issues (20)
- Update react version
- Undo/Ctrl-Z function is not working as expected
- Some triggers wipe entire text HOT 2
- onScroll handler for underlying textarea does not get propagated correctly HOT 1
- Clicking on second suggestion replaces whole text HOT 6
- 👋 Beware – not actively maintained. Looking for maintainer and leader of complete rewrite. HOT 1
- TypeError: Illegal invocation HOT 1
- Update React Version HOT 2
- TypeScript Example? HOT 1
- Suggestion-list position HOT 1
- Add support for React 18 HOT 2
- defaultValue not supported
- Remove Space After the AutoCompleted Text
- When using Key Up / Down, it doesn't show what item is selected.
- The suggestion popup is not using updated state HOT 1
- Clear Value after using onItemSelected HOT 3
- Disable autocomplete on 'enter' or 'tab'
- Is there any way to keep dropdown list not disappear when selecting an item, because I want to be able to multiple select HOT 1
- Is any way to use the regex patten to trigger
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-textarea-autocomplete.