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

{code('FocusZone')} provides arrow key navigation between component's child items, in such components as {code('Menu')}, {code('List')}, {code('Toolbar')} and {code('Grid')}. At the same time it is possible to navigate between these components by using {code('TAB')} key.

Tabbable elements (buttons, anchors, etc., elements with {code('tabindex="0"')} or {code('data-is-focusable="true"')} attributes) are considered when pressing directional arrow keys and focus is moved appropriately. Tabbing to a zone sets focus only to the current "active" element, making it simple to use the {code('TAB')} key to transition from one zone to the next (from e.g., {code('TAB')} from Menu to List), rather than through every focusable element.

{code('FocusZone')} operates based on DOM structure to:

Fluent UI leverages {code('FocusZone')} component which is based on the{' '} {link( 'Focus Zone from Fluent UI React.', 'https://developer.microsoft.com/en-us/fluentui#/controls/web/focuszone', )}{' '} The Focus Zone can wrap any component / element and adds arrow key navigation functionality.

Usage
In Fluent UI, Focus Zone is assigned to components through accessibility behaviors ({ //... focusZone: { mode: FocusZoneMode.Embed, props: { //... }, }, }) `} /> and then accessibility behavior is set for component ( )`} /> Read more about Accessibility Behaviors.

The accessibility behavior can control the focus zone operation by specifying Focus zone's properties -{' '} mode and props.

Mode

Type: {code('FocusZoneMode')}, with 2 main options:

`} />
  • Wrap - Focus Zone wraps component to it's own container and all attributes/events listeners applied there. ---> FocusZone's attributes/events listeners applied here `} />
  • Props

    The following props can be applied ( {link( 'lookup for API on GitHub', 'https://github.com/microsoft/fluentui/blob/master/packages/fluentui/react-bindings/src/FocusZone/FocusZone.types.ts', )} ):

    Override {code('FocusZone')} settings

    To be able to add/override Focus Zone settings already set for a component, it is needed to override or create a new accessibility behavior.

    For example, we want to specify default tabbable element for Menu to be the last one, not first.

    { const behavior = menuBehavior(props) behavior.focusZone.props.defaultTabbableElement = (root: HTMLElement): HTMLElement => { return root.querySelector(".ui-menu__item__wrapper:last-child") } return behavior } `} /> And then use this new behavior by Menu component: ( )`} />

    Read more about:

    • Accessibility Behaviors
    • FocusTrapZone
    • AutoFocusZone

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

    );