all files / lib/helpers/ ariaAppHider.js

89.66% Statements 26/29
66.67% Branches 12/18
100% Functions 6/6
89.66% Lines 26/29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                    10×                        
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.setElement = setElement;
exports.validateElement = validateElement;
exports.hide = hide;
exports.show = show;
exports.toggle = toggle;
exports.resetForTesting = resetForTesting;
var globalElement = typeof document !== 'undefined' ? document.body : null;
 
function setElement(element) {
  var useElement = element;
  Iif (typeof useElement === 'string') {
    var el = document.querySelectorAll(useElement);
    useElement = 'length' in el ? el[0] : el;
  }
  globalElement = useElement || globalElement;
  return globalElement;
}
 
function validateElement(appElement) {
  Iif (!appElement && !globalElement) {
    throw new Error(['react-modal: You must set an element with', '`Modal.setAppElement(el)` to make this accessible']);
  }
}
 
function hide(appElement) {
  validateElement(appElement);
  (appElement || globalElement).setAttribute('aria-hidden', 'true');
}
 
function show(appElement) {
  validateElement(appElement);
  (appElement || globalElement).removeAttribute('aria-hidden');
}
 
function toggle(shouldHide, appElement) {
  var apply = shouldHide ? hide : show;
  apply(appElement);
}
 
function resetForTesting() {
  globalElement = document.body;
}