2.1.0 • Published 5 months ago

@etheryte/focus-group v2.1.0

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
5 months ago

FocusGroup

FocusGroup is a basic building block for constructing accessible menus and interactive UI components that depend on focusable elements.

Installation

yarn add @etheryte/focus-group

Props

PropDescriptionDefault value
onFocusOutOptional, function to be called when the user focus moves outside of the container.undefined

Usage

import { useState } from "react";
import { FocusGroup } from "@etheryte/focus-group";

const Example = () => {
  const [isMenuOpen, setIsMenuOpen] = useState(false);

  return (
    <FocusGroup onFocusOut={() => setIsMenuOpen(false)}>
      <button
        id="example-button"
        aria-haspopup="menu"
        aria-controls="example-menu"
        aria-expanded={isMenuOpen}
        type="button"
        onClick={() => setIsMenuOpen(!isMenuOpen)}
      >
        Open menu
      </button>
      <menu
        id="example-menu"
        aria-label="Example menu"
        hidden={!isMenuOpen}
      >
        <li>Menu item</li>
      </menu>
    </FocusGroup>
  );
};

Development

Run a development demo:

yarn start

Publish a new version:

npm login
npm publish --access public
2.1.0

5 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago