Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-focus-trap

Package Overview
Dependencies
Maintainers
2
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-focus-trap - npm Package Compare versions

Comparing version 2.3.3 to 2.4.0

2

package.json
{
"name": "react-focus-trap",
"version": "2.3.3",
"version": "2.4.0",
"description": "Traps focus for accessible dropdowns and modal content.",

@@ -5,0 +5,0 @@ "main": "src/focus-trap.js",

'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
/**

@@ -22,83 +30,116 @@ * FocalPoint

var FocalPoint = React.createClass({
displayName: 'FocalPoint',
getDefaultProps: function getDefaultProps() {
return {
element: 'div'
};
},
contains: function contains(element) {
return this.refs.root.contains(element);
},
focus: function focus() {
if (this.contains(document.activeElement) === false) {
this.refs.root.focus();
var FocalPoint = function (_React$Component) {
_inherits(FocalPoint, _React$Component);
function FocalPoint() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, FocalPoint);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
},
trapFocus: function trapFocus(e) {
clearTimeout(timer);
timer = setTimeout(function (_) {
return stack[stack.length - 1].focus();
}, 10);
},
returnFocus: function returnFocus() {
var anchor = this.state.anchor;
// When transitioning between pages using hash route state,
// this anchor is some times lost. Do not attempt to focus
// on a non-existent anchor.
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = FocalPoint.__proto__ || Object.getPrototypeOf(FocalPoint)).call.apply(_ref, [this].concat(args))), _this), _this._onBlur = function (event) {
var current = stack[stack.length - 1];
if (anchor && (typeof anchor === 'undefined' ? 'undefined' : _typeof(anchor)) === 'object' && typeof anchor.focus === 'function') {
anchor.focus();
if (current && current.contains(event.target) === false) {
event.preventDefault();
_this.trapFocus();
}
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(FocalPoint, [{
key: 'contains',
value: function contains(element) {
return this.refs.root.contains(element);
}
},
componentWillMount: function componentWillMount() {
if (typeof document !== 'undefined') {
this.setState({ anchor: document.activeElement });
}, {
key: 'focus',
value: function focus() {
if (this.contains(document.activeElement) === false) {
this.refs.root.focus();
}
}
},
componentDidMount: function componentDidMount() {
stack.push(this);
}, {
key: 'trapFocus',
value: function trapFocus(e) {
clearTimeout(timer);
timer = setTimeout(function (_) {
return stack[stack.length - 1].focus();
}, 10);
}
}, {
key: 'returnFocus',
value: function returnFocus() {
var anchor = this.state.anchor;
this.trapFocus();
// When transitioning between pages using hash route state,
// this anchor is some times lost. Do not attempt to focus
// on a non-existent anchor.
document.addEventListener('focus', this._onBlur, true);
},
componentWillUnmount: function componentWillUnmount() {
var _this = this;
if (anchor && (typeof anchor === 'undefined' ? 'undefined' : _typeof(anchor)) === 'object' && typeof anchor.focus === 'function') {
anchor.focus();
}
}
}, {
key: 'componentWillMount',
value: function componentWillMount() {
if (typeof document !== 'undefined') {
this.setState({ anchor: document.activeElement });
}
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
stack.push(this);
stack = stack.filter(function (i) {
return i !== _this;
});
this.trapFocus();
document.removeEventListener('focus', this._onBlur, true);
document.addEventListener('focus', this._onBlur, true);
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
var _this2 = this;
clearTimeout(timer);
stack = stack.filter(function (i) {
return i !== _this2;
});
this.returnFocus();
},
render: function render() {
var _props = this.props;
var children = _props.children;
var Element = _props.element;
var className = _props.className;
document.removeEventListener('focus', this._onBlur, true);
clearTimeout(timer);
return React.createElement(
Element,
{ ref: 'root', tabIndex: '0', className: className },
children
);
},
_onBlur: function _onBlur(event) {
var current = stack[stack.length - 1];
this.returnFocus();
}
}, {
key: 'render',
value: function render() {
var _props = this.props,
children = _props.children,
Element = _props.element,
className = _props.className;
if (current && current.contains(event.target) === false) {
event.preventDefault();
this.trapFocus();
return React.createElement(
Element,
{ ref: 'root', tabIndex: '0', className: className },
children
);
}
}
});
}]);
return FocalPoint;
}(React.Component);
FocalPoint.defaultProps = {
element: 'div'
};
module.exports = FocalPoint;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9mb2NhbC1wb2ludC5qc3giXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztBQUFBOzs7OztBQUtBLElBQUksUUFBUSxRQUFRLE9BQVIsQ0FBWjtBQUNBLElBQUksUUFBUSxFQUFaO0FBQ0EsSUFBSSxRQUFRLElBQVo7O0FBRUE7Ozs7QUFJQSxJQUF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Expc3RlbmVyKCdmb2N1cycsIHRoaXMuX29uQmx1ciwgdHJ1ZSlcblxuICAgIGNsZWFyVGltZW91dCh0aW1lcilcblxuICAgIHRoaXMucmV0dXJuRm9jdXMoKVxuICB9LFxuXG4gIHJlbmRlcigpIHtcbiAgICBsZXQgeyBjaGlsZHJlbiwgZWxlbWVudDpFbGVtZW50LCBjbGFzc05hbWUgfSA9IHRoaXMucHJvcHNcblxuICAgIHJldHVybiAoXG4gICAgICA8RWxlbWVudCByZWY9XCJyb290XCIgdGFiSW5kZXg9XCIwXCIgY2xhc3NOYW1lPXsgY2xhc3NOYW1lIH0+XG4gICAgICAgIHsgY2hpbGRyZW4gfVxuICAgICAgPC9FbGVtZW50PlxuICAgIClcbiAgfSxcblxuICBfb25CbHVyKGV2ZW50KSB7XG4gICAgbGV0IGN1cnJlbnQgPSBzdGFja1tzdGFjay5sZW5ndGggLSAxXVxuXG4gICAgaWYgKGN1cnJlbnQgJiYgY3VycmVudC5jb250YWlucyhldmVudC50YXJnZXQpID09PSBmYWxzZSkge1xuICAgICAgZXZlbnQucHJldmVudERlZmF1bHQoKVxuICAgICAgdGhpcy50cmFwRm9jdXMoKVxuICAgIH1cbiAgfVxufSlcblxubW9kdWxlLmV4cG9ydHMgPSBGb2NhbFBvaW50XG4iXX0=
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9mb2NhbC1wb2ludC5qcyJdLCJuYW1lcyI6WyJSZWFjdCIsInJlcXVpcmUiLCJzdGFjayIsInRpbWVyIiwiZG9jdW1lbnQiLCJhY3RpdmVFbGVtZW50IiwicHVzaCIsIkZvY2FsUG9pbnQiLCJfb25CbHVyIiwiY3VycmVudCIsImxlbmd0aCIsImNvbnRhaW5zIiwiZXZlbnQiLCJ0YXJnZXQiLCJwcmV2ZW50RGVmYXVsdCIsInRyYXBGb2N1cyIsImVsZW1lbnQiLCJyZWZzIiwicm9vdCIsImZ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xlbWVudCB9KVxuICAgIH1cbiAgfVxuXG4gIGNvbXBvbmVudERpZE1vdW50KCkge1xuICAgIHN0YWNrLnB1c2godGhpcylcblxuICAgIHRoaXMudHJhcEZvY3VzKClcblxuICAgIGRvY3VtZW50LmFkZEV2ZW50TGlzdGVuZXIoJ2ZvY3VzJywgdGhpcy5fb25CbHVyLCB0cnVlKVxuICB9XG5cbiAgY29tcG9uZW50V2lsbFVubW91bnQoKSB7XG4gICAgc3RhY2sgPSBzdGFjay5maWx0ZXIoaSA9PiBpICE9PSB0aGlzKVxuXG4gICAgZG9jdW1lbnQucmVtb3ZlRXZlbnRMaXN0ZW5lcignZm9jdXMnLCB0aGlzLl9vbkJsdXIsIHRydWUpXG5cbiAgICBjbGVhclRpbWVvdXQodGltZXIpXG5cbiAgICB0aGlzLnJldHVybkZvY3VzKClcbiAgfVxuXG4gIHJlbmRlcigpIHtcbiAgICBsZXQgeyBjaGlsZHJlbiwgZWxlbWVudDogRWxlbWVudCwgY2xhc3NOYW1lIH0gPSB0aGlzLnByb3BzXG5cbiAgICByZXR1cm4gKFxuICAgICAgPEVsZW1lbnQgcmVmPVwicm9vdFwiIHRhYkluZGV4PVwiMFwiIGNsYXNzTmFtZT17Y2xhc3NOYW1lfT5cbiAgICAgICAge2NoaWxkcmVufVxuICAgICAgPC9FbGVtZW50PlxuICAgIClcbiAgfVxuXG4gIF9vbkJsdXIgPSBldmVudCA9PiB7XG4gICAgbGV0IGN1cnJlbnQgPSBzdGFja1tzdGFjay5sZW5ndGggLSAxXVxuXG4gICAgaWYgKGN1cnJlbnQgJiYgY3VycmVudC5jb250YWlucyhldmVudC50YXJnZXQpID09PSBmYWxzZSkge1xuICAgICAgZXZlbnQucHJldmVudERlZmF1bHQoKVxuICAgICAgdGhpcy50cmFwRm9jdXMoKVxuICAgIH1cbiAgfVxufVxuXG5tb2R1bGUuZXhwb3J0cyA9IEZvY2FsUG9pbnRcbiJdfQ==
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var FocalPoint = require('./focal-point');
var React = require('react');
var FocusTrap = React.createClass({
displayName: 'FocusTrap',
var FocusTrap = function (_React$Component) {
_inherits(FocusTrap, _React$Component);
function FocusTrap() {
var _ref;
propTypes: {
active: React.PropTypes.bool,
onExit: React.PropTypes.func
},
var _temp, _this, _ret;
getDefaultProps: function getDefaultProps() {
return {
active: true,
className: 'focus-trap'
};
},
render: function render() {
var _props = this.props;
var active = _props.active;
var className = _props.className;
var children = _props.children;
var element = _props.element;
var onExit = _props.onExit;
_classCallCheck(this, FocusTrap);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (!active) return null;
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = FocusTrap.__proto__ || Object.getPrototypeOf(FocusTrap)).call.apply(_ref, [this].concat(args))), _this), _this._onKeyUp = function (event) {
if (event.key === 'Escape' && 'onExit' in _this.props) {
_this.props.onExit();
}
}, _temp), _possibleConstructorReturn(_this, _ret);
}
return React.createElement(
'div',
{ className: className + '-wrapper', onKeyUp: this._onKeyUp },
React.createElement('div', { 'aria-hidden': 'true', className: className + '-backdrop', onClick: onExit }),
React.createElement(
FocalPoint,
{ ref: 'focus', className: className, element: element },
children
)
);
},
_onKeyUp: function _onKeyUp(e) {
if (e.key === 'Escape' && 'onExit' in this.props) {
this.props.onExit();
_createClass(FocusTrap, [{
key: 'render',
value: function render() {
var _props = this.props,
active = _props.active,
className = _props.className,
children = _props.children,
element = _props.element,
onExit = _props.onExit;
if (!active) return null;
return React.createElement(
'div',
{ className: className + '-wrapper', onKeyUp: this._onKeyUp },
React.createElement('div', {
'aria-hidden': 'true',
className: className + '-backdrop',
onClick: onExit
}),
React.createElement(
FocalPoint,
{ ref: 'focus', className: className, element: element },
children
)
);
}
}
});
}]);
return FocusTrap;
}(React.Component);
FocusTrap.defaultProps = {
active: true,
className: 'focus-trap'
};
module.exports = FocusTrap;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9mb2N1cy10cmFwLmpzeCJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLElBQUksYUFBYSxRQUFRLGVBQVIsQ0FBakI7QUFDQSxJQUFJLFFBQWEsUUFBUSxPQUFSLENBQWpCOztBQUVBLElBQUksWUFBWSxNQUFNLFdBQU4sQ0FBa0I7QUFBQTs7O0FBRWhDLGFBQVc7QUFDVCxZQUFTLE1BQU0sU0FBTixDQUFnQixJQURoQjtBQUVULFlBQVMsTUFBTSxTQUFOLENBQWdCO0FBRmhCLEdBRnFCOztBQU9oQyxpQkFQZ0MsNkJBT2Q7QUFDaEIsV0FBTztBQUNMLGNBQVksSUFEUDtBQUVMLGlCQUFZO0FBRlAsS0FBUDtBQUlELEdBWitCO0FBY2hDLFFBZGdDLG9CQWN2QjtBQUFBLGlCQUNnRCxLQUFLLEtBRHJEO0FBQUEsUUFDRCxNQURDLFVBQ0QsTUFEQztBQUF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ludCByZWY9XCJmb2N1c1wiIGNsYXNzTmFtZT17Y2xhc3NOYW1lfSBlbGVtZW50PXtlbGVtZW50fT5cbiAgICAgICAgICB7Y2hpbGRyZW59XG4gICAgICAgIDwvRm9jYWxQb2ludD5cbiAgICAgIDwvZGl2PlxuICAgIClcbiAgfVxuXG4gIF9vbktleVVwID0gZXZlbnQgPT4ge1xuICAgIGlmIChldmVudC5rZXkgPT09ICdFc2NhcGUnICYmICdvbkV4aXQnIGluIHRoaXMucHJvcHMpIHtcbiAgICAgIHRoaXMucHJvcHMub25FeGl0KClcbiAgICB9XG4gIH1cbn1cblxubW9kdWxlLmV4cG9ydHMgPSBGb2N1c1RyYXBcbiJdfQ==
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc