Skip to content

Commit 7a7b612

Browse files
feat(core): introduce debug mode (#315)
1 parent d045e70 commit 7a7b612

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

examples/js/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const searchClient = algoliasearch(
1212

1313
autocomplete({
1414
container: '#autocomplete',
15+
debug: true,
1516
getSources() {
1617
return [
1718
{

packages/autocomplete-core/src/getDefaultProps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function getDefaultProps<TItem>(
1414
: {}) as typeof window;
1515

1616
return {
17+
debug: false,
1718
openOnFocus: false,
1819
placeholder: '',
1920
autoFocus: false,

packages/autocomplete-core/src/stateReducer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ export const stateReducer: Reducer = (action, state, props) => {
125125
}
126126

127127
case 'blur': {
128+
if (props.debug) {
129+
return state;
130+
}
131+
128132
return {
129133
...state,
130134
isOpen: false,

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ export interface AutocompleteApi<
77
TEvent = Event,
88
TMouseEvent = MouseEvent,
99
TKeyboardEvent = KeyboardEvent
10-
>
11-
extends AutocompleteSetters<TItem>,
10+
> extends AutocompleteSetters<TItem>,
1211
AutocompleteAccessibilityGetters<
1312
TItem,
1413
TEvent,
@@ -155,6 +154,15 @@ interface Navigator<TItem> {
155154
}
156155

157156
export interface PublicAutocompleteOptions<TItem> {
157+
/**
158+
* Whether to consider the experience in debug mode.
159+
*
160+
* The debug mode is useful when developing because it doesn't close
161+
* the dropdown when the blur event occurs.
162+
*
163+
* @default false
164+
*/
165+
debug?: boolean;
158166
/**
159167
* The Autocomplete ID to create accessible attributes.
160168
*
@@ -243,6 +251,7 @@ export interface PublicAutocompleteOptions<TItem> {
243251

244252
// Props manipulated internally with default values.
245253
export interface AutocompleteOptions<TItem> {
254+
debug: boolean;
246255
id: string;
247256
onStateChange<TItem>(props: { state: AutocompleteState<TItem> }): void;
248257
placeholder: string;

packages/website/docs/partials/createAutocomplete-props.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,9 @@ The function called when the autocomplete form is submitted.
9797
The function called when the input changes.
9898

9999
This turns the experience in controlled mode, leaving you in charge of updating the state.
100+
101+
## `debug`
102+
103+
> `boolean` | defaults to `false`
104+
105+
Whether to consider the experience in debug mode. It is useful when developing because it doesn't close the dropdown when the blur event occurs.

0 commit comments

Comments
 (0)