Category: Navigation

  • Navigator

    Navigator

    import { Navigator } from '@wordpress/components';
    

    View on Storybook

    View source on GitHub

    Examples

    Default

    const Default = () => <Navigator initialPath="/">(<>
            <Navigator.Screen path="/">
                <h2>This is the home screen.</h2>
    
                <VStack alignment="left">
                    <Navigator.Button variant="primary" path="/child">
                        Go to child screen.
                    </Navigator.Button>
    
                    <Navigator.Button variant="primary" path="/product/1">
                        Go to dynamic path screen with id 1.
                    </Navigator.Button>
    
                    <Navigator.Button variant="primary" path="/product/2">
                        Go to dynamic path screen with id 2.
                    </Navigator.Button>
                </VStack>
            </Navigator.Screen>
            <Navigator.Screen path="/child">
                <h2>This is the child screen.</h2>
                <HStack spacing={ 2 } alignment="left">
                    <Navigator.BackButton variant="secondary">
                        Go back
                    </Navigator.BackButton>
    
                    <Navigator.Button
                        variant="primary"
                        path="/child/grandchild"
                    >
                        Go to grand child screen.
                    </Navigator.Button>
                </HStack>
            </Navigator.Screen>
            <Navigator.Screen path="/child/grandchild">
                <h2>This is the grand child screen.</h2>
                <Navigator.BackButton variant="secondary">
                    Go back
                </Navigator.BackButton>
            </Navigator.Screen>
            <Navigator.Screen path="/product/:id">
                <DynamicScreen />
            </Navigator.Screen>
        </>)</Navigator>;
    

    With Nested Initial Path

    const WithNestedInitialPath = () => <Navigator initialPath="/child/grandchild" />;
    

    Skip Focus

    const SkipFocus = () => <Navigator initialPath="/">(<>
            <div
                style={ {
                    height: 150,
                    outline: '1px solid black',
                    outlineOffset: '-1px',
                    marginBlockEnd: '1rem',
                    display: 'contents',
                } }
            >
                <Navigator.Screen path="/">
                    <h2>Home screen</h2>
                    <Navigator.Button variant="primary" path="/child">
                        Go to child screen.
                    </Navigator.Button>
                </Navigator.Screen>
    
                <Navigator.Screen path="/child">
                    <h2>Child screen</h2>
                    <Navigator.BackButton variant="secondary">
                        Go back to home screen
                    </Navigator.BackButton>
                </Navigator.Screen>
            </div>
            <NavigatorButtonWithSkipFocus path="/child">
                Go to child screen, but keep focus on this button
            </NavigatorButtonWithSkipFocus>
        </>)</Navigator>;
    
  • TreeGrid

    TreeGrid

    TreeGrid is used to create a tree hierarchy. It is not a visually styled component, but instead helps with adding keyboard navigation and roving tab index behaviors to tree grid structures.

    A tree grid is a hierarchical 2 dimensional UI component, for example it could be used to implement a file system browser.

    A tree grid allows the user to navigate using arrow keys. Up/down to navigate vertically across rows, and left/right to navigate horizontally between focusables in a row.

    The TreeGrid renders both a table and tbody element, and is intended to be used with TreeGridRow (tr) and TreeGridCell (td) to build out a grid.

    See: https://www.w3.org/TR/wai-aria-practices/examples/treegrid/treegrid-1.html

    import { __experimentalTreeGrid as TreeGrid } from '@wordpress/components';
    

    View on Storybook

    View in Figma

    View source on GitHub

    Props

    NameDefaultDescription
    onExpandRow() => {}

    unknown

    onCollapseRow() => {}

    unknown

    onFocusRow() => {}

    unknown

    Examples

    Default

    const Default = () => <TreeGrid onExpandRow={fn()} onCollapseRow={fn()} onFocusRow={fn()}><Rows items={ groceries } /></TreeGrid>;