From 7bf1a7fb2cae3df889e4f1228aa379d771f49021 Mon Sep 17 00:00:00 2001 From: Philip Ottesen Date: Wed, 16 Nov 2016 10:18:59 -0500 Subject: [PATCH 1/2] Adding optional theme parameters, optional onBlur with focusedSuggestion, setting strictNullChecks = true --- react-autosuggest/react-autosuggest-tests.tsx | 13 +++++-- react-autosuggest/react-autosuggest.d.ts | 35 ++++++++++++------- react-autosuggest/tsconfig.json | 2 +- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/react-autosuggest/react-autosuggest-tests.tsx b/react-autosuggest/react-autosuggest-tests.tsx index 5a107fe525..d3d4278829 100644 --- a/react-autosuggest/react-autosuggest-tests.tsx +++ b/react-autosuggest/react-autosuggest-tests.tsx @@ -55,12 +55,21 @@ export class ReactAutosuggestBasicTest extends React.Component { onChange: this.onChange.bind(this) }; + const theme = { + input: 'themed-input-class', + container: 'themed-container-class', + suggestionFocused: 'active' + } + return ; + alwaysRenderSuggestions={true} + inputProps={inputProps} + theme={theme} + />; } protected onSuggestionsSelected(event: React.FormEvent, data: ReactAutosuggest.ExplicitSuggestionSelectedEventData): void { @@ -306,7 +315,7 @@ export class ReactAutosuggestCustomTest extends React.Component { { parts.map((part, index) => { - const className = part.highlight ? 'highlight' : null; + const className = part.highlight ? 'highlight' : undefined; return {part.text}; }) diff --git a/react-autosuggest/react-autosuggest.d.ts b/react-autosuggest/react-autosuggest.d.ts index cfec62d047..1a144ea44f 100644 --- a/react-autosuggest/react-autosuggest.d.ts +++ b/react-autosuggest/react-autosuggest.d.ts @@ -16,14 +16,24 @@ declare namespace ReactAutosuggest { valueBeforeUpDown?: string; } + interface ChangeEvent { + newValue: string; + method: 'down' | 'up' | 'escape' | 'enter' | 'click' | 'type'; + } + + interface BlurEvent { + focusedSuggestion: any; + } + interface InputProps extends React.HTMLAttributes { value: string; - onChange: (event: React.FormEvent, params?: {newValue: string, method: string}) => void; + onChange: (event: React.FormEvent, params?: ChangeEvent) => void; + onBlur?: (event: React.FormEvent, params?: BlurEvent) => void; } interface ExplicitSuggestionSelectedEventData { - method: string; - sectionIndex: number; + method: 'click' | 'enter'; + sectionIndex: number | null; suggestion: TSuggestion; suggestionValue: string; } @@ -32,15 +42,15 @@ declare namespace ReactAutosuggest { } interface Theme { - container: string; - containerOpen: string; - input: string; - sectionContainer: string; - sectionSuggestionsContainer: string; - sectionTitle: string; - suggestion: string; - suggestionFocused: string; - suggestionsContainer: string; + container?: string; + containerOpen?: string; + input?: string; + sectionContainer?: string; + sectionSuggestionsContainer?: string; + sectionTitle?: string; + suggestion?: string; + suggestionFocused?: string; + suggestionsContainer?: string; } interface AutosuggestProps extends React.Props { @@ -49,6 +59,7 @@ declare namespace ReactAutosuggest { getSuggestionValue: (suggestion: any) => string; renderSuggestion: (suggestion: any, inputValues: InputValues) => JSX.Element; inputProps: InputProps; + alwaysRenderSuggestions?: boolean; shouldRenderSuggestions?: (value: string) => boolean; multiSection?: boolean; renderSectionTitle?: (section: any, inputValues: InputValues) => JSX.Element; diff --git a/react-autosuggest/tsconfig.json b/react-autosuggest/tsconfig.json index 3f2805e714..c7b874872f 100644 --- a/react-autosuggest/tsconfig.json +++ b/react-autosuggest/tsconfig.json @@ -3,7 +3,7 @@ "module": "commonjs", "target": "es6", "noImplicitAny": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" From e8171dca7f90197c55a3a66c5952929ff0a67135 Mon Sep 17 00:00:00 2001 From: Philip Ottesen Date: Wed, 16 Nov 2016 10:37:09 -0500 Subject: [PATCH 2/2] Updating authors --- react-autosuggest/react-autosuggest.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-autosuggest/react-autosuggest.d.ts b/react-autosuggest/react-autosuggest.d.ts index 1a144ea44f..739509bdef 100644 --- a/react-autosuggest/react-autosuggest.d.ts +++ b/react-autosuggest/react-autosuggest.d.ts @@ -1,6 +1,6 @@ // Type definitions for react-autosuggest v3.7.3 // Project: http://react-autosuggest.js.org/ -// Definitions by: Nicolas Schmitt +// Definitions by: Nicolas Schmitt , Philip Ottesen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped ///