Skip to content

Commit

Permalink
feat(core): rename searchBoxElement to formElement (#374)
Browse files Browse the repository at this point in the history
BREAKING CHANGE
  • Loading branch information
francoischalifour authored Nov 23, 2020
1 parent 98dfe4b commit 79c4985
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/autocomplete-core/src/getPropGetters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function getPropGetters<TItem, TEvent, TMouseEvent, TKeyboardEvent>({
}

const isTargetWithinAutocomplete = [
getterProps.searchBoxElement,
getterProps.formElement,
getterProps.panelElement,
].some((contextNode) => {
return (
Expand Down
4 changes: 2 additions & 2 deletions packages/autocomplete-core/src/types/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export interface AutocompleteAccessibilityGetters<

export type GetEnvironmentProps = (props: {
[key: string]: unknown;
searchBoxElement: HTMLElement;
panelElement: HTMLElement;
formElement: HTMLElement;
inputElement: HTMLInputElement;
panelElement: HTMLElement;
}) => {
onTouchStart(event: TouchEvent): void;
onTouchMove(event: TouchEvent): void;
Expand Down
2 changes: 1 addition & 1 deletion packages/autocomplete-js/src/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function autocomplete<TItem>({

runEffect(() => {
const environmentProps = autocomplete.getEnvironmentProps({
searchBoxElement: form,
formElement: form,
panelElement: panel,
inputElement: input,
});
Expand Down
10 changes: 5 additions & 5 deletions packages/website/docs/creating-a-renderer.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,18 @@ function Autocomplete() {
// ...

const inputRef = React.useRef(null);
const searchBoxRef = React.useRef(null);
const formRef = React.useRef(null);
const panelRef = React.useRef(null);

const { getEnvironmentProps } = autocomplete;

React.useEffect(() => {
if (!(searchBoxRef.current && panelRef.current && inputRef.current)) {
if (!(formRef.current && panelRef.current && inputRef.current)) {
return;
}

const { onTouchStart, onTouchMove } = getEnvironmentProps({
searchBoxElement: searchBoxRef.current,
formElement: formRef.current,
panelElement: panelRef.current,
inputElement: inputRef.current,
});
Expand All @@ -290,12 +290,12 @@ function Autocomplete() {
window.removeEventListener('touchstart', onTouchStart);
window.removeEventListener('touchmove', onTouchMove);
};
}, [getEnvironmentProps, searchBoxRef, panelRef, inputRef]);
}, [getEnvironmentProps, formRef, panelRef, inputRef]);

return (
<div className="aa-Autocomplete" {...autocomplete.getRootProps({})}>
<form
ref={searchBoxRef}
ref={formRef}
className="aa-Form"
{...autocomplete.getFormProps({ inputElement: inputRef.current })}
>
Expand Down
6 changes: 3 additions & 3 deletions packages/website/docs/prop-getters.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ The prop getters are functions that returns attributes and event handlers to cre

Returns the props to attach to the [environment](#environment).

You need to pass `searchBoxElement`, `panelElement` and `inputElement` so that the library creates the correct touch events for touch devices.
You need to pass `formElement`, `panelElement` and `inputElement` so that the library creates the correct touch events for touch devices.

```ts
type GetEnvironmentProps = (props: {
[key: string]: unknown;
searchBoxElement: HTMLElement;
panelElement: HTMLElement;
formElement: HTMLElement;
inputElement: HTMLInputElement;
panelElement: HTMLElement;
}) => {
onTouchStart(event: TouchEvent): void;
onTouchMove(event: TouchEvent): void;
Expand Down

0 comments on commit 79c4985

Please sign in to comment.