Skip to content

Commit

Permalink
[SwipeableDrawer] Make paper ref accessible (mui#35082)
Browse files Browse the repository at this point in the history
Signed-off-by: Zeeshan Tamboli <[email protected]>
Co-authored-by: Zeeshan Tamboli <[email protected]>
  • Loading branch information
2 people authored and felipe.richter committed Dec 6, 2022
1 parent 0563518 commit d441706
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/mui-material/src/SwipeableDrawer/SwipeableDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { elementTypeAcceptingRef } from '@mui/utils';
import { useThemeProps } from '@mui/system';
import { NoSsr } from '@mui/base';
import Drawer, { getAnchor, isHorizontal } from '../Drawer/Drawer';
import useForkRef from '../utils/useForkRef';
import ownerDocument from '../utils/ownerDocument';
import ownerWindow from '../utils/ownerWindow';
import useEventCallback from '../utils/useEventCallback';
Expand Down Expand Up @@ -168,6 +169,8 @@ const SwipeableDrawer = React.forwardRef(function SwipeableDrawer(inProps, ref)
const backdropRef = React.useRef();
const paperRef = React.useRef();

const handleRef = useForkRef(PaperProps.ref, paperRef);

const touchDetected = React.useRef(false);

// Ref for transition duration based on / to match swipe speed
Expand Down Expand Up @@ -574,7 +577,7 @@ const SwipeableDrawer = React.forwardRef(function SwipeableDrawer(inProps, ref)
pointerEvents: variant === 'temporary' && !open ? 'none' : '',
...PaperProps.style,
},
ref: paperRef,
ref: handleRef,
}}
anchor={anchor}
transitionDuration={calculatedDurationRef.current || transitionDuration}
Expand Down
10 changes: 10 additions & 0 deletions packages/mui-material/src/SwipeableDrawer/SwipeableDrawer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,16 @@ describe('<SwipeableDrawer />', () => {
setProps({ variant: 'temporary' });
expect(document.querySelector('[class*=PrivateSwipeArea-root]')).not.to.equal(null);
});

it('should be able to attach paper ref passed through PaperProps', () => {
const ref = React.createRef();
render(
<SwipeableDrawer onOpen={() => {}} onClose={() => {}} PaperProps={{ ref }} open>
<div />
</SwipeableDrawer>,
);
expect(ref.current).not.to.equal(null);
});
});

describe('disableSwipeToOpen', () => {
Expand Down

0 comments on commit d441706

Please sign in to comment.