Splitter
可调整大小的面板:大小、限制、折叠和嵌套区域。
何时使用
Splitter将工作区域划分为多个面板,用户可以更改面板的大小。适用于编辑器、预览和详细信息区域。容器需要一定的尺寸:垂直组合必须具有可触及的高度。
在 Splitter 内使用 Splitter.Panel 声明面板,也可以传入包含 children 片段的 items 数组。传入数组时优先使用数组。面板按位置识别。
面板尺寸
size、defaultSize、min 和 max 接受以 px 为单位的数字或百分比字符串。未指定的剩余部分在面板之间分配。 defaultSize 在创建时读取;进一步的改变可以通过 size 来控制。
| 问题 | 设置 | 示例 |
|---|---|---|
| 分割禁区 | Splitter.Panel、min、max |
两个有限制的面板 |
| 在应用程序中存储尺寸 | size、onResize |
托管维度 |
| 从上到下分割区域 | orientation="vertical" |
垂直划分 |
| 创建多个级别 | 嵌套 Splitter |
嵌套区域 |
| 发布后应用尺寸 | lazy、onResizeEnd |
延迟调整大小 |
如果至少一个面板具有 size,则整个组就变得易于管理。接受回调中建议的数字并更新相应 items 的尺寸。保持相同的 size 可以让你拒绝改变;对于外部复位,可以再次传输百分比值。
resizable=false 防止更改相邻边框,而不是隐藏面板。对于拖动,两个相邻面板都必须允许调整大小。orientation 优先于 vertical。
更改和折叠
常规拖动报告 onResizeStart,中间拖动报告 onResize 和 onResizeEnd。 lazy 显示初步行并在完成后应用结果;通过 onResizeEnd 保存大小,因为中间的 onResize 没有被调用。
collapsible 面板允许在 start/end 时折叠并设置按钮的可见性。一般 collapsible.motion 包括动画、icon 变化图标。 onCollapse 报告更改事件后的一系列折叠状态和大小。
onDraggerDoubleClick 获取边框索引。 重置示例 本身会恢复应用程序中的大小;回调不会自动替换状态。
destroyOnHidden 默认为 false:如果 size 为零,则内容存储在 DOM 中。这保留了本地状态,但隐藏字段可能仍保持 Tab 键顺序 - 这一限制也在基准测试中重现。 隐藏内容示例 使用 true。将重要值保留在被删除的面板之外;面板的本地 destroyOnHidden 优先于全局销毁。
设计和可用性
classNames/styles 支持 root、panel 和拖动器对象或道具中的函数。styles 接受 CSS 字符串和对象。 classNames.dragger.active 在拖动过程中使用,styles.dragger.active 尚未使用。 语义示例 显示当前设置和 ConfigProvider.splitter。
theme.components.Splitter 将 splitBarSize、splitTriggerSize 和 splitBarDraggableSize 应用于边框和捕获区域。当地风格完善了设计。 draggerIcon 更改图标,null/false 留下空的自定义包装器而不是标准内容。
边界具有 role=separator、方向和百分比 aria-valuenow/min/max。拖动支持鼠标和触摸;使用箭头调整大小尚未实现。可通过键盘访问折叠按钮。它们的名字在当前包中是固定的; 6.7 文档中通过 aria-label 自定义 icon 进行的覆盖尚未延续。
bind:nativeElement 在挂载后返回根 div。要更改面板的组成,请考虑 items 的位置标识并将编辑器数据存储在应用程序状态中。
非空本地 prefixCls 更改根、面板、分隔符、折叠按钮、preview 和遮罩的类。空字符串和 undefined 继承ConfigProvider.prefixCls,带有 -splitter 后缀,默认为 ant-splitter。语义回调接收 prefixCls 的初始本地值。 前缀示例 包含具有一个本地类的嵌套区域、单独的 lazy preview 以及保存尺寸和编辑器。
预览服务变量使用不带点的通用前缀:--suite-splitter-bar-preview-offset。本地 class 和 theme.cssVar.prefix 对其没有影响。 CSS 由类/命名空间对隔离,因此嵌套作用域不会读取彼此的偏移量。 CSS 注册顺序依赖性未在参考中重现。更改前缀会保留活动的拖动、面板及其内容; destroyOnHidden 继续单独控制折叠内容的删除。
Splitter 的外观使用当前主题的设计令牌(design tokens)。
示例
两个有限制的面板
使用 Splitter.Panel 在 Splitter 内声明面板。数字表示像素,百分比字符串表示可用空间的比例。min 和 max 限制拖动范围。
<script lang="ts">
import { Splitter } from '@woodger/antd';
let result = $state(("拖动分隔符"));
</script>
<style>
.surface {
height: 220px;
overflow: hidden;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
}
.pane {
display: grid;
height: 100%;
min-width: 0;
box-sizing: border-box;
align-content: center;
padding: 12px;
overflow-wrap: anywhere;
background: var(--ant-color-fill-quaternary);
}
output {
display: block;
margin-top: 16px;
overflow-wrap: anywhere;
}
</style>
<div class="surface">
<Splitter onResizeEnd={next => { result = next.map(Math.round).join(' / ') + ' px'; }}>
<Splitter.Panel defaultSize="40%" min="20%" max="80%">
<div class="pane">{("第一个面板")}</div>
</Splitter.Panel>
<Splitter.Panel min="20%">
<div class="pane">{("第二个面板")}</div>
</Splitter.Panel>
</Splitter>
</div>
<output aria-label={("更换分路器的结果")}>{result}</output>
托管维度
如果至少指定了一个面板的 size,应用程序将在 onResize 中获取尺寸。禁止接受留下了以前的几何形状。
<script lang="ts">
import { Button, Splitter, type SplitterSize } from '@woodger/antd';
let sizes = $state<SplitterSize[]>(['50%', '50%']);
let frozen = $state(false);
function resize(next: number[]) {
if (!frozen) sizes = next;
}
</script>
<style>
.surface {
height: 220px;
overflow: hidden;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
}
.pane {
display: grid;
height: 100%;
min-width: 0;
box-sizing: border-box;
align-content: center;
padding: 12px;
overflow-wrap: anywhere;
background: var(--ant-color-fill-quaternary);
}
.controls {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
label {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
}
output {
display: block;
margin-top: 16px;
overflow-wrap: anywhere;
}
</style>
{#snippet first()}<div class="pane">{("第一个面板")}</div>{/snippet}
{#snippet second()}<div class="pane">{("第二个面板")}</div>{/snippet}
<div class="controls"><label><input type="checkbox" bind:checked={frozen} />{(" 不接受更改")}</label><Button onclick={() => {
sizes = [
'50%',
'50%'
];
}}>{("重置尺寸")}</Button></div>
<div class="surface"><Splitter items={([{
children: first,
size: sizes[0],
min: '20%'
}, { children: second, size: sizes[1], min: '20%' }])} onResize={resize} /></div>
<output aria-label={("可接受的分路器尺寸")}>{sizes.map(
value => typeof value === 'number' ? Math.round(value) + 'px' : value
).join(' / ')}</output>
垂直划分
orientation="vertical" 将面板从上到下放置。分隔符本身的 ARIA 方向变为水平。
<script lang="ts">
import { Splitter } from '@woodger/antd';
</script>
<style>
.surface {
height: 220px;
overflow: hidden;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
}
.pane {
display: grid;
height: 100%;
min-width: 0;
box-sizing: border-box;
align-content: center;
padding: 12px;
overflow-wrap: anywhere;
background: var(--ant-color-fill-quaternary);
}
</style>
{#snippet first()}<div class="pane">{("第一个面板")}</div>{/snippet}
{#snippet second()}<div class="pane">{("第二个面板")}</div>{/snippet}
<div class="surface"><Splitter orientation="vertical" items={([{
children: first,
defaultSize: '40%',
min: '20%'
}, { children: second, min: '20%' }])} /></div>
折叠面板
collapsible 包括分隔板上的按钮。 onCollapse 报告一系列状态和建议的大小。
<script lang="ts">
import { Splitter } from '@woodger/antd';
let result = $state(("面板打开"));
</script>
<style>
.surface {
height: 220px;
overflow: hidden;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
}
.pane {
display: grid;
height: 100%;
min-width: 0;
box-sizing: border-box;
align-content: center;
padding: 12px;
overflow-wrap: anywhere;
background: var(--ant-color-fill-quaternary);
}
output {
display: block;
margin-top: 16px;
overflow-wrap: anywhere;
}
</style>
{#snippet first()}<div class="pane">{("第一个面板")}</div>{/snippet}
{#snippet second()}<div class="pane">{("第二个面板")}</div>{/snippet}
<div class="surface"><Splitter collapsible={{ motion: true }} items={([{
children: first,
collapsible: true
}, { children: second, collapsible: true }])} onCollapse={(
collapsed,
sizes
) => {
result = collapsed.map((
value,
index
) => `${index + 1}: ${value ? "隐" : "可见的"} (${Math.round(
sizes[index]
)}px)`).join(', ');
}} /></div>
<output aria-label={("折叠分离器")}>{result}</output>
折叠按钮的可见性
showCollapsibleIcon 接受 true、false 或 auto。这是按钮的可见性,而不是面板的状态。
<script lang="ts">
import { Splitter, type SplitterIconVisibility } from '@woodger/antd';
let visibility = $state<SplitterIconVisibility>('auto');
</script>
<style>
.surface {
height: 220px;
overflow: hidden;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
}
.pane {
display: grid;
height: 100%;
min-width: 0;
box-sizing: border-box;
align-content: center;
padding: 12px;
overflow-wrap: anywhere;
background: var(--ant-color-fill-quaternary);
}
.controls {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
label {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
}
</style>
{#snippet first()}<div class="pane">{("第一个面板")}</div>{/snippet}
{#snippet second()}<div class="pane">{("第二个面板")}</div>{/snippet}
<div
class="controls"
>
<label>{("折叠按钮 ")}<select
bind:value={visibility}
>
<option
value="auto"
>
{("悬停时")}
</option>
<option value={true}>
{("总是")}
</option>
<option value={false}>
{("隐藏")}
</option>
</select></label>
</div>
<div class="surface"><Splitter items={([{
children: first, collapsible: {
start: true,
end: true,
showCollapsibleIcon: visibility
}
}, { children: second, collapsible: true }])} /></div>
多个面板
每对邻居之间都会出现一个分隔符。 resizable=false 面板禁止更改两个相邻边框。
<script lang="ts">
import { Splitter } from '@woodger/antd';
</script>
<style>
.surface {
height: 220px;
overflow: hidden;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
}
.pane {
display: grid;
height: 100%;
min-width: 0;
box-sizing: border-box;
align-content: center;
padding: 12px;
overflow-wrap: anywhere;
background: var(--ant-color-fill-quaternary);
}
</style>
{#snippet first()}<div class="pane">{("第一个面板")}</div>{/snippet}
{#snippet second()}<div class="pane">{("第二个面板")}</div>{/snippet}
{#snippet third()}<div class="pane">{("第三面板")}</div>{/snippet}
<div class="surface"><Splitter items={([{
children: first,
defaultSize: '30%',
min: '15%'
}, { children: second, defaultSize: '40%', min: '15%' }, { children: third, min: '15%' }])} /></div>
嵌套区域
水平分离器与第二面板中的垂直分离器组合。每个容器管理自己的维度。
<script lang="ts">
import { Splitter } from '@woodger/antd';
</script>
<style>
.surface {
height: 220px;
overflow: hidden;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
}
.pane {
display: grid;
height: 100%;
min-width: 0;
box-sizing: border-box;
align-content: center;
padding: 12px;
overflow-wrap: anywhere;
background: var(--ant-color-fill-quaternary);
}
</style>
{#snippet first()}<div class="pane">{("第一个面板")}</div>{/snippet}
{#snippet second()}<div class="pane">{("第二个面板")}</div>{/snippet}
{#snippet third()}<div class="pane">{("第三面板")}</div>{/snippet}
{#snippet nested()}<Splitter orientation="vertical" items={([{
children: second,
min: '20%'
}, { children: third, min: '20%' }])} />{/snippet}
<div class="surface"><Splitter items={([{ children: first, min: '20%' }, {
children: nested,
min: '20%'
}])} /></div>
延迟调整大小
lazy 显示介词行。释放时几何体和 onResizeEnd 更新;在此模式下不会调用 onResize。
<script lang="ts">
import { Splitter } from '@woodger/antd';
let result = $state(("尺寸还没变"));
</script>
<style>
.surface {
height: 220px;
overflow: hidden;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
}
.pane {
display: grid;
height: 100%;
min-width: 0;
box-sizing: border-box;
align-content: center;
padding: 12px;
overflow-wrap: anywhere;
background: var(--ant-color-fill-quaternary);
}
output {
display: block;
margin-top: 16px;
overflow-wrap: anywhere;
}
</style>
{#snippet first()}<div class="pane">{("第一个面板")}</div>{/snippet}
{#snippet second()}<div class="pane">{("第二个面板")}</div>{/snippet}
<div class="surface"><Splitter lazy items={([{
children: first,
defaultSize: '40%',
min: '20%'
}, { children: second, min: '20%' }])} onResizeEnd={next => {
result = next.map(
Math.round
).join(' / ') + ' px';
}} /></div>
<output aria-label={("延迟维度分割器")}>{result}</output>
自定义图标
draggerIcon 和 collapsible.icon 接受字符串或片段。当前包的按钮名称仍然是标准的切换 start/end 面板。
<script lang="ts">
import { Splitter } from '@woodger/antd';
</script>
<style>
.surface {
height: 220px;
overflow: hidden;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
}
.pane {
display: grid;
height: 100%;
min-width: 0;
box-sizing: border-box;
align-content: center;
padding: 12px;
overflow-wrap: anywhere;
background: var(--ant-color-fill-quaternary);
}
</style>
{#snippet first()}<div class="pane">{("第一个面板")}</div>{/snippet}
{#snippet second()}<div class="pane">{("第二个面板")}</div>{/snippet}
{#snippet handle()}<span aria-hidden="true">⋮</span>{/snippet}
{#snippet startIcon()}<span aria-hidden="true">−</span>{/snippet}
{#snippet endIcon()}<span aria-hidden="true">+</span>{/snippet}
<div class="surface"><Splitter draggerIcon={handle} collapsible={{
icon: {
start: startIcon,
end: endIcon
}
}} items={([
{
children: first,
collapsible: true
},
{ children: second, collapsible: true }
])} /></div>
语义槽和提供者
root、panel 和拖动器是分开设计的。 ConfigProvider.splitter 设置通用样式,局部函数对其进行细化。
<script lang="ts">
import { ConfigProvider, Splitter } from '@woodger/antd';
</script>
<style>
.surface {
height: 220px;
overflow: hidden;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
}
.pane {
display: grid;
height: 100%;
min-width: 0;
box-sizing: border-box;
align-content: center;
padding: 12px;
overflow-wrap: anywhere;
background: transparent;
}
</style>
{#snippet first()}<div class="pane">{("第一个面板")}</div>{/snippet}
{#snippet second()}<div class="pane">{("第二个面板")}</div>{/snippet}
<ConfigProvider splitter={{
styles: {
root: 'border-radius:8px',
panel: 'background:var(--ant-color-primary-bg)'
}
}}>
<div class="surface"><Splitter classNames={{ panel: 'custom-split-panel' }} styles={(
{ props }
) => ({
dragger: {
default: `background:${props.orientation === 'horizontal' ? '#722ed1' : '#08979c'}`
}
})} items={([{ children: first }, { children: second }])} /></div>
</ConfigProvider>
双击重置
onDraggerDoubleClick 报告边框的索引。应用程序将管理的大小返回为均等份额。
<script lang="ts">
import { Splitter, type SplitterSize } from '@woodger/antd';
let sizes = $state<SplitterSize[]>(['30%', '70%']);
let resets = $state(0);
function reset() {
sizes = ['50%', '50%'];
resets += 1;
}
</script>
<style>
.surface {
height: 220px;
overflow: hidden;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
}
.pane {
display: grid;
height: 100%;
min-width: 0;
box-sizing: border-box;
align-content: center;
padding: 12px;
overflow-wrap: anywhere;
background: var(--ant-color-fill-quaternary);
}
output {
display: block;
margin-top: 16px;
overflow-wrap: anywhere;
}
</style>
{#snippet first()}<div class="pane">{("第一个面板")}</div>{/snippet}
{#snippet second()}<div class="pane">{("第二个面板")}</div>{/snippet}
<div class="surface"><Splitter items={([{
children: first,
size: sizes[0],
min: '20%'
}, { children: second, size: sizes[1], min: '20%' }])} onResize={next => {
sizes = next;
}} onDraggerDoubleClick={reset} /></div>
<output aria-label={("分配器重置")}>{resets}</output>
两个 Splitter 在不同的范围内使用相同的本地类。延迟调整大小及其预览保持独立;草稿存储在正在删除的面板之外。
本地和共享前缀
具有一类的嵌套区域、独立的 lazy preview 以及保存尺寸和编辑器。
<script lang="ts">
import { Checkbox, ConfigProvider, Input, Splitter } from '@woodger/antd';
let custom = $state(true);
let local = $state(true);
let draft = $state('');
let collapsed = $state(false);
let sizes = $state(("调整大小后"));
let innerSizes = $state(("调整大小后"));
const prefix = $derived(custom ? 'suite' : 'ant');
</script>
<style>
.example {
display: grid;
gap: 20px;
min-width: 0;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.surface {
height: 240px;
min-width: 0;
overflow: hidden;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
}
.pane {
display: grid;
box-sizing: border-box;
height: 100%;
min-width: 0;
align-content: start;
gap: 8px;
padding: 12px;
background: var(--ant-color-fill-quaternary);
overflow-wrap: anywhere;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
{#snippet editor()}
<div class="pane">
<span>{("编辑")}</span>
<Input bind:value={draft} aria-label={("带前缀的分离草稿")} />
</div>
{/snippet}
{#snippet nested()}
<ConfigProvider prefixCls="neighbor" style="height: 100%">
<Splitter class="prefix-splitter-inner" prefixCls={local ? 'project-splitter' : ''}
orientation="vertical" lazy items={([
{ children: "嵌套面板 1", defaultSize: '50%', min: '10%' },
{ children: "嵌套面板 2", min: '10%' }
])} onResizeEnd={next => { innerSizes = next.map(Math.round).join(' / ') + ' px'; }} />
</ConfigProvider>
{/snippet}
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("通用前缀 Splitter 套件")}</Checkbox>
<Checkbox bind:checked={local}>{("本地前缀分割器")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} theme={{ cssVar: { prefix: 'splitter-theme' } }}>
<div class="surface">
<Splitter class="prefix-splitter-main" prefixCls={local ? 'project-splitter' : ''}
lazy destroyOnHidden collapsible={{ motion: false }} items={([
{
children: editor, defaultSize: '45%', min: '20%', max: '80%',
collapsible: { start: true, end: true, showCollapsibleIcon: true }
},
{
children: nested, min: '20%',
collapsible: { start: true, end: true, showCollapsibleIcon: true }
}
])} onResizeEnd={next => { sizes = next.map(Math.round).join(' / ') + ' px'; }}
onCollapse={next => { collapsed = next[0]; }} />
</div>
</ConfigProvider>
<output
aria-label={("前缀分割器")}
>{("\n 一般的: ")}{prefix}{(";班级: ")}{(local ? 'project-splitter' : prefix + '-splitter')};
{(collapsed ? "编辑器已最小化" : "编辑透露")}{(";方面: ")}{sizes}
</output>
<output aria-label={("带前缀的嵌套调整大小")}>{innerSizes}</output>
<p>
{("两个 Splitter 在不同的范围内使用相同的本地类。延迟调整大小及其预览保持独立;草稿存储在正在删除的面板之外。")}
</p>
</div>
拖动分隔符或使用箭头折叠面板。
尺寸限制为面积的百分之二十。
项目面板
保存的概述示例:方向更改、限制和调整大小的结果。
<script lang="ts">
import { Splitter } from '@woodger/antd';
let vertical = $state(false);
let sizes = $state<number[]>([]);
</script>
<style>
.controls {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 16px;
}
.surface {
height: 240px;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
overflow: hidden;
}
.pane {
display: grid;
height: 100%;
box-sizing: border-box;
align-content: center;
gap: 8px;
padding: 16px;
overflow-wrap: anywhere;
}
.pane p {
margin: 0;
color: var(--ant-color-text-secondary);
}
output {
display: block;
margin-top: 16px;
}
</style>
{#snippet first()}
<div class="pane"><strong>
{("第一个面板")}
</strong><p>
{("拖动分隔符或使用箭头折叠面板。")}
</p></div>
{/snippet}
{#snippet second()}
<div class="pane"><strong>
{("第二个面板")}
</strong><p>
{("尺寸限制为面积的百分之二十。")}
</p></div>
{/snippet}
<label class="controls"><input type="checkbox" bind:checked={vertical} />{(" 垂直划分")}</label>
<div class="surface">
<Splitter
orientation={vertical ? 'vertical' : 'horizontal'}
items={([
{ children: first, defaultSize: '40%', min: '20%', collapsible: true },
{ children: second, min: '20%', collapsible: true }
])}
onResizeEnd={next => { sizes = next; }}
/>
</div>
<output aria-label={("面板尺寸")}>{(sizes.length ? `${sizes.map(
Math.round
).join(' / ')} px` : "调整面板大小")}</output>
API
ant.design 实时页面主题映射到已安装包的公共 API。 Props 的完整定义位于 @woodger/antd 中。
| 主题 | 示例或限制 |
|---|---|
| CSS prefixes | 通用和局部 prefix、嵌套区域和独立的 lazy 预览。 |
| Basic | 两个带有 min/max 的面板。 |
| Control mode | 应用程序接受尺寸。 |
| Vertical | 垂直划分。 |
| Collapsible | 按钮、动作和回调。 |
| Control collapsible icons | auto/true/false. |
| Multiple panels | 三个相邻的面板。 |
| Complex combination | 嵌套划分。 |
| Lazy | 发布后尺寸会发生变化。 |
| Customize | 自定义图标。 |
| Custom semantic dom styling | ConfigProvider 和语义槽。 |
| Double-clicked reset | 受控比例重置。 |
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
prefixCls | 根、面板、分隔符和预览的完整本地前缀。空字符串和 undefined 继承相同的前缀。 styles/classNames 获取原始本地前缀;命名空间预览取决于 ConfigProvider.prefixCls。 | string | ConfigProvider + -splitter |
items | 面板数组,内容可以是字符串或片段。传入 items 时,优先使用该数组。嵌套声明为 Splitter.Panel。 | SplitterPanelProps[] | [] |
orientation | 面板轴:horizontal 或 vertical。 | horizontal | vertical | horizontal |
lazy | 延迟调整大小,直到释放指针。 | boolean | false |
destroyOnHidden | 删除折叠面板的内容;面板参数优先。 | boolean | false |
collapsible | 图标折叠和片段的动画。 | motion/icon config | — |
draggerIcon | 你自己的图标; null/false 创建一个空包装器。 | SplitterContent | Spinner |
onResizeStart | 开始拖动,尺寸以 px 为单位。 | (sizes: number[]) => void | — |
onResize | 用于 resize 和 collapse 的建议尺寸;应用程序接受它们以 controlled size。 | (sizes: number[]) => void | — |
onResizeEnd | 完成变更。lazy 报告建议大小而不使用 onResize。 | (sizes: number[]) => void | — |
onCollapse | 折叠时 onResize/onResizeEnd 之后。 | (collapsed, sizes) => void | — |
onDraggerDoubleClick | 双击边框,其中 resizable=false。 | (index: number) => void | — |
classNames | 类 root/panel/dragger,dragger 有 default/active。 | SplitterSemantic<SplitterClassSlots> | — |
styles | 用于 root、panel 和 dragger.default 的 CSS 字符串和对象。 | SplitterSemantic<SplitterStyleSlots> | — |
nativeElement | bind:nativeElement 而不是 React SplitterRef。 | HTMLDivElement | — |
面板选项
size 为整个组启用受控模式; defaultSize 指定初始大小。min/max 限制大小。默认情况下可调整大小 true;两个相邻的面板必须允许修改。 collapsible - boolean 或 start/end/showCollapsibleIcon 对象。 destroyOnHidden 会覆盖组设置。class/style 指的是面板;内容传递给 children。
Semantic DOM
root 包含邻居之间的 panel 和拖动器。语义 classNames/styles 可通过本地 props 和 ConfigProvider.splitter 获得。 dragger.default 设置普通样式; classNames.dragger.active 在拖动过程中应用,styles.dragger.active 在安装的实现中不使用。
边框具有 role="separator"、aria-orientation 和百分比 aria-valuenow/min/max。拖放支持鼠标和触摸;目前还无法使用键盘箭头调整大小。 Tab、Enter 和 Space 上提供折叠按钮。
在套装版本中,按钮的名称固定为“切换 start/end 面板”。 React 6.7 中引入的通过 aria-label 自定义 icon 覆盖名称的功能尚未保留。
注册令牌
表中有 3 个组件 token 对应 ant.design。 theme.components.Splitter 应用于边框和捕获区域大小。 root/panel/dragger 的附加样式通过语义 styles 和 ConfigProvider.splitter 显示。
| 代币 | 目的 |
|---|---|
splitBarDraggableSize | 边境占领区。 |
splitBarSize | 隔板厚度。 |
splitTriggerSize | 折叠按钮大小。 |
| 代币 | 当前值 |
|---|---|
colorFill | rgba(0,0,0,0.15) |
colorPrimary | #2f54eb |
colorPrimaryBorder | #adc6ff |
colorText | rgba(0,0,0,0.88) |
borderRadiusXS | 2 |
controlHeightSM | 24 |
controlItemBgActive | #f0f5ff |
controlItemBgActiveHover | #d6e4ff |
controlItemBgHover | rgba(0,0,0,0.04) |
fontFamily | -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
'Noto Color Emoji' |
fontSize | 14 |
fontSizeSM | 12 |
lineHeight | 1.5714285714285714 |
lineWidthFocus | 3 |
motionDurationSlow | 0.3s |
motionEaseInOut | cubic-bezier(0.645, 0.045, 0.355, 1) |
zIndexPopupBase | 1000 |
FAQ
为什么受控 Splitter 不改变大小?
接受 onResize 中的建议值,如果 lazy 的话 - onResizeEnd 中,并更新面板的 size。
如何设置尺寸?
数字是 px,百分比线是容器的份额。 defaultSize 仅指定初始值。
是否可以使用 resizable=false 隐藏面板?
不,它禁止调整相邻边框的大小。 Collapse 设置为 collapsible,内容保存设置为 destroyOnHidden。
隐藏面板中的焦点是什么?
保留 DOM 后,字段可能会保持 Tab 键顺序。 destroyOnHidden=true 删除内容及其本地状态;在应用程序中存储重要数据。
如何 lazy 保存尺寸?
通过 onResizeEnd。 preline 不会调整面板大小,也不会调用中间的 onResize。