Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AutoComplete] Fix issue with popover positioning on iOS #7333

Merged
merged 1 commit into from
Jul 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/Popover/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import propTypes from '../utils/propTypes';
import Paper from '../Paper';
import throttle from 'lodash.throttle';
import PopoverAnimationDefault from './PopoverAnimationDefault';
import {isIOS, getOffsetTop} from '../utils/iOSHelpers';

const styles = {
root: {
Expand Down Expand Up @@ -253,14 +252,7 @@ class Popover extends Component {
};

a.right = rect.right || a.left + a.width;

// The fixed positioning isn't respected on iOS when an input is focused.
// We need to compute the position from the top of the page and not the viewport.
if (isIOS() && document.activeElement.tagName === 'INPUT') {
a.bottom = getOffsetTop(el) + a.height;
} else {
a.bottom = rect.bottom || a.top + a.height;
}
a.bottom = rect.bottom || a.top + a.height;
a.middle = a.left + ((a.right - a.left) / 2);
a.center = a.top + ((a.bottom - a.top) / 2);

Expand Down
16 changes: 2 additions & 14 deletions src/Popover/Popover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,17 @@ describe('<Popover />', () => {
getBoundingClientRect,
};
/* eslint-disable max-len */
const userAgentsWithIOS = [
const userAgents = [
'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53',
'Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53',
'Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A101a Safari/419.3',
];
const nonIOSuserAgents = [
'Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)',
'Mozilla/5.0 (Linux; Android 4.4.4; Nexus 7 Build/KTU84Q) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Safari/537.36',
'Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+',
];
/* eslint-enable max-len */

userAgentsWithIOS.forEach((agent) => {
it(`should use absolute positioning for ${agent}`, () => {
window.navigator.__defineGetter__('userAgent', () => agent); // eslint-disable-line no-underscore-dangle,max-len
const wrapper = mountWithContext(<Popover open={true} animated={true} />);
const result = wrapper.instance().getAnchorPosition(el);
const expected = {bottom: 30, top: 10, center: 20, left: 10, right: 10, middle: 10, height: 10, width: 10};
assert.deepEqual(result, expected);
});
});

nonIOSuserAgents.forEach((agent) => {
userAgents.forEach((agent) => {
it(`should use normal positioning for ${agent}`, () => {
window.navigator.__defineGetter__('userAgent', () => agent); // eslint-disable-line no-underscore-dangle,max-len
const wrapper = mountWithContext(<Popover open={true} animated={true} />);
Expand Down
20 changes: 0 additions & 20 deletions src/utils/iOSHelpers.js

This file was deleted.

43 changes: 0 additions & 43 deletions src/utils/iOSHelpers.spec.js

This file was deleted.