Skip to content

Commit

Permalink
[DatePicker] Prevent scroll on open
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Feb 19, 2021
1 parent 8fcb6c0 commit d6061b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Expand Up @@ -254,7 +254,7 @@ describe('<DesktopDatePicker />', () => {
});
});

describe.only('scroll', () => {
describe('scroll', () => {
const NoTransition = React.forwardRef(function NoTransition(
props: TransitionProps & { children?: React.ReactNode },
ref: React.Ref<HTMLDivElement>,
Expand Down
6 changes: 5 additions & 1 deletion packages/material-ui-lab/src/PickersDay/PickersDay.tsx
Expand Up @@ -128,6 +128,8 @@ export interface PickersDayProps<TDate> extends ExtendMui<ButtonBaseProps> {
onDaySelect: (day: TDate, isFinish: PickerSelectionState) => void;
}

const useEnhancedEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;

const noop = () => {};

/**
Expand Down Expand Up @@ -165,7 +167,9 @@ const PickersDay = React.forwardRef(function PickersDay<TDate>(
const ref = React.useRef<HTMLButtonElement>(null);
const handleRef = useForkRef(ref, forwardedRef);

React.useEffect(() => {
// Since this is rendered when a Popper is opened we can't use passive effects.
// Focusing in passive effects in Popper causes scroll jump.
useEnhancedEffect(() => {
if (autoFocus && !disabled && !isAnimating && !outsideCurrentMonth) {
// ref.current being null would be a bug in Material-UI
ref.current!.focus();
Expand Down

0 comments on commit d6061b7

Please sign in to comment.