Skip to content

Commit

Permalink
Popover: Avoid resetting the isMobile state when not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Nov 16, 2017
1 parent 01378bc commit c5bc012
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
19 changes: 12 additions & 7 deletions components/popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,19 @@ class Popover extends Component {
popover.style.top = 0;
popover.style.right = 0;
popover.style.bottom = 0;
if ( ! this.state.isMobile ) {
this.setState( {
isMobile: true,
} );
}
return;
}

if ( this.state.isMobile ) {
this.setState( {
isMobile: true,
isMobile: false,
} );
return;
}
this.setState( {
isMobile: false,
} );

const [ yAxis, xAxis ] = this.getPositions();
const isTop = 'top' === yAxis;
Expand All @@ -186,8 +191,8 @@ class Popover extends Component {
return;
}

//popover.style.bottom = 'auto';
//popover.style.right = 'auto';
popover.style.bottom = 'auto';
popover.style.right = 'auto';

if ( isRight ) {
popover.style.left = rect.left + ARROW_OFFSET + 'px';
Expand Down
6 changes: 4 additions & 2 deletions components/popover/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ describe( 'Popover', () => {
style: {},
};

instance.setState = () => {};

return instance;
}

Expand All @@ -240,6 +238,8 @@ describe( 'Popover', () => {
expect( instance.nodes.popover.style ).toEqual( {
left: '225px',
top: '210px',
right: 'auto',
bottom: 'auto',
} );
} );

Expand All @@ -252,6 +252,8 @@ describe( 'Popover', () => {
expect( instance.nodes.popover.style ).toEqual( {
left: '225px',
top: '395px',
right: 'auto',
bottom: 'auto',
} );
} );
} );
Expand Down

0 comments on commit c5bc012

Please sign in to comment.