@wordpress/dom
Advanced tools
Comparing version 2.6.0 to 2.7.0
/** | ||
* External dependencies | ||
*/ | ||
import { without } from 'lodash'; | ||
import { without, first, last } from 'lodash'; | ||
/** | ||
@@ -134,6 +134,50 @@ * Internal dependencies | ||
} | ||
/** | ||
* Givin focusable elements, filters out tabbable element. | ||
* | ||
* @param {Array} focusables Focusable elements to filter. | ||
* | ||
* @return {Array} Tabbable elements. | ||
*/ | ||
function filterTabbable(focusables) { | ||
return focusables.filter(isTabbableIndex).map(mapElementToObjectTabbable).sort(compareObjectTabbables).map(mapObjectTabbableToElement).reduce(createStatefulCollapseRadioGroup(), []); | ||
} | ||
export function find(context) { | ||
return findFocusable(context).filter(isTabbableIndex).map(mapElementToObjectTabbable).sort(compareObjectTabbables).map(mapObjectTabbableToElement).reduce(createStatefulCollapseRadioGroup(), []); | ||
return filterTabbable(findFocusable(context)); | ||
} | ||
/** | ||
* Given a focusable element, find the preceding tabbable element. | ||
* | ||
* @param {Element} element The focusable element before which to look. Defaults | ||
* to the active element. | ||
*/ | ||
export function findPrevious() { | ||
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.activeElement; | ||
var focusables = findFocusable(document.body); | ||
var index = focusables.indexOf(element); // Remove all focusables after and including `element`. | ||
focusables.length = index; | ||
return last(filterTabbable(focusables)); | ||
} | ||
/** | ||
* Given a focusable element, find the next tabbable element. | ||
* | ||
* @param {Element} element The focusable element after which to look. Defaults | ||
* to the active element. | ||
*/ | ||
export function findNext() { | ||
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.activeElement; | ||
var focusables = findFocusable(document.body); | ||
var index = focusables.indexOf(element); // Remove all focusables before and inside `element`. | ||
var remaining = focusables.slice(index + 1).filter(function (node) { | ||
return !element.contains(node); | ||
}); | ||
return first(filterTabbable(remaining)); | ||
} | ||
//# sourceMappingURL=tabbable.js.map |
@@ -8,2 +8,4 @@ "use strict"; | ||
exports.find = find; | ||
exports.findPrevious = findPrevious; | ||
exports.findNext = findNext; | ||
@@ -146,6 +148,52 @@ var _lodash = require("lodash"); | ||
} | ||
/** | ||
* Givin focusable elements, filters out tabbable element. | ||
* | ||
* @param {Array} focusables Focusable elements to filter. | ||
* | ||
* @return {Array} Tabbable elements. | ||
*/ | ||
function filterTabbable(focusables) { | ||
return focusables.filter(isTabbableIndex).map(mapElementToObjectTabbable).sort(compareObjectTabbables).map(mapObjectTabbableToElement).reduce(createStatefulCollapseRadioGroup(), []); | ||
} | ||
function find(context) { | ||
return (0, _focusable.find)(context).filter(isTabbableIndex).map(mapElementToObjectTabbable).sort(compareObjectTabbables).map(mapObjectTabbableToElement).reduce(createStatefulCollapseRadioGroup(), []); | ||
return filterTabbable((0, _focusable.find)(context)); | ||
} | ||
/** | ||
* Given a focusable element, find the preceding tabbable element. | ||
* | ||
* @param {Element} element The focusable element before which to look. Defaults | ||
* to the active element. | ||
*/ | ||
function findPrevious() { | ||
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.activeElement; | ||
var focusables = (0, _focusable.find)(document.body); | ||
var index = focusables.indexOf(element); // Remove all focusables after and including `element`. | ||
focusables.length = index; | ||
return (0, _lodash.last)(filterTabbable(focusables)); | ||
} | ||
/** | ||
* Given a focusable element, find the next tabbable element. | ||
* | ||
* @param {Element} element The focusable element after which to look. Defaults | ||
* to the active element. | ||
*/ | ||
function findNext() { | ||
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.activeElement; | ||
var focusables = (0, _focusable.find)(document.body); | ||
var index = focusables.indexOf(element); // Remove all focusables before and inside `element`. | ||
var remaining = focusables.slice(index + 1).filter(function (node) { | ||
return !element.contains(node); | ||
}); | ||
return (0, _lodash.first)(filterTabbable(remaining)); | ||
} | ||
//# sourceMappingURL=tabbable.js.map |
### WordPress - Web publishing software | ||
Copyright 2011-2019 by the contributors | ||
Copyright 2011-2020 by the contributors | ||
@@ -5,0 +5,0 @@ This program is free software; you can redistribute it and/or modify |
{ | ||
"name": "@wordpress/dom", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"description": "DOM utilities module for WordPress.", | ||
@@ -32,3 +32,3 @@ "author": "The WordPress Contributors", | ||
}, | ||
"gitHead": "52bfe7deb90fe2b6df7f1a0a92f89cc69462a491" | ||
"gitHead": "3e867dd7c6560e4b2cb9a59cc02856e055be6142" | ||
} |
/** | ||
* External dependencies | ||
*/ | ||
import { without } from 'lodash'; | ||
import { without, first, last } from 'lodash'; | ||
@@ -128,4 +128,11 @@ /** | ||
export function find( context ) { | ||
return findFocusable( context ) | ||
/** | ||
* Givin focusable elements, filters out tabbable element. | ||
* | ||
* @param {Array} focusables Focusable elements to filter. | ||
* | ||
* @return {Array} Tabbable elements. | ||
*/ | ||
function filterTabbable( focusables ) { | ||
return focusables | ||
.filter( isTabbableIndex ) | ||
@@ -137,1 +144,39 @@ .map( mapElementToObjectTabbable ) | ||
} | ||
export function find( context ) { | ||
return filterTabbable( findFocusable( context ) ); | ||
} | ||
/** | ||
* Given a focusable element, find the preceding tabbable element. | ||
* | ||
* @param {Element} element The focusable element before which to look. Defaults | ||
* to the active element. | ||
*/ | ||
export function findPrevious( element = document.activeElement ) { | ||
const focusables = findFocusable( document.body ); | ||
const index = focusables.indexOf( element ); | ||
// Remove all focusables after and including `element`. | ||
focusables.length = index; | ||
return last( filterTabbable( focusables ) ); | ||
} | ||
/** | ||
* Given a focusable element, find the next tabbable element. | ||
* | ||
* @param {Element} element The focusable element after which to look. Defaults | ||
* to the active element. | ||
*/ | ||
export function findNext( element = document.activeElement ) { | ||
const focusables = findFocusable( document.body ); | ||
const index = focusables.indexOf( element ); | ||
// Remove all focusables before and inside `element`. | ||
const remaining = focusables | ||
.slice( index + 1 ) | ||
.filter( ( node ) => ! element.contains( node ) ); | ||
return first( filterTabbable( remaining ) ); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
220038
2804