Skip to content

Commit

Permalink
fix(react-renderer): panel now closes when clicking/touching outside (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aymeric-giraudet authored Nov 16, 2022
1 parent d0ca975 commit b133e85
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/react-renderer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import './App.css';
export function App() {
return (
<div className="container">
<Autocomplete placeholder="Search" openOnFocus={true} debug={true} />
<Autocomplete placeholder="Search" openOnFocus={true} />
</div>
);
}
6 changes: 4 additions & 2 deletions examples/react-renderer/src/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,22 @@ export function Autocomplete(
return undefined;
}

const { onTouchStart, onTouchMove } = getEnvironmentProps({
const { onTouchStart, onTouchMove, onMouseDown } = getEnvironmentProps({
formElement: formRef.current,
inputElement: inputRef.current,
panelElement: panelRef.current,
});

window.addEventListener('mousedown', onMouseDown);
window.addEventListener('touchstart', onTouchStart);
window.addEventListener('touchmove', onTouchMove);

return () => {
window.removeEventListener('mousedown', onMouseDown);
window.removeEventListener('touchstart', onTouchStart);
window.removeEventListener('touchmove', onTouchMove);
};
}, [getEnvironmentProps, formRef, inputRef, panelRef]);
}, [getEnvironmentProps, autocompleteState.isOpen]);

return (
<div className="aa-Autocomplete" {...autocomplete.getRootProps({})}>
Expand Down

0 comments on commit b133e85

Please sign in to comment.