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

halfshot-react-aria-offcanvas

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

halfshot-react-aria-offcanvas

Accessible Off-Canvas component for React.js

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

react-aria-offcanvas

npm Travis (.org) branch npm npm bundle size code style: prettier

Accessible Off-Canvas component for React.js

Demo

https://neosiae.github.io/react-aria-offcanvas/

Installation

Install react-aria-offcanvas using npm:

npm install --save react-aria-offcanvas

Or via yarn:

yarn add react-aria-offcanvas

Usage

import React, { Component, Fragment } from 'react'
import OffCanvas from 'react-aria-offcanvas'

const Navigation = () => (
  <nav id="menu">
    <ul>
      <li>
        <a href="#m-i-1">Menu Item 1</a>
      </li>
      <li>
        <a href="#m-i-2">Menu Item 2</a>
      </li>
      <li>
        <a href="#m-i-3">Menu Item 3</a>
      </li>
      <li>
        <a href="#m-i-4">Menu Item 4</a>
      </li>
      <li>
        <a href="#m-i-5">Menu Item 5</a>
      </li>
    </ul>
  </nav>
)

export default class App extends Component {
  state = {
    isOpen: false,
  }

  open = () => {
    this.setState({ isOpen: true })
  }

  close = () => {
    this.setState({ isOpen: false })
  }

  render() {
    return (
      <Fragment>
        <button
          id="menu-button"
          aria-label="Menu"
          aria-controls="menu"
          aria-expanded={this.state.isOpen}
          onClick={this.open}
        >
          Click here
        </button>
        <OffCanvas
          isOpen={this.state.isOpen}
          onClose={this.close}
          labelledby="menu-button"
        >
          <button onClick={this.close}>Close</button>
          <Navigation />
        </OffCanvas>
      </Fragment>
    )
  }
}

Props

The only required property for the component is isOpen, which controls whether the component is displayed or not.

PropTypeDefaultDescription
isOpenboolfalseOpen or close OffCanvas.
widthstring300pxThe width of OffCanvas.
heightstring300pxThe height of OffCanvas.
positionstringleftPosition OffCanvas to the left, right, top or bottom.
mainContainerSelectorstringAllow OffCanvas to push your page. Pass a valid CSS selector of an element that should be pushed.
onClosefuncCallback fired when the overlay is clicked or esc key is pressed.
closeOnEscbooltrueClose OffCanvas on esc key.
closeOnOverlayClickbooltrueClose OffCanvas on overlay click.
lockBodyAfterOpenbooltrueLock body overflow on menu open
trapFocusAfterOpenbooltrueTrap focus when OffCanvas is open.
returnFocusAfterClosebooltrueReturn focus to the element that had focus before opening OffCanvas.
focusFirstChildAfterOpenboolSet initial focus on the first focusable child inside OffCanvas.
focusThisChildAfterOpenstringSet initial focus on a specific child inside OffCanvas. Pass a valid CSS selector of an element that should receive initial focus.
styleobject{ overlay: {}, content: {} }Inline styles object. It has two keys: overlay - overlay styles and content - OffCanvas styles.
classNamestringCustom className for OffCanvas.
overlayClassNamestringCustom className for the overlay.
rolestringCustom role for OffCanvas.
labelstringCustom aria-label for OffCanvas.
labelledbystringCustom aria-labelledby for OffCanvas.

License

MIT

Keywords

FAQs

Package last updated on 26 Sep 2023

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