import { CodeSnippet } from '@fluentui/docs-components'; import * as React from 'react'; import { Link } from 'react-router-dom'; import { Header } from '@fluentui/react-northstar'; import DocPage from '../components/DocPage'; import { link, code } from '../utils/helpers'; import ComponentPropsTable from '../components/ComponentDoc/ComponentPropsTable'; export default () => (
Content
Overview

{code('FocusTrapZone')} grabs the focus and traps it within an HTML element. Currently can be used only in{' '} {code('Popup')} and {code('Dialog')} components. Pressing {code('TAB')} key will circle focus within the inner focusable elements of the {code('FocusTrapZone')}. The main purpose is to block user interaction outside {code('FocusTrapZone')} in any way. Therefore, keyboard events are not propagated outside {code('FocusTrapZone')}, hence {code('Popup')} or{' '} {code('Dialog')}.

Fluent UI leverages Focus Trap Zone component which is based on the{' '} {link( 'Focus Trap Zone from Fluent UI React.', 'https://developer.microsoft.com/en-us/fluentui#/controls/web/focustrapzone', )}

Usage

To apply {code('FocusTrapZone')} to {code('Popup')} set prop {code('trapFocus')} to {code('true')} with default settings or set an object with desired values for focus trap zone props.

`} />

{code('Dialog')} component has always set {code('trapFocus')} prop to {code('true')}, but it is also possible to override default settings by specifying object of {code('FocusTrapZoneProps')}.

{code('FocusTrapZone')}'s props which can be applied to {code('trapFocus')} prop ( {link( 'lookup for API on GitHub', 'https://github.com/microsoft/fluentui/blob/master/packages/fluentui/react-bindings/src/FocusZone/FocusTrapZone.types.tsx', )} ):

Override {code('FocusTrapZone')} settings

For example, we want to disable first focus on Popup mount, so we can control the initial focus by ourselves:

( )`} />

Same usage applies to {code('Dialog')} component:

( )`} />

Read more about:

  • Accessibility Behaviors
  • FocusZone
  • AutoFocusZone

{code('FocusTrapZone')} code on{' '} {link( 'GitHub.', 'https://github.com/microsoft/fluentui/blob/master/packages/fluentui/react-bindings/src/FocusZone/FocusTrapZone.tsx', )}

);