NavigationRail
NavigationRail 通过 NavigationRailItem 提供纵向主要导航目标,并内置 collapsed 与 expanded 状态切换。
行尺寸
在 NavigationRail 或 NavigationRailItem 上设置 size。展开状态的行使用共享的单行尺寸比例;折叠状态的行会为图标交互目标和标签预留空间,因此小尺寸也可能达到相同的内容下限。
尺寸比例、共享的 rowSize 默认值和密度行为,详见行尺寸。
示例
默认
带链接
状态切换
参考
结构
| 元素 | 部件 | 选择器 |
|---|---|---|
<nav> | root | [data-scope="navigation-rail"][data-part="root"]鼠标左键单击复制 |
<div> | items | [data-scope="navigation-rail"][data-part="items"]鼠标左键单击复制 |
结构
| 元素 | 部件 | 选择器 |
|---|---|---|
<component> | root | [data-scope="navigation-rail-item"][data-part="root"]鼠标左键单击复制 |
<span> | indicator | [data-scope="navigation-rail-item"][data-part="indicator"]鼠标左键单击复制 |
<span> | icon-layer | [data-scope="navigation-rail-item"][data-part="icon-layer"]鼠标左键单击复制 |
<span> | icon | [data-scope="navigation-rail-item"][data-part="icon"]鼠标左键单击复制 |
<span> | label条件显示 | [data-scope="navigation-rail-item"][data-part="label"]鼠标左键单击复制 |
属性
| 名称 | 说明 | 默认值 | 控件 |
|---|---|---|---|
shape可选 | Corner style; inherits the shared shape default. M3Shape | undefined | - | - |
size可选 | Row size; inherits the nearest row size or defaults to medium. RowSize | undefined | - | - |
ariaLabel可选 | Accessible label for the navigation landmark. string | undefined | "Navigation rail" | |
disabled可选 | Disable all items inside the rail. boolean | undefined | false | |
modelValue可选 | - string | undefined | - | |
state可选 | - expandedcollapsed | "collapsed" |
事件2
| 名称 | 类型 | 说明 |
|---|---|---|
update:modelValue | [value: string | undefined] | - |
update:state | [value: "expanded" | "collapsed"] | - |
插槽3
| 名称 | 参数 | 说明 |
|---|---|---|
default | - | Navigation destinations. Usually a list of NavigationRailItem components. |
leading | - | Leading slot for other components, such as a header or a floating action button. |
trailing | - | Trailing slot for other components, such as a header or a floating action button. |
样式38
| Token | 说明 |
|---|---|
--md-navigation-rail-bottom-spaceLayout回退值 --dp(16) | Controls bottom space. |
--md-navigation-rail-collapsed-item-gapLayout回退值 --dp(4) | Controls collapsed item gap. |
--md-navigation-rail-collapsed-padding-inlineLayout回退值 0 | Controls collapsed padding inline. |
--md-navigation-rail-collapsed-top-spaceLayout回退值 --dp(44) | Controls collapsed top space. |
--md-navigation-rail-collapsed-widthLayout回退值 --dp(80) | Controls collapsed width. |
--md-navigation-rail-container-colorColor回退值 var(--md-sys-color-surface) | Controls container color. |
--md-navigation-rail-container-shapeShape回退值 var(--md-shape-docked) | Controls container shape. |
--md-navigation-rail-expanded-item-gapLayout回退值 --dp(2) | Controls expanded item gap. |
--md-navigation-rail-expanded-padding-inlineLayout回退值 --dp(8) | Controls expanded padding inline. |
--md-navigation-rail-expanded-top-spaceLayout回退值 --dp(44) | Controls expanded top space. |
--md-navigation-rail-expanded-widthLayout回退值 --dp(220) | Controls expanded width. |
--md-navigation-rail-motionMotion回退值 var(--md-easing-spatial) | Controls motion. |
--md-navigation-rail-item-active-icon-colorColor回退值 var(--md-sys-color-on-secondary-container) | Controls item active icon color. |
--md-navigation-rail-item-active-indicator-colorColor回退值 var(--md-sys-color-secondary-container) | Controls item active indicator color. |
--md-navigation-rail-item-active-label-colorColor回退值 var(--md-sys-color-secondary) | Controls item active label color. |
--md-navigation-rail-item-active-state-layer-colorState回退值 var(--md-sys-color-on-secondary-container) | Controls item active state layer color. |
--md-navigation-rail-item-collapsed-heightLayout回退值 --dp(64) | Controls item collapsed height. |
--md-navigation-rail-item-collapsed-icon-label-spaceLayout回退值 --dp(4) | Controls item collapsed icon label space. |
--md-navigation-rail-item-collapsed-indicator-heightLayout回退值 --dp(32) | Controls item collapsed indicator height. |
--md-navigation-rail-item-collapsed-indicator-widthLayout回退值 --dp(56) | Controls item collapsed indicator width. |
--md-navigation-rail-item-collapsed-padding-blockLayout回退值 --dp(6) | Controls item collapsed padding block. |
--md-navigation-rail-item-disabled-opacityDisabled回退值 0.38 | Controls item disabled opacity. |
--md-navigation-rail-item-expanded-heightLayout回退值 --dp(56) | Controls item expanded height. |
--md-navigation-rail-item-expanded-icon-label-spaceLayout回退值 --dp(8) | Controls item expanded icon label space. |
--md-navigation-rail-item-expanded-indicator-heightLayout回退值 --dp(56) | Controls item expanded indicator height. |
--md-navigation-rail-item-expanded-leading-spaceLayout回退值 --dp(16) | Controls item expanded leading space. |
--md-navigation-rail-item-expanded-trailing-spaceLayout回退值 --dp(24) | Controls item expanded trailing space. |
--md-navigation-rail-item-focus-indicator-colorFocus回退值 var(--md-sys-color-secondary) | Controls item focus indicator color. |
--md-navigation-rail-item-focus-indicator-offsetFocus回退值 var(--md-sys-state-focus-indicator-outer-offset) | Controls item focus indicator offset. |
--md-navigation-rail-item-focus-indicator-thicknessFocus回退值 var(--md-sys-state-focus-indicator-thickness) | Controls item focus indicator thickness. |
--md-navigation-rail-item-icon-sizeLayout回退值 Typography, density and icon scale (default reference: --dp(24)) | Controls item icon size. |
--md-navigation-rail-item-icon-touch-target-sizeLayout回退值 --dp(32) | Controls item icon touch target size. |
--md-navigation-rail-item-inactive-icon-colorColor回退值 var(--md-sys-color-on-surface-variant) | Controls item inactive icon color. |
--md-navigation-rail-item-inactive-label-colorColor回退值 var(--md-sys-color-on-surface-variant) | Controls item inactive label color. |
--md-navigation-rail-item-inactive-state-layer-colorState回退值 var(--md-sys-color-on-surface-variant) | Controls item inactive state layer color. |
--md-navigation-rail-item-indicator-collapsed-visual-widthLayout回退值 --dp(12) | Controls item indicator collapsed visual width. |
--md-navigation-rail-item-indicator-shapeShape回退值 var(--md-shape-indicator) | Controls item indicator shape. |
--md-navigation-rail-item-motionMotion回退值 var(--md-easing-spatial) | Controls item motion. |
NavigationRailItem
属性
| 名称 | 说明 | 默认值 |
|---|---|---|
shape可选 | Corner style; inherits the shared shape default. M3Shape | undefined | - |
size可选 | Row size; inherits the nearest row size or defaults to medium. RowSize | undefined | - |
value可选 | Destination value used by NavigationRail v-model. string | undefined | undefined |
icon可选 | Default icon name (Material Symbols Outlined). string | undefined | undefined |
label可选 | Fallback label text when default slot is not provided. string | undefined | undefined |
href可选 | Optional href. When provided, the item renders as an anchor. string | undefined | undefined |
disabled可选 | Disable interaction. boolean | undefined | false |
selected可选 | Force selected state when not controlled by NavigationRail. boolean | undefined | undefined |
ariaLabel可选 | Accessible label. Useful when label text is omitted visually. string | undefined | undefined |
插槽2
| 名称 | 参数 | 说明 |
|---|---|---|
default | - | Label content. |
icon | - | Icon content. |