@adaptabletools/adaptable
Version:
Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
27 lines (26 loc) • 810 B
JavaScript
import getFocusableChildren from './getFocusableChildren';
const emptyObject = {};
export default (node, event, config) => {
config = config || emptyObject;
const { key, target, shiftKey } = event;
if (key != 'Tab') {
return;
}
const focusableChildren = (config.getFocusableChildren || getFocusableChildren)(node);
const last = focusableChildren[focusableChildren.length - 1];
const first = focusableChildren[0];
if (target === first && first && shiftKey) {
event.preventDefault();
if (last && last.focus) {
last.focus();
}
return true;
}
if (target === last && last && !shiftKey) {
event.preventDefault();
if (first && first.focus) {
first.focus();
}
return true;
}
};