Skip to content

Commit

Permalink
Fix scroll position for IE
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Kim committed Mar 7, 2018
1 parent 64aa20e commit 4dc981d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
18 changes: 12 additions & 6 deletions example-app/app/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@ import { Portal } from 'react-redux-popup';
class App extends Component {
constructor(props) {
super(props);
this.openModal = () => this.props.openPopup('modal1');
this.openModal = () => props.openPopup('modal1');
this.scroll = () => props.refreshPopupPosition();
}

componentDidMount() {
window.addEventListener('scroll', this.scroll);
}

componentWillUnmount() {
window.removeEventListener('scroll', this.scroll);
}

render() {
return (
<div
style={{overflow:'auto', height:'400px'}}
onScroll={this.scroll.bind(this)}
onScroll={this.scroll}
ref={div => { this.containerElement = div; }}>
<button onClick={this.openModal}>Open Modal</button>
<div className="abc" style={{height:'1000px'}}>
Expand All @@ -35,10 +45,6 @@ class App extends Component {
</div>
);
}

scroll(event) {
this.props.refreshPopupPosition();
}
}

export default connect(null, { closePopup, openPopup, refreshPopupPosition })(App);
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-redux-popup",
"version": "2.1.7",
"version": "2.1.8",
"description": "React redux popup",
"license": "MIT",
"main": "lib/react-redux-popup",
Expand Down
16 changes: 8 additions & 8 deletions src/__tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ describe('utils', function() {
});

it('should anchor to bottom when enough space below and window has scrolled', () => {
window.scrollX = 20;
window.scrollY = 30;
window.pageXOffset = 20;
window.pageYOffset = 30;

const anchor = 'bottom';
const rect = { bottom: 50, left: 10, right: 50, top: 10 };
Expand All @@ -488,8 +488,8 @@ describe('utils', function() {
});

it('should anchor to top when enough space above and window has scrolled', () => {
window.scrollX = 20;
window.scrollY = 30;
window.pageXOffset = 20;
window.pageYOffset = 30;

const anchor = 'top';
const rect = { bottom: 290, left: 10, right: 50, top: 250 };
Expand All @@ -514,8 +514,8 @@ describe('utils', function() {
});

it('should anchor to right when enough space on the right and window has scrolled', () => {
window.scrollX = 20;
window.scrollY = 30;
window.pageXOffset = 20;
window.pageYOffset = 30;

const anchor = 'right';
const rect = { bottom: 50, left: 10, right: 50, top: 10 };
Expand All @@ -540,8 +540,8 @@ describe('utils', function() {
});

it('should anchor to left when enough space on the left and window has scrolled', () => {
window.scrollX = 20;
window.scrollY = 30;
window.pageXOffset = 20;
window.pageYOffset = 30;

const anchor = 'left';
const rect = { bottom: 50, left: 250, right: 290, top: 10 };
Expand Down
8 changes: 4 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ export function getPopupPosition(
windowWidth,
popupWidth,
rect.left,
rect.right) + window.scrollX,
rect.right) + window.pageXOffset,
top: calculatePosition(
windowHeight,
popupHeight,
rect.top,
rect.bottom,
offset,
anchor === 'bottom') + window.scrollY
anchor === 'bottom') + window.pageYOffset
};
default: // left and right
return {
Expand All @@ -64,12 +64,12 @@ export function getPopupPosition(
rect.left,
rect.right,
offset,
anchor === 'right') + window.scrollX,
anchor === 'right') + window.pageXOffset,
top: adjustPosition(
windowHeight,
popupHeight,
rect.top,
rect.bottom) + window.scrollY
rect.bottom) + window.pageYOffset
};
}
}

0 comments on commit 4dc981d

Please sign in to comment.