New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@trend/focustrap

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trend/focustrap

A React component that traps focus.

  • 0.4.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Focus trap

A React component that traps focus.

This component is a wrapper for focus-trap and a manual fork of focus-trap-react tailored for trend-components needs.

Installation

## Has peer dependency with react and react-dom
npm i react react-dom
npm i @trend/focustrap

Basic Usage

With a module bundler like webpack, use as you would anything else:

import React from 'react';
import FocusTrap from '@trend/focustrap';

class Demo extends React.Component {
  state = {
    activeTrap: false
  }

  mountTrap = () => {
    this.setState({ activeTrap: true });
  }

  unmountTrap = () => {
    this.setState({ activeTrap: false });
  }

  render() {
    const trap = this.state.activeTrap
      ? <FocusTrap
          focusTrapOptions={{
            onDeactivate: this.unmountTrap
          }}>
          <div style={{
            border: '1px solid rgba(0, 0, 0, 0.2',
            padding: '1rem'
          }}>
            <p>
              Here is a focus trap
              {' '}
              <a href="#">with</a>
              {' '}
              <a href="#">some</a>
              {' '}
              <a href="#">focusable</a>
              {' '}
              parts.
            </p>
            <p>
              <button onClick={this.unmountTrap}>
                deactivate trap
              </button>
            </p>
          </div>
        </FocusTrap>
      : false;

    return (
      <div className="tc-pal">
        <div className="tc-mbl">
          <button onClick={this.mountTrap}>toggle trap</button>
        </div>
        {trap}
      </div>
    );
  }
}

Props

focusTrapOptions

object | optional

See focus-trap createOptions for available options.

active

boolean | optional

Toggle the activation state of a mounted FocusTrap. By default a FocusTrap is activated and deactivated by mounting and unmounting the component.

paused

boolean | optional

See (focus-trap docs)(https://github.com/davidtheclark/focus-trap#focustrap--createfocustrapelement-createoptions) to pause and unpause a FocusTrap.

tag

string | Optional, defaults to div

An HTML tag for FocusTrap DOM node.

...rest

All additional props are passed through to the rendered DOM element.

Keywords

FAQs

Package last updated on 12 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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