diff --git a/examples/twitter-compose-with-typeahead/src/App.tsx b/examples/twitter-compose-with-typeahead/src/App.tsx index 43d8fa678..6706ff1c2 100644 --- a/examples/twitter-compose-with-typeahead/src/App.tsx +++ b/examples/twitter-compose-with-typeahead/src/App.tsx @@ -7,7 +7,7 @@ import './App.css'; export function App() { return (
- +
); } diff --git a/examples/twitter-compose-with-typeahead/src/Autocomplete.tsx b/examples/twitter-compose-with-typeahead/src/Autocomplete.tsx index 2be7362fa..1e2435693 100644 --- a/examples/twitter-compose-with-typeahead/src/Autocomplete.tsx +++ b/examples/twitter-compose-with-typeahead/src/Autocomplete.tsx @@ -24,6 +24,7 @@ export function Autocomplete( const { autocomplete, state } = useAutocomplete({ ...props, id: 'twitter-autocomplete', + defaultActiveItemId: 0, getSources({ query }) { const cursorPosition = inputRef.current?.selectionEnd || 0; const activeToken = getActiveToken(query, cursorPosition); diff --git a/examples/twitter-compose-with-typeahead/src/utils/getActiveToken.ts b/examples/twitter-compose-with-typeahead/src/utils/getActiveToken.ts index d1caac7ba..d55dfe3ad 100644 --- a/examples/twitter-compose-with-typeahead/src/utils/getActiveToken.ts +++ b/examples/twitter-compose-with-typeahead/src/utils/getActiveToken.ts @@ -1,5 +1,5 @@ -export function getActiveToken(query: string, cursorPosition: number) { - const tokenizedQuery = query.split(/[\s\n]/).reduce((acc, word, index) => { +export function getActiveToken(input: string, cursorPosition: number) { + const tokenizedQuery = input.split(/[\s\n]/).reduce((acc, word, index) => { const previous = acc[index - 1]; const start = index === 0 ? index : previous.range[1] + 1; const end = start + word.length; diff --git a/examples/twitter-compose-with-typeahead/src/utils/isValidTwitterUsername.ts b/examples/twitter-compose-with-typeahead/src/utils/isValidTwitterUsername.ts index 396957aad..00167aed1 100644 --- a/examples/twitter-compose-with-typeahead/src/utils/isValidTwitterUsername.ts +++ b/examples/twitter-compose-with-typeahead/src/utils/isValidTwitterUsername.ts @@ -1,8 +1,3 @@ export function isValidTwitterUsername(username: string) { - return ( - username.startsWith('@') && - username.length > 1 && - username.length <= 15 && - /^@\w+$/.test(username) - ); + return /^@\w{1,15}$/.test(username); }