Skip to content
This repository was archived by the owner on Jan 16, 2022. It is now read-only.

Commit cfb29ce

Browse files
tmknjuanpicado
authored andcommitted
fix: added typings for react-autosuggest (#200)
1 parent 245247c commit cfb29ce

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,8 @@
213213
"type": "opencollective",
214214
"url": "https://opencollective.com/verdaccio",
215215
"logo": "https://opencollective.com/verdaccio/logo.txt"
216+
},
217+
"dependencies": {
218+
"@types/react-autosuggest": "9.3.11"
216219
}
217220
}

src/components/AutoComplete/AutoComplete.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { KeyboardEvent } from 'react';
22
import { css } from 'emotion';
3-
import Autosuggest from 'react-autosuggest';
3+
import Autosuggest, { SuggestionSelectedEventData, InputProps, ChangeEvent } from 'react-autosuggest';
44
import match from 'autosuggest-highlight/match';
55
import parse from 'autosuggest-highlight/parse';
66
import MenuItem from '@material-ui/core/MenuItem';
@@ -20,12 +20,12 @@ interface Props {
2020
placeholder?: string;
2121
startAdornment?: JSX.Element;
2222
disableUnderline?: boolean;
23-
onChange?: (event: KeyboardEvent<HTMLInputElement>, { newValue, method }: { newValue: string; method: string }) => void;
24-
onSuggestionsFetch?: ({ value: string }) => Promise<void>;
23+
onChange: (event: React.FormEvent<HTMLInputElement>, params: ChangeEvent) => void;
24+
onSuggestionsFetch: ({ value: string }) => Promise<void>;
2525
onCleanSuggestions?: () => void;
26-
onClick?: (event: KeyboardEvent<HTMLInputElement>, { suggestionValue, method }: { suggestionValue: string[]; method: string }) => void;
26+
onClick?: (event: React.FormEvent<HTMLInputElement>, data: SuggestionSelectedEventData<unknown>) => void;
2727
onKeyDown?: (event: KeyboardEvent<HTMLInputElement>) => void;
28-
onBlur?: (event: KeyboardEvent<HTMLInputElement>) => void;
28+
onBlur?: (event: React.FormEvent<HTMLInputElement>) => void;
2929
}
3030

3131
/* eslint-disable react/jsx-sort-props */
@@ -113,7 +113,7 @@ const AutoComplete = ({
113113
onSuggestionsFetchRequested: onSuggestionsFetch,
114114
onSuggestionsClearRequested: onCleanSuggestions,
115115
};
116-
const inputProps = {
116+
const inputProps: InputProps<unknown> = {
117117
value,
118118
onChange,
119119
placeholder,

src/components/Search/Search.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { KeyboardEvent, Component, ReactElement } from 'react';
22
import { withRouter, RouteComponentProps } from 'react-router-dom';
3+
import { SuggestionSelectedEventData, ChangeEvent } from 'react-autosuggest';
34
import { css } from 'emotion';
45
import { default as IconSearch } from '@material-ui/icons/Search';
56
import InputAdornment from '@material-ui/core/InputAdornment';
@@ -19,10 +20,10 @@ export interface State {
1920

2021
export type cancelAllSearchRequests = () => void;
2122
export type handlePackagesClearRequested = () => void;
22-
export type handleSearch = (event: KeyboardEvent<HTMLInputElement>, { newValue, method }: { newValue: string; method: string }) => void;
23+
export type handleSearch = (event: React.FormEvent<HTMLInputElement>, { newValue, method }: ChangeEvent) => void;
2324
export type handleClickSearch = (event: KeyboardEvent<HTMLInputElement>, { suggestionValue, method }: { suggestionValue: object[]; method: string }) => void;
2425
export type handleFetchPackages = ({ value: string }) => Promise<void>;
25-
export type onBlur = (event: KeyboardEvent<HTMLInputElement>) => void;
26+
export type onBlur = (event: React.FormEvent<HTMLInputElement>) => void;
2627

2728
const CONSTANTS = {
2829
API_DELAY: 300,
@@ -117,8 +118,8 @@ export class Search extends Component<RouteComponentProps<{}>, State> {
117118
* When an user select any package by clicking or pressing return key.
118119
*/
119120
private handleClickSearch = (
120-
event: React.KeyboardEvent<HTMLInputElement>,
121-
{ suggestionValue, method }: { suggestionValue: string[]; method: string }
121+
event: React.FormEvent<HTMLInputElement>,
122+
{ suggestionValue, method }: SuggestionSelectedEventData<unknown>
122123
): void | undefined => {
123124
const { history } = this.props;
124125
// stops event bubbling

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,13 @@
16991699
resolved "https://registry.verdaccio.org/@types%2fq/-/q-1.5.2.tgz#690a1475b84f2a884fd07cd797c00f5f31356ea8"
17001700
integrity sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw==
17011701

1702+
"@types/react-autosuggest@9.3.11":
1703+
version "9.3.11"
1704+
resolved "https://registry.yarnpkg.com/@types/react-autosuggest/-/react-autosuggest-9.3.11.tgz#2b554a4ac350da5bcd50ad368972f2e80e879232"
1705+
integrity sha512-OY0N0BZ2MiD4W3oTquRvpqYucExiLNgXgu4JkXZ2gKs4lONiS7B+fSotiQnjLdGIy+4sW3tzTvfbQfPgTZGInA==
1706+
dependencies:
1707+
"@types/react" "*"
1708+
17021709
"@types/react-dom@*":
17031710
version "16.9.1"
17041711
resolved "https://registry.verdaccio.org/@types%2freact-dom/-/react-dom-16.9.1.tgz#79206237cba9532a9f870b1cd5428bef6b66378c"

0 commit comments

Comments
 (0)