Skip to content

Commit

Permalink
[Slide] Fix double negation in CSS translate (#21115)
Browse files Browse the repository at this point in the history
  • Loading branch information
scristall committed May 19, 2020
1 parent 8357c68 commit ee5c39e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/material-ui/src/Slide/Slide.js
Expand Up @@ -36,15 +36,15 @@ function getTranslateValue(direction, node) {
}

if (direction === 'left') {
return `translateX(${window.innerWidth}px) translateX(-${rect.left - offsetX}px)`;
return `translateX(${window.innerWidth}px) translateX(${offsetX - rect.left}px)`;
}

if (direction === 'right') {
return `translateX(-${rect.left + rect.width - offsetX}px)`;
}

if (direction === 'up') {
return `translateY(${window.innerHeight}px) translateY(-${rect.top - offsetY}px)`;
return `translateY(${window.innerHeight}px) translateY(${offsetY - rect.top}px)`;
}

// direction === 'down'
Expand Down
43 changes: 43 additions & 0 deletions packages/material-ui/src/Slide/Slide.test.js
Expand Up @@ -185,6 +185,7 @@ describe('<Slide />', () => {
right: 800,
top: 200,
bottom: 500,
...props.rect,
}));
} catch (error) {
// already stubbed
Expand Down Expand Up @@ -291,6 +292,48 @@ describe('<Slide />', () => {

expect(nodeEnterTransformStyle).to.equal('translateX(-800px)');
});

it('should set element transform in the `up` direction when element is offscreen', () => {
const childRef = React.createRef();
let nodeEnterTransformStyle;
const wrapper = mount(
<Slide
direction="up"
onEnter={(node) => {
nodeEnterTransformStyle = node.style.transform;
}}
>
<FakeDiv rect={{ top: -100 }} ref={childRef} />
</Slide>,
);

wrapper.setProps({ in: true });

expect(nodeEnterTransformStyle).to.equal(
`translateY(${global.innerHeight}px) translateY(100px)`,
);
});

it('should set element transform in the `left` direction when element is offscreen', () => {
const childRef = React.createRef();
let nodeEnterTransformStyle;
const wrapper = mount(
<Slide
direction="left"
onEnter={(node) => {
nodeEnterTransformStyle = node.style.transform;
}}
>
<FakeDiv rect={{ left: -100 }} ref={childRef} />
</Slide>,
);

wrapper.setProps({ in: true });

expect(nodeEnterTransformStyle).to.equal(
`translateX(${global.innerWidth}px) translateX(100px)`,
);
});
});

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

0 comments on commit ee5c39e

Please sign in to comment.