Skip to content

Commit

Permalink
feat(react): allow for NavBar to include additional props for html di…
Browse files Browse the repository at this point in the history
…v elements.
  • Loading branch information
scurker committed Aug 1, 2023
1 parent 27396d7 commit 581104d
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 107 deletions.
119 changes: 119 additions & 0 deletions docs/pages/components/NavBar.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
title: NavBar
description: A navigation bar that contains links to other sections of the website.
source: https://github.com/dequelabs/cauldron/tree/develop/packages/react/src/components/NavBar/NavBar.tsx
---

import { NavBar, NavItem } from '@deque/cauldron-react'

```js
import { NavBar, NavItem } from '@deque/cauldron-react'
```

The `NavBar` component is intended to be placed directly below the `TopBar` component to display an additional section of navigational links for the current area.

Under the hood, `NavBar` renders inside of a `nav` element. If there are multiple `nav` elements present on the page be sure to include `aria-label` or `aria-labelledby` to help uniquely identify each nav region.

## Examples

### Default

```jsx example
<NavBar aria-label="NavBar Example">
<NavItem>
<a href="#">One</a>
</NavItem>
<NavItem>
<a href="#">Two</a>
</NavItem>
<NavItem>
<a href="#">Three</a>
</NavItem>
</NavBar>
```

### NavBar with Active NavItem

```jsx example
<NavBar aria-label="NavBar with Active NavItem Example">
<NavItem active>
<a href="#">One</a>
</NavItem>
<NavItem>
<a href="#">Two</a>
</NavItem>
<NavItem>
<a href="#">Three</a>
</NavItem>
</NavBar>
```

### Collapsed

```jsx example
<NavBar aria-label="Collapsed NavBar Example" collapsed={true}>
<NavItem>
<a href="#">One</a>
</NavItem>
<NavItem>
<a href="#">Two</a>
</NavItem>
<NavItem>
<a href="#">Three</a>
</NavItem>
</NavBar>
```

## Props

### NavBar

<ComponentProps
children={true}
className={true}
props={[
{
name: 'collapsed',
type: 'boolean',
defaultValue: 'false',
description: 'Collapses NavBar into a toggleable hamburger menu with a flyout list of nav items.',
},
{
name: 'navTriggerLabel',
type: 'string',
description: 'Label shown in menu trigger when component is collapsed.',
defaultValue: 'MAIN MENU'
},
{
name: 'propId',
type: 'string',
description: 'ID passed to aria-controls, so assistive technology knows the trigger controls the menu.',
defaultValue: 'randomly generated with react-id-generator'
}
]}
/>

### NavItem

<ComponentProps
children={true}
className={true}
props={[
{
name: 'active',
type: 'boolean',
defaultValue: 'false',
description: 'Indicates that the current NavItem is active.',
},
{
name: 'aria-current',
type: ['page', 'step', 'location', 'boolean'],
description: 'When active, the aria-current value to mark the NavItem as.',
defaultValue: 'true'
}
]}
/>

## Related Components

- [TopBar](./TopBar)
1 change: 1 addition & 0 deletions docs/pages/components/TopBar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,4 @@ In addition to navigational items, the `MenuBar` can also contain a dropdown men
## Related Components

- [OptionsMenu](./OptionsMenu)
- [NavBar](./NavBar)
7 changes: 0 additions & 7 deletions docs/patterns/components/NavBar/index.css

This file was deleted.

98 changes: 0 additions & 98 deletions docs/patterns/components/NavBar/index.js

This file was deleted.

6 changes: 4 additions & 2 deletions packages/react/src/components/NavBar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import PropTypes from 'prop-types';
import Icon from '../Icon';
import { useId } from 'react-id-generator';

interface NavBarProps {
interface NavBarProps extends React.HTMLAttributes<HTMLDivElement> {
children: React.ReactNode;
initialActiveIndex?: number;
className?: string;
Expand All @@ -23,7 +23,8 @@ const NavBar = ({
className,
collapsed = false,
navTriggerLabel = 'MAIN MENU',
propId
propId,
...props
}: NavBarProps) => {
const navRef = useRef<HTMLElement>(null);
const triggerRef = useRef<HTMLButtonElement>(null);
Expand Down Expand Up @@ -69,6 +70,7 @@ const NavBar = ({
'NavBar--collapsed': collapsed
})}
ref={navRef}
{...props}
>
{collapsed && (
<button
Expand Down

0 comments on commit 581104d

Please sign in to comment.