Skip to content

Commit 2f5c683

Browse files
sarahdayandhayab
andauthored
feat: pass insights option default to undefined (#1198)
Co-authored-by: Dhaya <[email protected]>
1 parent 5fd58f6 commit 2f5c683

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

packages/autocomplete-core/src/createAutocomplete.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ export function createAutocomplete<
6969
}
7070

7171
if (
72-
options.insights &&
72+
props.insights &&
7373
!props.plugins.some((plugin) => plugin.name === 'aa.algoliaInsightsPlugin')
7474
) {
7575
const insightsParams =
76-
typeof options.insights === 'boolean' ? {} : options.insights;
76+
typeof props.insights === 'boolean' ? {} : props.insights;
7777
props.plugins.push(createAlgoliaInsightsPlugin(insightsParams));
7878
}
7979

packages/autocomplete-core/src/getDefaultProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function getDefaultProps<TItem extends BaseItem>(
3232
autoFocus: false,
3333
defaultActiveItemId: null,
3434
stallThreshold: 300,
35-
insights: false,
35+
insights: undefined,
3636
environment,
3737
shouldPanelOpen: ({ state }) => getItemsCount(state) > 0,
3838
reshape: ({ sources }) => sources,

packages/autocomplete-core/src/types/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,28 @@ import {
99
} from '@algolia/autocomplete-plugin-algolia-insights';
1010
import {
1111
AutocompleteOptions as _AutocompleteOptions,
12+
InternalAutocompleteOptions as _InternalAutocompleteOptions,
1213
BaseItem,
1314
} from '@algolia/autocomplete-shared/dist/esm/core';
1415

1516
export type AutocompleteInsightsApi = _AutocompleteInsightsApi;
1617
export type AlgoliaInsightsHit = _AlgoliaInsightsHit;
17-
export interface AutocompleteOptions<TItem extends BaseItem>
18-
extends _AutocompleteOptions<TItem> {
18+
19+
type InsightsOption = {
1920
/**
2021
* Whether to enable the Insights plugin and load the Insights library if it has not been loaded yet.
2122
*
2223
* See [**autocomplete-plugin-algolia-insights**](https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-algolia-insights/) for more information.
2324
*
24-
* @default false
25+
* @default undefined
2526
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-insights
2627
*/
27-
insights?: CreateAlgoliaInsightsPluginParams | boolean;
28-
}
28+
insights?: CreateAlgoliaInsightsPluginParams | boolean | undefined;
29+
};
30+
31+
export interface AutocompleteOptions<TItem extends BaseItem>
32+
extends _AutocompleteOptions<TItem>,
33+
InsightsOption {}
34+
export interface InternalAutocompleteOptions<TItem extends BaseItem>
35+
extends _InternalAutocompleteOptions<TItem>,
36+
InsightsOption {}

0 commit comments

Comments
 (0)