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

Use IE's msMatchesSelector when matches is not available #129

Merged
merged 1 commit into from
Aug 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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