Skip to content

Commit

Permalink
Recalculate maxHeight on resize and scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
kudlajz committed Nov 4, 2024
1 parent 5223c32 commit 825710d
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/slate-editor/src/components/SearchInput/Suggestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function Suggestions<T>({
placement: 'bottom-end',
});

const updatePanelSizeAndPosition = useFunction(() => {
const updatePanelSize = useFunction(() => {
setHeight(childrenContainer.current?.getBoundingClientRect().height);

if (container.current) {
Expand All @@ -65,18 +65,22 @@ export function Suggestions<T>({
}
});

useEffect(updatePanelSizeAndPosition, [
query,
suggestions,
calculatedMaxHeight,
minHeight,
maxHeight,
]);
useEffect(() => {
window.addEventListener('scroll', updatePanelSize);
window.addEventListener('resize', updatePanelSize);

return () => {
window.removeEventListener('scroll', updatePanelSize);
window.removeEventListener('resize', updatePanelSize);
};
}, [updatePanelSize]);

useEffect(updatePanelSize, [query, suggestions, minHeight, maxHeight]);

useEffect(() => {
async function repositionPopper() {
await popper.update?.();
updatePanelSizeAndPosition();
updatePanelSize();

if (activeElement) {
scrollarea?.ensureVisible(activeElement);
Expand Down

0 comments on commit 825710d

Please sign in to comment.