2.0.15 • Published 3 months ago

@zendeskgarden/container-focusjail v2.0.15

Weekly downloads
12,782
License
Apache-2.0
Repository
github
Last release
3 months ago

@zendeskgarden/container-focusjail npm version

This package includes containers relating to focus looping in the Garden Design System.

Installation

npm install @zendeskgarden/container-focusjail

Usage

This container implements the dialog focus loop design pattern and can be used to build a modal component. Check out storybook for live examples.

useFocusJail

The useFocusJail hook allows you to trap focus to a container element. Useful for modals and widgets. Garden uses this in react-components for the modals package.

import { useRef } from 'react';
import { useFocusJail } from '@zendeskgarden/container-focusjail';

const FocusJail = () => {
  const containerRef = useRef(null);
  const { getContainerProps } = useFocusJail({
    focusOnMount: false,
    environment: window.parent.document,
    containerRef
  });

  return (
    <>
      <input />
      <div {...getContainerProps({ ref: containerRef, tabIndex: -1 })}>
        <p>Focus is locked within the parent element</p>
        <input />
        <button>Focusable Items</button>
      </div>
    </>
  );
};

FocusJailContainer

FocusJailContainer is a render-prop wrapper for the useFocusJail hook.

import { createRef } from 'react';
import { FocusJailContainer } from '@zendeskgarden/container-focusjail';

const containerRef = createRef(null);

<FocusJailContainer
  containerRef={containerRef}
  focusOnMount={false}
  environment={window.parent.document}
>
  {({ getContainerProps }) => (
    <>
      <input />
      <div {...getContainerProps({ ref: containerRef, tabIndex: -1 })}>
        <p>Focus is locked within the parent element</p>
        <input />
        <button>Focusable Items</button>
      </div>
    </>
  )}
</FocusJailContainer>;
2.0.15

3 months ago

2.0.14

3 months ago

2.0.13

3 months ago

2.0.11

7 months ago

2.0.7

10 months ago

2.0.12

7 months ago

2.0.9

8 months ago

2.0.10

8 months ago

2.0.8

9 months ago

2.0.6

11 months ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.2

1 year ago

2.0.1

2 years ago

2.0.0

2 years ago

1.4.11

2 years ago

1.4.13

2 years ago

1.4.12

2 years ago

1.4.10

3 years ago

1.4.9

3 years ago

1.4.7

3 years ago

1.4.6

3 years ago

1.4.5

3 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.1.0

5 years ago