@zendeskgarden/container-focusvisible
TypeScript icon, indicating that this package has built-in type declarations

2.0.6 • Public • Published

@zendeskgarden/container-focusvisible npm version

This package includes containers relating to the :focus-visible polyfill in the Garden Design System.

Installation

npm install @zendeskgarden/container-focusvisible

Usage

Check out storybook for live examples.

useFocusVisible

import { useRef } from 'react';
import styled from 'styled-components';
import { useFocusVisible } from '@zendeskgarden/container-focusvisible';

const FocusVisibleButton = styled.button`
  :focus {
    outline: none;
  }

  /* Apply custom focus styling based on className */
  &.garden-focus-visible {
    outline: 2px dashed red;
  }

  /* Apply custom focus styling based on data attribute */
  &[data-garden-focus-visible] {
    outline: 2px dashed red;
  }
`;

const Example = () => {
  const scope = useRef();
  useFocusVisible({ scope });

  return (
    <div ref={scope}>
      <FocusVisibleButton>
        This element receives focus-visible className and data attribute
      </FocusVisibleButton>
    </div>
  );
};

FocusVisibleContainer

import { FocusVisibleContainer } from '@zendeskgarden/container-focusvisible';

const Example = () => {
  const scope = useRef();

  return (
    <FocusVisibleContainer scope={scope} className="custom-focus-visible-class">
      <div ref={scope}>
        <button>Hello world</button>
        <input placeholder="some elements always receive focus-visible" />
      </div>
    </FocusVisibleContainer>
  );
};

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.61,007latest

Version History

VersionDownloads (Last 7 Days)Published
2.0.61,007
2.0.526
2.0.4851
2.0.36,980
2.0.20
2.0.10
2.0.00
1.0.6331
1.0.5554
1.0.42
1.0.25
1.0.1549
1.0.01
0.4.10631
0.4.948
0.4.88
0.4.745
0.4.62
0.4.51
0.4.411
0.4.312
0.4.20
0.4.10
0.4.00
0.3.00
0.2.10
0.2.00
0.1.00

Package Sidebar

Install

npm i @zendeskgarden/container-focusvisible

Weekly Downloads

11,064

Version

2.0.6

License

Apache-2.0

Unpacked Size

29.5 kB

Total Files

8

Last publish

Collaborators

  • zendesk-garden