Skip to content

Commit

Permalink
fix: scroll popup into view only if required
Browse files Browse the repository at this point in the history
affects: @medly-components/core, @medly-components/forms
  • Loading branch information
gmukul01 committed Jun 27, 2024
1 parent 1e3e30a commit e5967d8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/components/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Component: FC<CalendarProps> = memo(
}, [date, minSelectableDate, maxSelectableDate]);

useEffect(() => {
ref.current?.scrollIntoView(true);
ref.current?.scrollIntoView({ behavior: 'instant', block: 'nearest' });
}, []);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const Component: FC<Props> = memo(props => {
}, [selectedDates.startDate, selectedDates.endDate]);

useEffect(() => {
ref.current?.scrollIntoView(true);
ref.current?.scrollIntoView({ behavior: 'instant', block: 'nearest' });
}, []);

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/Popover/Popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Component: FC<PopoverPopupProps> = memo(
stopPropagation = useCallback((e: React.MouseEvent) => e.stopPropagation(), []);

useEffect(() => {
isOpen && popupRef.current?.scrollIntoView(true);
isOpen && popupRef.current?.scrollIntoView({ behavior: 'instant', block: 'nearest' });
}, [isOpen]);

return isOpen ? <PopupStyled ref={popupRef} onClick={stopPropagation} placement={props.placement!} {...props} /> : null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArrowRightIcon, CheckIcon } from '@medly-components/icons';
import { useKeyPress, useOuterClickNotifier, WithStyle } from '@medly-components/utils';
import { WithStyle, useKeyPress, useOuterClickNotifier } from '@medly-components/utils';
import type { FC } from 'react';
import { isValidElement, memo, useCallback, useEffect, useRef, useState } from 'react';
import { withTheme } from 'styled-components';
Expand Down Expand Up @@ -32,6 +32,7 @@ const Component: FC<OptionProps> = memo(props => {
useEffect(() => {
(selected || hovered) &&
ref.current?.scrollIntoView({
behavior: 'instant',
block: 'nearest'
});
}, [selected, hovered]);
Expand Down

0 comments on commit e5967d8

Please sign in to comment.