Skip to content

Commit

Permalink
feat: Do not set focus in sub-menus to prevent undesirable scrolling …
Browse files Browse the repository at this point in the history
…behavior in iOS (#4607)
  • Loading branch information
alex-barstow authored and misteroneill committed Oct 2, 2017
1 parent f51d36b commit 1ac8065
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/js/menu/menu-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as Dom from '../utils/dom.js';
import * as Fn from '../utils/fn.js';
import * as Events from '../utils/events.js';
import toTitleCase from '../utils/to-title-case.js';
import { IS_IOS } from '../utils/browser.js';
import document from 'global/document';

/**
Expand Down Expand Up @@ -339,8 +340,12 @@ class MenuButton extends Component {
this.buttonPressed_ = true;
this.menu.lockShowing();
this.menuButton_.el_.setAttribute('aria-expanded', 'true');
// set the focus into the submenu
this.menu.focus();

// set the focus into the submenu, except on iOS where it is resulting in
// undesired scrolling behavior when the player is in an iframe
if (!IS_IOS && !Dom.isInFrame()) {
this.menu.focus();
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/js/utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ export function isEl(value) {
return isObject(value) && value.nodeType === 1;
}

/**
* Determines if the current DOM is embedded in an iframe.
*
* @return {boolean}
*
*/
export function isInFrame() {

// We need a try/catch here because Safari will throw errors when attempting
// to get either `parent` or `self`
try {
return window.parent !== window.self;
} catch (x) {
return true;
}
}

/**
* Creates functions to query the DOM using a given method.
*
Expand Down

0 comments on commit 1ac8065

Please sign in to comment.