Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getClosestTabbable( target, isReverse ) {
// Since the current focus target is not guaranteed to be a text field,
// find all focusables. Tabbability is considered later.
let focusableNodes = focus.focusable.find( this.container );
if ( isReverse ) {
focusableNodes = reverse( focusableNodes );
}
// Consider as candidates those focusables after the current target.
// It's assumed this can only be reached if the target is focusable
// (on its keydown event), so no need to verify it exists in the set.
focusableNodes = focusableNodes.slice( focusableNodes.indexOf( target ) + 1 );
function isTabCandidate( node, i, array ) {
// Not a candidate if the node is not tabbable.
if ( ! focus.tabbable.isTabbableIndex( node ) ) {
return false;
}
disable() {
focus.focusable.find( this.node ).forEach( ( focusable ) => {
if ( includes( DISABLED_ELIGIBLE_NODE_NAMES, focusable.nodeName ) ) {
focusable.setAttribute( 'disabled', '' );
}
if ( focusable.hasAttribute( 'tabindex' ) ) {
focusable.removeAttribute( 'tabindex' );
}
if ( focusable.hasAttribute( 'contenteditable' ) ) {
focusable.setAttribute( 'contenteditable', 'false' );
}
} );
}
getFocusableContext( target ) {
const { onlyBrowserTabstops } = this.props;
const finder = onlyBrowserTabstops ? focus.tabbable : focus.focusable;
const focusables = finder.find( this.container );
const index = this.getFocusableIndex( focusables, target );
if ( index > -1 && target ) {
return { index, target, focusables };
}
return null;
}
function getRowFocusables( rowElement ) {
const focusablesInRow = focus.focusable.find( rowElement );
if ( ! focusablesInRow || ! focusablesInRow.length ) {
return;
}
return focusablesInRow.filter( ( focusable ) => {
return focusable.closest( '[role="treeitem"]' ) === rowElement;
} );
}