Skip to content

Commit

Permalink
Use IE's msMatchesSelector when matches is not available. (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
aomarks authored and Alice committed Aug 2, 2019
1 parent a0c9c1a commit 215c781
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/inert.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
/** @type {typeof Array.prototype.slice} */
const slice = Array.prototype.slice;

/**
* IE has a non-standard name for "matches".
* @type {typeof Element.prototype.matches}
*/
const matches =
Element.prototype.matches || Element.prototype.msMatchesSelector;

/** @type {string} */
const _focusableElementsString = ['a[href]',
'area[href]',
Expand Down Expand Up @@ -177,7 +184,7 @@ class InertRoot {
this._adoptInertRoot(element);
}

if (element.matches(_focusableElementsString) || element.hasAttribute('tabindex')) {
if (matches.call(element, _focusableElementsString) || element.hasAttribute('tabindex')) {
this._manageNode(element);
}
}
Expand Down Expand Up @@ -384,7 +391,7 @@ class InertNode {
return;
}
const element = /** @type {!Element} */ (this.node);
if (element.matches(_focusableElementsString)) {
if (matches.call(element, _focusableElementsString)) {
if (/** @type {!HTMLElement} */ (element).tabIndex === -1 &&
this.hasSavedTabIndex) {
return;
Expand Down Expand Up @@ -597,7 +604,7 @@ class InertManager {
return;
}
const inertElements = slice.call(node.querySelectorAll('[inert]'));
if (node.matches('[inert]')) {
if (matches.call(node, '[inert]')) {
inertElements.unshift(node);
}
inertElements.forEach(function(inertElement) {
Expand Down

0 comments on commit 215c781

Please sign in to comment.