Skip to content

Commit b7e86d5

Browse files
feat: rename getters (#362)
1 parent a33c793 commit b7e86d5

File tree

17 files changed

+93
-93
lines changed

17 files changed

+93
-93
lines changed

packages/autocomplete-core/src/createAutocomplete.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export function createAutocomplete<
3131
getFormProps,
3232
getLabelProps,
3333
getInputProps,
34-
getDropdownProps,
35-
getMenuProps,
34+
getPanelProps,
35+
getListProps,
3636
getItemProps,
3737
} = getPropGetters<TItem, TEvent, TMouseEvent, TKeyboardEvent>({
3838
store,
@@ -77,8 +77,8 @@ export function createAutocomplete<
7777
getFormProps,
7878
getInputProps,
7979
getLabelProps,
80-
getDropdownProps,
81-
getMenuProps,
80+
getPanelProps,
81+
getListProps,
8282
getItemProps,
8383
refresh,
8484
};

packages/autocomplete-core/src/getDefaultProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function getDefaultProps<TItem>(
2525
defaultSelectedItemId: null,
2626
stallThreshold: 300,
2727
environment,
28-
shouldDropdownShow: ({ state }) => getItemsCount(state) > 0,
28+
shouldPanelShow: ({ state }) => getItemsCount(state) > 0,
2929
...props,
3030
// Since `generateAutocompleteId` triggers a side effect (it increments
3131
// and internal counter), we don't want to execute it if unnecessary.

packages/autocomplete-core/src/getPropGetters.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import {
55
AutocompleteSetters,
66
AutocompleteStore,
77
AutocompleteRefresh,
8-
GetDropdownProps,
8+
GetPanelProps,
99
GetEnvironmentProps,
1010
GetFormProps,
1111
GetInputProps,
1212
GetItemProps,
1313
GetLabelProps,
14-
GetMenuProps,
14+
GetListProps,
1515
GetRootProps,
1616
} from './types';
1717
import { getSelectedItem, isOrContainsNode } from './utils';
@@ -36,7 +36,7 @@ export function getPropGetters<TItem, TEvent, TMouseEvent, TKeyboardEvent>({
3636
const getEnvironmentProps: GetEnvironmentProps = (getterProps) => {
3737
return {
3838
// On touch devices, we do not rely on the native `blur` event of the
39-
// input to close the dropdown, but rather on a custom `touchstart` event
39+
// input to close the panel, but rather on a custom `touchstart` event
4040
// outside of the autocomplete elements.
4141
// This ensures a working experience on mobile because we blur the input
4242
// on touch devices when the user starts scrolling (`touchmove`).
@@ -50,7 +50,7 @@ export function getPropGetters<TItem, TEvent, TMouseEvent, TKeyboardEvent>({
5050

5151
const isTargetWithinAutocomplete = [
5252
getterProps.searchBoxElement,
53-
getterProps.dropdownElement,
53+
getterProps.panelElement,
5454
].some((contextNode) => {
5555
return (
5656
contextNode &&
@@ -69,7 +69,7 @@ export function getPropGetters<TItem, TEvent, TMouseEvent, TKeyboardEvent>({
6969
// When scrolling on touch devices (mobiles, tablets, etc.), we want to
7070
// mimic the native platform behavior where the input is blurred to
7171
// hide the virtual keyboard. This gives more vertical space to
72-
// discover all the suggestions showing up in the dropdown.
72+
// discover all the suggestions showing up in the panel.
7373
onTouchMove(event: TouchEvent) {
7474
if (
7575
store.getState().isOpen === false ||
@@ -90,7 +90,7 @@ export function getPropGetters<TItem, TEvent, TMouseEvent, TKeyboardEvent>({
9090
role: 'combobox',
9191
'aria-expanded': store.getState().isOpen,
9292
'aria-haspopup': 'listbox',
93-
'aria-owns': store.getState().isOpen ? `${props.id}-menu` : undefined,
93+
'aria-owns': store.getState().isOpen ? `${props.id}-list` : undefined,
9494
'aria-labelledby': `${props.id}-label`,
9595
...rest,
9696
};
@@ -156,7 +156,7 @@ export function getPropGetters<TItem, TEvent, TMouseEvent, TKeyboardEvent>({
156156
) => {
157157
function onFocus(event: TEvent) {
158158
// We want to trigger a query when `openOnFocus` is true
159-
// because the dropdown should open with the current query.
159+
// because the panel should open with the current query.
160160
if (props.openOnFocus || store.getState().query.length > 0) {
161161
onInput({
162162
query: store.getState().completion || store.getState().query,
@@ -185,7 +185,7 @@ export function getPropGetters<TItem, TEvent, TMouseEvent, TKeyboardEvent>({
185185
store.getState().isOpen && store.getState().selectedItemId !== null
186186
? `${props.id}-item-${store.getState().selectedItemId}`
187187
: undefined,
188-
'aria-controls': store.getState().isOpen ? `${props.id}-menu` : undefined,
188+
'aria-controls': store.getState().isOpen ? `${props.id}-list` : undefined,
189189
'aria-labelledby': `${props.id}-label`,
190190
value: store.getState().completion || store.getState().query,
191191
id: `${props.id}-input`,
@@ -236,13 +236,13 @@ export function getPropGetters<TItem, TEvent, TMouseEvent, TKeyboardEvent>({
236236
}
237237
},
238238
onClick: (event) => {
239-
// When the dropdown is closed and you click on the input while
239+
// When the panel is closed and you click on the input while
240240
// the input is focused, the `onFocus` event is not triggered
241241
// (default browser behavior).
242-
// In an autocomplete context, it makes sense to open the menu in this
242+
// In an autocomplete context, it makes sense to open the panel in this
243243
// case.
244244
// We mimic this event by catching the `onClick` event which
245-
// triggers the `onFocus` for the dropdown to open.
245+
// triggers the `onFocus` for the panel to open.
246246
if (
247247
providedProps.inputElement ===
248248
props.environment.document.activeElement &&
@@ -263,21 +263,21 @@ export function getPropGetters<TItem, TEvent, TMouseEvent, TKeyboardEvent>({
263263
};
264264
};
265265

266-
const getMenuProps: GetMenuProps = (rest) => {
266+
const getListProps: GetListProps = (rest) => {
267267
return {
268268
role: 'listbox',
269269
'aria-labelledby': `${props.id}-label`,
270-
id: `${props.id}-menu`,
270+
id: `${props.id}-list`,
271271
...rest,
272272
};
273273
};
274274

275-
const getDropdownProps: GetDropdownProps<TMouseEvent> = (rest) => {
275+
const getPanelProps: GetPanelProps<TMouseEvent> = (rest) => {
276276
return {
277277
onMouseDown(event) {
278-
// Prevents the `activeElement` from being changed to the dropdown so
278+
// Prevents the `activeElement` from being changed to the panel so
279279
// that the blur event is not triggered, otherwise it closes the
280-
// dropdown.
280+
// panel.
281281
((event as unknown) as MouseEvent).preventDefault();
282282
},
283283
onMouseLeave() {
@@ -391,8 +391,8 @@ export function getPropGetters<TItem, TEvent, TMouseEvent, TKeyboardEvent>({
391391
getFormProps,
392392
getLabelProps,
393393
getInputProps,
394-
getDropdownProps,
395-
getMenuProps,
394+
getPanelProps,
395+
getListProps,
396396
getItemProps,
397397
};
398398
}

packages/autocomplete-core/src/onInput.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface OnInputParams<TItem> extends AutocompleteSetters<TItem> {
1919
*
2020
* This is useful when we call `onInput` in a different scenario than an
2121
* actual input. For example, we use `onInput` when we click on an item,
22-
* but we want to close the dropdown in that case.
22+
* but we want to close the panel in that case.
2323
*/
2424
nextState?: Partial<AutocompleteState<TItem>>;
2525
refresh: AutocompleteRefresh;
@@ -71,7 +71,7 @@ export function onInput<TItem>({
7171
}))
7272
);
7373
setIsOpen(
74-
nextState.isOpen ?? props.shouldDropdownShow({ state: store.getState() })
74+
nextState.isOpen ?? props.shouldPanelShow({ state: store.getState() })
7575
);
7676

7777
return Promise.resolve();
@@ -127,7 +127,7 @@ export function onInput<TItem>({
127127
setIsOpen(
128128
nextState.isOpen ??
129129
((query.length === 0 && props.openOnFocus) ||
130-
props.shouldDropdownShow({ state: store.getState() }))
130+
props.shouldPanelShow({ state: store.getState() }))
131131
);
132132

133133
const highlightedItem = getSelectedItem({

packages/autocomplete-core/src/onKeyDown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function onKeyDown<TItem>({
7070
} else if (event.key === 'Escape') {
7171
// This prevents the default browser behavior on `input[type="search"]`
7272
// to remove the query right away because we first want to close the
73-
// dropdown.
73+
// panel.
7474
event.preventDefault();
7575

7676
store.send(event.key, null);

packages/autocomplete-core/src/stateReducer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ export const stateReducer: Reducer = (state, action) => {
114114
return {
115115
...state,
116116
selectedItemId:
117-
// Since we open the menu on reset when openOnFocus=true
117+
// Since we open the panel on reset when openOnFocus=true
118118
// we need to restore the highlighted index to the defaultSelectedItemId. (DocSearch use-case)
119119

120-
// Since we close the menu when openOnFocus=false
120+
// Since we close the panel when openOnFocus=false
121121
// we lose track of the highlighted index. (Query-suggestions use-case)
122122
action.props.openOnFocus === true
123123
? action.props.defaultSelectedItemId
124124
: null,
125-
isOpen: action.props.openOnFocus, // @TODO: Check with UX team if we want to close the menu on reset.
125+
isOpen: action.props.openOnFocus, // @TODO: Check with UX team if we want to close the panel on reset.
126126
status: 'idle',
127127
query: '',
128128
};

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export interface AutocompleteOptions<TItem> {
163163
* Whether to consider the experience in debug mode.
164164
*
165165
* The debug mode is useful when developing because it doesn't close
166-
* the dropdown when the blur event occurs.
166+
* the panel when the blur event occurs.
167167
*
168168
* @default false
169169
*/
@@ -198,7 +198,7 @@ export interface AutocompleteOptions<TItem> {
198198
*/
199199
defaultSelectedItemId?: number | null;
200200
/**
201-
* Whether to open the dropdown on focus when there's no query.
201+
* Whether to open the panel on focus when there's no query.
202202
*
203203
* @default false
204204
*/
@@ -233,9 +233,9 @@ export interface AutocompleteOptions<TItem> {
233233
*/
234234
navigator?: Partial<Navigator<TItem>>;
235235
/**
236-
* The function called to determine whether the dropdown should open.
236+
* The function called to determine whether the panel should open.
237237
*/
238-
shouldDropdownShow?(params: { state: AutocompleteState<TItem> }): boolean;
238+
shouldPanelShow?(params: { state: AutocompleteState<TItem> }): boolean;
239239
/**
240240
* The function called when the autocomplete form is submitted.
241241
*/
@@ -272,7 +272,7 @@ export interface InternalAutocompleteOptions<TItem>
272272
environment: Environment;
273273
navigator: Navigator<TItem>;
274274
plugins: Array<AutocompletePlugin<TItem, unknown>>;
275-
shouldDropdownShow(params: { state: AutocompleteState<TItem> }): boolean;
275+
shouldPanelShow(params: { state: AutocompleteState<TItem> }): boolean;
276276
onSubmit(params: OnSubmitParams<TItem>): void;
277277
onInput?(params: OnInputParams<TItem>): void | Promise<any>;
278278
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ export interface AutocompleteAccessibilityGetters<
1111
getFormProps: GetFormProps<TEvent>;
1212
getLabelProps: GetLabelProps;
1313
getInputProps: GetInputProps<TEvent, TMouseEvent, TKeyboardEvent>;
14-
getDropdownProps: GetDropdownProps<TMouseEvent>;
15-
getMenuProps: GetMenuProps;
14+
getPanelProps: GetPanelProps<TMouseEvent>;
15+
getListProps: GetListProps;
1616
getItemProps: GetItemProps<TItem, TMouseEvent>;
1717
}
1818

1919
export type GetEnvironmentProps = (props: {
2020
[key: string]: unknown;
2121
searchBoxElement: HTMLElement;
22-
dropdownElement: HTMLElement;
22+
panelElement: HTMLElement;
2323
inputElement: HTMLInputElement;
2424
}) => {
2525
onTouchStart(event: TouchEvent): void;
@@ -89,14 +89,14 @@ export type GetInputProps<TEvent, TMouseEvent, TKeyboardEvent> = (props: {
8989
onClick(event: TMouseEvent): void;
9090
};
9191

92-
export type GetDropdownProps<TMouseEvent> = (props?: {
92+
export type GetPanelProps<TMouseEvent> = (props?: {
9393
[key: string]: unknown;
9494
}) => {
9595
onMouseDown(event: TMouseEvent): void;
9696
onMouseLeave(): void;
9797
};
9898

99-
export type GetMenuProps = (props?: {
99+
export type GetListProps = (props?: {
100100
[key: string]: unknown;
101101
}) => {
102102
role: string;

packages/autocomplete-js/src/autocomplete.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55

66
import { concatClassNames } from './concatClassNames';
77
import { debounce } from './debounce';
8-
import { getDropdownPositionStyle } from './getDropdownPositionStyle';
98
import { getHTMLElement } from './getHTMLElement';
9+
import { getPanelPositionStyle } from './getPanelPositionStyle';
1010
import { resetIcon, searchIcon } from './icons';
1111
import { renderTemplate } from './renderTemplate';
1212
import { setProperties, setPropertiesWithoutEvents } from './setProperties';
@@ -24,8 +24,8 @@ function defaultRender({ root, sections }) {
2424

2525
export function autocomplete<TItem>({
2626
container,
27-
render: renderDropdown = defaultRender,
28-
dropdownPlacement = 'input-wrapper-width',
27+
render: renderPanel = defaultRender,
28+
panelPlacement = 'input-wrapper-width',
2929
classNames = {},
3030
...props
3131
}: AutocompleteOptions<TItem>): AutocompleteApi<TItem> {
@@ -52,14 +52,14 @@ export function autocomplete<TItem>({
5252

5353
const onResize = debounce(() => {
5454
if (!panel.hasAttribute('hidden')) {
55-
setDropdownPosition();
55+
setPanelPosition();
5656
}
5757
}, 100);
5858

59-
function setDropdownPosition() {
59+
function setPanelPosition() {
6060
setProperties(panel, {
61-
style: getDropdownPositionStyle({
62-
dropdownPlacement,
61+
style: getPanelPositionStyle({
62+
panelPlacement,
6363
container: root,
6464
inputWrapper,
6565
environment: props.environment,
@@ -70,7 +70,7 @@ export function autocomplete<TItem>({
7070
setProperties(window as any, {
7171
...autocomplete.getEnvironmentProps({
7272
searchBoxElement: form,
73-
dropdownElement: panel,
73+
panelElement: panel,
7474
inputElement: input,
7575
}),
7676
onResize,
@@ -103,7 +103,7 @@ export function autocomplete<TItem>({
103103
innerHTML: resetIcon,
104104
});
105105
setProperties(panel, {
106-
...autocomplete.getDropdownProps(),
106+
...autocomplete.getPanelProps(),
107107
hidden: true,
108108
class: concatClassNames(['aa-Panel', classNames.panel]),
109109
});
@@ -156,13 +156,13 @@ export function autocomplete<TItem>({
156156
}
157157

158158
if (items.length > 0) {
159-
const menu = document.createElement('ul');
160-
setProperties(menu, {
161-
...autocomplete.getMenuProps(),
159+
const list = document.createElement('ul');
160+
setProperties(list, {
161+
...autocomplete.getListProps(),
162162
class: concatClassNames(['aa-List', classNames.list]),
163163
});
164164

165-
const menuItems = items.map((item) => {
165+
const listItems = items.map((item) => {
166166
const li = document.createElement('li');
167167
setProperties(li, {
168168
...autocomplete.getItemProps({ item, source }),
@@ -173,11 +173,11 @@ export function autocomplete<TItem>({
173173
return li;
174174
});
175175

176-
for (const menuItem of menuItems) {
177-
menu.appendChild(menuItem);
176+
for (const listItem of listItems) {
177+
list.appendChild(listItem);
178178
}
179179

180-
section.appendChild(menu);
180+
section.appendChild(list);
181181
}
182182

183183
if (source.templates.footer) {
@@ -195,7 +195,7 @@ export function autocomplete<TItem>({
195195
return section;
196196
});
197197

198-
renderDropdown({ root: panel, sections, state });
198+
renderPanel({ root: panel, sections, state });
199199
}
200200

201201
inputWrapper.appendChild(input);
@@ -206,7 +206,7 @@ export function autocomplete<TItem>({
206206
root.appendChild(panel);
207207
containerElement.appendChild(root);
208208

209-
setDropdownPosition();
209+
setPanelPosition();
210210

211211
function destroy() {
212212
containerElement.innerHTML = '';

0 commit comments

Comments
 (0)