Skip to content

Commit d1ae962

Browse files
Hossam HindawyHossam Hindawy
authored andcommitted
Add new types for CioAutocompleteProps with and without Shopify defaults
1 parent 8eab2f4 commit d1ae962

File tree

1 file changed

+39
-24
lines changed

1 file changed

+39
-24
lines changed

src/types.ts

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export type ShopifySettings = {
5858
searchUrl: string;
5959
};
6060

61-
export type CioAutocompleteProps = CioClientConfig &
61+
export type CioAutocompletePropsBase = CioClientConfig &
6262
OptionalItemsComboboxProps<Item> & {
6363
/**
6464
* Set to `false` to show suggestions only after a user clears their query,
@@ -70,12 +70,6 @@ export type CioAutocompleteProps = CioClientConfig &
7070
* i.e. <a href=getSearchResultsUrl([selected_search_suggestion])>[Search Suggestion]</a>
7171
*/
7272
getSearchResultsUrl?: (item: SearchSuggestion) => string;
73-
/**
74-
* Callback function that runs when the user submits a search.
75-
* Usually used to trigger a redirect.
76-
* If provided, it will override Shopify defaults even when useShopifyDefaults is true.
77-
*/
78-
onSubmit?: OnSubmit;
7973
/**
8074
* Callback function that runs when the user focuses on the input
8175
*/
@@ -114,25 +108,46 @@ export type CioAutocompleteProps = CioClientConfig &
114108
* Search input default value
115109
*/
116110
defaultInput?: string;
117-
/**
118-
* Set to `true` to apply Shopify-specific defaults for `onSubmit` behavior.
119-
*
120-
* When enabled, the autocomplete will automatically handle navigation:
121-
* - **Product selections**: Redirects to the product URL (preserving query parameters)
122-
* - **Search Suggestions**: Redirects to the search results page with the selected query
123-
* - **Manual search**: Redirects to the search results page with the entered query
124-
*
125-
* **Note**: If you provide a custom `onSubmit` handler, it will override the Shopify defaults.
126-
*/
127-
useShopifyDefaults?: boolean;
128-
/**
129-
* Configuration settings for Shopify integration. Used when `useShopifyDefaults` is enabled.
130-
*
131-
* Allows you to customize the search URL and other Shopify-specific behaviors.
132-
*/
133-
shopifySettings?: ShopifySettings;
134111
};
135112

113+
export type CioAutocompletePropsWithShopifyDefaults = {
114+
/**
115+
* Callback function that runs when the user submits a search.
116+
* Usually used to trigger a redirect.
117+
* If provided, it will override Shopify defaults even when useShopifyDefaults is true.
118+
*/
119+
onSubmit?: OnSubmit;
120+
/**
121+
* Set to `true` to apply Shopify-specific defaults for `onSubmit` behavior.
122+
*
123+
* When enabled, the autocomplete will automatically handle navigation:
124+
* - **Product selections**: Redirects to the product URL (preserving query parameters)
125+
* - **Search Suggestions**: Redirects to the search results page with the selected query
126+
* - **Manual search**: Redirects to the search results page with the entered query
127+
*
128+
* **Note**: If you provide a custom `onSubmit` handler, it will override the Shopify defaults.
129+
*/
130+
useShopifyDefaults: true;
131+
/**
132+
* Configuration settings for Shopify integration. Used when `useShopifyDefaults` is enabled.
133+
*
134+
* Allows you to customize the search URL and other Shopify-specific behaviors.
135+
*/
136+
shopifySettings?: ShopifySettings;
137+
};
138+
139+
export type CioAutocompletePropsWithoutShopifyDefaults = {
140+
/**
141+
* Callback function that runs when the user submits a search.
142+
* Usually used to trigger a redirect.
143+
*/
144+
onSubmit: OnSubmit;
145+
useShopifyDefaults?: false;
146+
};
147+
148+
export type CioAutocompleteProps = CioAutocompletePropsBase &
149+
(CioAutocompletePropsWithShopifyDefaults | CioAutocompletePropsWithoutShopifyDefaults);
150+
136151
/**
137152
* AutocompleteSubmitEvent type is AutocompleteSelectSubmit or AutocompleteSearchSubmit.
138153
* Use isAutocompleteSearchSubmit or isAutocompleteSelectSubmit type predicates to safely access event properties.

0 commit comments

Comments
 (0)