From 3f6d89f42b3347d63993695e6e8d4e8162465f3c Mon Sep 17 00:00:00 2001 From: arichter83 Date: Wed, 6 Feb 2019 00:01:02 +0100 Subject: [PATCH 1/2] Added result.customOption for allowNew items See https://github.com/ericgio/react-bootstrap-typeahead/blob/4537b2522854431f67732c9cbddd9ce5bffbc958/src/containers/typeaheadContainer.js#L142 --- types/react-bootstrap-typeahead/index.d.ts | 6 ++++-- .../react-bootstrap-typeahead-tests.tsx | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/types/react-bootstrap-typeahead/index.d.ts b/types/react-bootstrap-typeahead/index.d.ts index 2f1ad8b7be..c4cc65f66a 100644 --- a/types/react-bootstrap-typeahead/index.d.ts +++ b/types/react-bootstrap-typeahead/index.d.ts @@ -107,6 +107,8 @@ export interface TypeaheadContainerProps { text: string; } +export type TypeaheadResult = T & { customOption: boolean } + export interface TypeaheadProps { /* For localized accessibility: Should return a string indicating the number of results for screen readers. Receives the current results. */ @@ -252,10 +254,10 @@ export interface TypeaheadProps { placeholder?: string; /* Callback for custom menu rendering. */ - renderMenu?: (results: T[], menuProps: any) => React.ReactNode; + renderMenu?: (results: TypeaheadResult[], menuProps: any) => React.ReactNode; /* Provides a hook for customized rendering of menu item contents. */ - renderMenuItemChildren?: (option: T, props: TypeaheadMenuProps, index: number) => React.ReactNode; + renderMenuItemChildren?: (option: TypeaheadResult, props: TypeaheadMenuProps, index: number) => React.ReactNode; /* Provides a hook for customized rendering of tokens when multiple selections are enabled. */ renderToken?: (selectedItem: T, props: TypeaheadMenuProps, index: number) => React.ReactNode; diff --git a/types/react-bootstrap-typeahead/react-bootstrap-typeahead-tests.tsx b/types/react-bootstrap-typeahead/react-bootstrap-typeahead-tests.tsx index 7e2c3a29a6..f331752cbb 100644 --- a/types/react-bootstrap-typeahead/react-bootstrap-typeahead-tests.tsx +++ b/types/react-bootstrap-typeahead/react-bootstrap-typeahead-tests.tsx @@ -107,6 +107,21 @@ class BasicExample extends React.Component { } /> + ( + + { results.map((result, index) => ( + + { result.customOption && 'New: ' } + {result.name} + + )) } + + )} + /> Date: Wed, 6 Feb 2019 00:07:07 +0100 Subject: [PATCH 2/2] Fix linting --- types/react-bootstrap-typeahead/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/react-bootstrap-typeahead/index.d.ts b/types/react-bootstrap-typeahead/index.d.ts index c4cc65f66a..93fa2c9c6a 100644 --- a/types/react-bootstrap-typeahead/index.d.ts +++ b/types/react-bootstrap-typeahead/index.d.ts @@ -107,7 +107,7 @@ export interface TypeaheadContainerProps { text: string; } -export type TypeaheadResult = T & { customOption: boolean } +export type TypeaheadResult = T & { customOption: boolean }; export interface TypeaheadProps { /* For localized accessibility: Should return a string indicating the number of results for screen readers. @@ -254,7 +254,7 @@ export interface TypeaheadProps { placeholder?: string; /* Callback for custom menu rendering. */ - renderMenu?: (results: TypeaheadResult[], menuProps: any) => React.ReactNode; + renderMenu?: (results: Array>, menuProps: any) => React.ReactNode; /* Provides a hook for customized rendering of menu item contents. */ renderMenuItemChildren?: (option: TypeaheadResult, props: TypeaheadMenuProps, index: number) => React.ReactNode;