Navigation · Navigation
Navigation
A menu list that provides navigation for pages and features.
Demos
How to import
Basic Usage
By passing
items
Parameters, you can quickly get a navigation bar.Each navigation item includes:
itemKey
: The unique identity of the navigation project (must)text
: Navigation copywritingicon
: Navigation icon
Navigation Indentation
Version: >= 0.16.0
Navigation indentation is currently effective only for first-level navigation.
Pure Copywriting Navigation
If the navigation project doesn't come in,
icon
field, then the copy will be automatically filled to the left.Define The Head And Bottom
Developers may often define the Logo area and the put away button area, while Navigation provides such a container for developers to quickly define the navigation head and bottom, and you only need to pass in the header or Footer as required.
For
footer
, semi-ui extra encapsulates a pull-up feature button that developers can pass through collapseButton = true
to turn on the function, but the parameter takes effect only with mode = "vertical"
(Vertical navigation).For the parameters, see Nav.Header and Nav.Footer.
Navigation Style Definition
Navigation currently provides two parameters to define navigation styles:
style
and bodyStyle
, in which style
The style used to define the outermost layer of the navigation component, while bodyStyle
The style used to define the navigation list. (Both the navigation head and the bottom of the navigation accept their respective style
Parameters).For example, you need a navigation list to scroll, navigate the head and bottom fixed navigation components, which can be used this way:
JSX Writing
Users can use JSX to define navigation headers, navigation items, and navigation bottoms.
Use react-router like router lib
In order to use routing components such as react-router, NavItem can be wrapped in the Link or NavLink provided by the routing component to let users click NavItem to trigger the routing component. We need to customize rendering.
Use renderWrapper to customize navigation components in each navigation item. See CodeSandBox demo
Navigation Direction
Navigation currently offers navigation in two directions:
- Vertical (default)
- Horizontal
You can pass
mode = "vertical"
(default) or mode = "horizontal"
to control.In particular, there are some functions (parameters) only in
mode = "vertical"
effective:isCollapsed
(Navigation put away to the side)defaultOpenKeys
|openKeys
(Specifies the default and controlled array of expanded subnavigation items key, which is valid only inmode = "vertical"
andisCollapsed = false
)collapseButton
ofFooter
Vertical Direction
Horizontal Direction
Horizontal Plus Vertical
The general platform design will adopt the mode of horizontal and vertical navigation. Here is a common example.
Expand and collapse arrow position
toggleIconPosition
set 'left' or 'right', default rightIndentation limit
No indentation by default. If you need to indent the navigation items according to the level, please set limitIndent to false
When using Nav.Item to pass navigation items in React Jsx mode, please pass level props to Nav.Item manually.
Object method No need to care about level when passing in navigation items.
limitIndent only takes effect in the vertical direction.
Uncontrolled Properties
Including:
defaultSelectedKeys
(default selected navigation itemkey
array)defaultOpenKeys
(default expanded navigation itemkey
array, valid only withmode = "vertical"
andisCollapsed = false
|defaultIsCollapsed = false
)defaultIsCollapsed
(whether the sidebar is closed by default, valid only whenmode = "vertical"
)
Controlled Properties
The Navigation component provides several controlled properties that, combined with a variety of callbacks, can easily control navigation.
The properties currently controlled are:
isCollapsed
(whether the sidebar is closed, effective only whenmode="vertical"
)selectedKeys
(currently selected navigation itemkey
array)openKeys
(currently expanded array of navigation items, onlymode="vertical"
andisCollapsed=false
valid)
The corresponding callback is:
onCollapseChange(isCollapsed: boolean) => void
onSelect ({ itemKey: string, selectedKeys: string[], domEvent: MouseEvent, isOpen: boolean }) => void
onOpenChange ({ itemKey: string, openKeys: string[], domEvent: MouseEvent, isOpen: boolean }) => void
API Reference
Nav
Properties | Type | Description | Default |
---|---|---|---|
bodyStyle | Custom style for navigation item list | object | |
className | Style name of outermost element | boolean | |
defaultIsCollapsed | Whether the default is put away, valid only when mode = "vertical" | boolean | false |
defaultOpenKeys | Initially open sub navigation itemKey array, valid only mode = "vertical" and the sidebar is in an expanded state | string[] | [] |
defaultSelectedKeys | Originally selected navigation item itemKey array | string[] | [] |
expandIcon | Default Arrow Icon | ReactNode | |
footer | The bottom area configure objects or elements, see Nav.Footer | object|ReactNode | |
getPopupContainer | Dropdown's getPopupContainer config of vertical collapsed Nav or horizontal Nav. >= v2.24 | Function | |
header | Head area configuration objects or elements, see Nav.Header | object|ReactNode | |
isCollapsed | A controlled attribute of whether it is in a put-away state, valid only when mode = "vertical" | boolean | |
items | Navigate the list of items, each item can continue with the items property. If it is a string array, each item is taken as text and itemKey | object|string[]|Item[]|Sub[] | |
mode | Navigation type, currently supports horizontal and vertical, optional value: vertical \ | horizontal | string |
onClick | Trigger when clicking on any navigation item | (itemKey, event, isOpen) => void | () = > {} |
onCollapseChange | The callback when the state changes. | (isCollapsed) => void | () = > {} |
onOpenChange | Triggers when switching the hidden state of a sub navigation project | ({itemKey, openKeys, event, isOpen}) => void | () = > {} |
onSelect | Triggers the first time you select an optional navigation project, where the selected Items field version > = 0.17.0 is supported | (onSelectProps) => void | () = > {} |
openKeys | Controlled open sub navigation itemKey array, expanded with onOpenChange callback control sub navigation items, valid only mode = "vertical" and the sidebar is in an unfolding state | string[] | |
renderWrapper | Custom navigation item outer component >=2.24.0 | (data) => ReactNode | |
prefixCls | classsname prefix | string | semi |
selectedKeys | Controlled navigation item itemKey array, with onSelect callback control navigation item selection | string[] | |
style | Custom styles for outermost elements | object | |
subNavCloseDelay | Delay of sub navigation floating layer closure. Effective when the limit is true or mode is "limit" in MS | number | 100 |
subNavOpenDelay | The delay displayed by the sub navigation floating layer. Effective when the input is true or mode is "selected" in MS | number | 0 |
tooltipHideDelay | The latency hidden by tooltip is valid when it is true in MS | number | 100 |
tooltipShowDelay | The delay displayed by tooltip is valid when it is true in MS | number | 0 |
limitIndent | To lift the indentation limit, you can use level to customize the indentation of navigation items. The horizontal mode can only be true >=1.27.0 | boolean | true |
toggleIconPosition | Parent navigation item arrow position with child navigation items >=1.27.0 | 'left' | 'right' | 'right' |
Nav.Item
Properties | Description | Type | Default | |
---|---|---|---|---|
disabled | Disabled state | boolean | false | |
icon | Navigation project icon name or component | ReactNode | ||
indent | If the icon is empty, keep its space or not. Only effective for first level navigation | boolean | false | |
itemKey | Unique item identifier, no duplication allowed | string | "" | |
level | The nesting level of the current item. When limitIndent is true, it is used to customize the indentation position | number | ||
link | Navigation item href link, when imported, the navigation item will be wrapped with an a tag | string | - | |
linkOptions | Parameters transparently passed to the a tag | object | - | |
text | Navigation project copy or element | string | ReactNode | "" | |
onClick | Callback of click | function({ itemKey: string, domEvent: MouseEvent, isOpen: boolean }) | () => {} | |
onMouseEnter | Callback of mouse enter event | function(e) => {} | () => {} | |
onMouseLeave | Callback of mouse leave event | function(e) => {} | () => {} |
Nav.Sub
Properties | Description | Type | Default |
---|---|---|---|
disabled | Disabled state | boolean | false |
dropdownStyle | Style of dropdown layer | CSSProperties | |
icon | Navigation project icon name or component | ReactNode | |
indent | If the icon is empty, keep its space or not. Only effective for first level navigation | boolean | false |
isCollapsed | Whether it is a controlled attribute in the collapsed state, only mode = "vertical" | boolean | false |
isOpen | Control open state | boolean | false |
itemKey | Navigation project only key | string | "" |
level | The nesting level of the current item. When limitIndent is true, it is used to customize the indentation position | number | |
maxHeight | max height | number | 999 |
text | Navigation project copy or component | string | ReactNode | "" |
onMouseEnter | Callback of mouse enter event | function(e) => {} | () => {} |
onMouseLeave | Callback of mouse leave event | function(e) => {} | () => {} |
Nav.Header
Properties | Description | Type | Default | Version |
---|---|---|---|---|
children | Sub element | ReactNode | ||
className | Outermost style name | string | ||
link | Navigation item href link, when imported, the navigation item will be wrapped with an a tag | string | - | |
linkOptions | Parameters transparently passed to the a tag | object | - | |
logo | Logo, can be a string or component | string | ReactNode | ||
style | Outermost style | object | ||
text | Logo copy, which can be a string or component | string | ReactNode |
Nav.Footer
Properties | Description | Type | Default | Version |
---|---|---|---|---|
children | Sub element | ReactNode | ||
className | Outermost style name | string | ||
collapseButton | Whether to display the bottom "collapse sidebar" button, only work when mode="vertical" and the children parameter of the Footer component is empty | boolean|ReactNode | false | |
collapseText | Title of the collapse button | (collapsed:boolean) => string|ReactNode | 0.35.0 | |
style | Outermost style | object | ||
onClick | Click callback | (event) => void |
Accessibility
Keyboard and Focus
- Each clickable item in the Navigation can be focused, use
Tab
andShift + Tab
to switch focus between each other, and each link can be activated by theEnter
key - When an item can be opened popup
- The way to open the popup layer is hover : when the item is focused, the popup layer opens. Keyboard users can use the down arrow to move the focus to the bullet layer, and the Esc key can return the focus to the item
- The way to open the popup layer is click : when the item is focused, click the Enter key to open the popup layer. Keyboard users can use the down arrow to move the focus to the bullet layer, and the Esc key can return the focus to the item -Keyboard interaction does not fully support nested scenes
Content Guidelines
- Navigation bar menu uses sentence case format
- Keep it as simple as possible
Design Tokens
FAQ
- Lost animation in navigation bar?When using functional components, you should give items with useState or useMemo, because passing an array directly to items will trigger component rerendering.
- Lost item when subNav is too height >=999px ? Please refer to this issue