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.5.0 to 2.6.0-beta.0

66

index.js

@@ -12,13 +12,5 @@ 'use strict';

var stack = [];
var timer = null;
var isDOM = typeof document !== 'undefined';
/**
* To support server-side rendering, do not push the active element
* when not in the browser environment
*/
if (typeof document !== 'undefined' && document.activeElement) {
stack.push(document.activeElement);
}
var defaultProps$1 = {

@@ -32,2 +24,5 @@ element: 'div'

this.anchor = null;
this.focus = this.focus.bind(this);
this._onBlur = this._onBlur.bind(this);

@@ -53,9 +48,6 @@ this._setRoot = this._setRoot.bind(this);

clearTimeout(timer);
timer = setTimeout(function (_) { return stack[stack.length - 1].focus(); }, 10);
timer = setTimeout(this.focus, 10);
};
FocalPoint.prototype.returnFocus = function returnFocus () {
var ref = this.state;
var anchor = ref.anchor;
// When transitioning between pages using hash route state,

@@ -65,7 +57,7 @@ // this anchor is some times lost. Do not attempt to focus

if (
anchor &&
typeof anchor === 'object' &&
typeof anchor.focus === 'function'
this.anchor &&
typeof this.anchor === 'object' &&
typeof this.anchor.focus === 'function'
) {
anchor.focus();
this.anchor.focus();
}

@@ -75,4 +67,4 @@ };

FocalPoint.prototype.componentWillMount = function componentWillMount () {
if (typeof document !== 'undefined') {
this.setState({ anchor: document.activeElement });
if (isDOM) {
this.anchor = document.activeElement;
}

@@ -82,4 +74,2 @@ };

FocalPoint.prototype.componentDidMount = function componentDidMount () {
stack.push(this);
this.trapFocus();

@@ -91,6 +81,2 @@

FocalPoint.prototype.componentWillUnmount = function componentWillUnmount () {
var this$1 = this;
stack = stack.filter(function (i) { return i !== this$1; });
document.removeEventListener('focus', this._onBlur, true);

@@ -101,2 +87,4 @@

this.returnFocus();
this.anchor = null;
};

@@ -107,10 +95,11 @@

var children = ref.children;
var Element = ref.element;
var element = ref.element;
var className = ref.className;
return (
React.createElement( Element, { ref: this._setRoot, tabIndex: "0", className: className },
children
)
)
return React.createElement(element, {
ref: this._setRoot,
tabIndex: 0,
className: className,
children: children
})
};

@@ -125,3 +114,3 @@

FocalPoint.prototype._onBlur = function _onBlur (event) {
var current = stack[stack.length - 1];
var current = this.anchor;

@@ -141,3 +130,4 @@ if (current && current.contains(event.target) === false) {

active: true,
className: 'focus-trap'
className: 'focus-trap',
onExit: function () {}
};

@@ -148,5 +138,3 @@

superclass.call(this, props, context);
this._onKeyUp = this._onKeyUp.bind(this);
this._setFocus = this._setFocus.bind(this);
}

@@ -172,3 +160,3 @@

'aria-hidden': "true", className: (className + "-backdrop"), onClick: onExit }),
React.createElement( FocalPoint, { ref: this._setFocus, className: className, element: element },
React.createElement( FocalPoint, { className: className, element: element },
children

@@ -182,8 +170,4 @@ )

FocusTrap.prototype._setFocus = function _setFocus (el) {
this.focus = el;
};
FocusTrap.prototype._onKeyUp = function _onKeyUp (event) {
if (event.key === 'Escape' && 'onExit' in this.props) {
if (event.key === 'Escape') {
this.props.onExit();

@@ -190,0 +174,0 @@ }

{
"name": "react-focus-trap",
"version": "2.5.0",
"version": "2.6.0-beta.0",
"description": "Traps focus for accessible dropdowns and modal content.",

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

Sorry, the diff of this file is not supported yet

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