분할 조절기는 두 패널과 그 사이에서 공간 배분을 조절하는 손잡이로 이루어집니다. 파일 목록과 편집기를 나란히 배치하거나 편집기 아래에 터미널을 배치할 때 사용합니다. 두 패널은 가느다란 경계선에서 맞닿습니다. 경계선에 호버하거나 포커스하면 선의 색이 진해지고 작은 손잡이 표시가 나타납니다.
분할 조절기는 레이아웃 자체가 아니라 레이아웃에 쓰이는 컴포넌트입니다. 손잡이에는 고유한 재질과 상태, 키보드 조작 계약이 있습니다. 크기를 조절할 필요가 없는 두 패널에는 마스터-디테일을 참고하세요.
스타일시트는 분할 조절기의 모양과 배치를 정하고, splitter동작은 손잡이를 움직입니다. 이 동작이 갱신하는 값은 컨테이너의 --splitter-size와 손잡이의 aria-valuenow뿐이며, 두 곳에 첫 번째 패널의 크기를 같은 숫자로 기록합니다.
분할 조절기
<divclass="splitter sheet overflow-hiddenh(240)"style="--splitter-size: 36%"><divclass="splitter-pane p-mdtext-smfg-text-body"><pclass="m(0)fg-text-strong">Files</p><pclass="mt-smm(0)">theme.css</p><pclass="m(0)">master.css</p><pclass="m(0)">components/</p></div><divclass="splitter-handle"role="separator"tabindex="0"aria-label="Resize the file list"aria-valuenow="36"aria-valuemin="15"aria-valuemax="85"></div><divclass="splitter-pane p-mdtext-smfg-text-body"><pclass="m(0)fg-text-strong">Editor</p><pclass="mt-smm(0)">Drag the line between the panes, or focus it and press the arrow keys.</p></div></div><scripttype="module">import{ attach }from'@master/ui/behaviors'attach()</script>
import{ useEffect, useRef }from'react'import{ attach }from'@master/ui/behaviors'exportfunctionExample(){const root =useRef<HTMLDivElement>(null)useEffect(()=>attach(root.current!),[])return(<divref={root}className="splitter sheet overflow-hiddenh(240)"style={{'--splitter-size':'36%'}asReact.CSSProperties}><divclassName="splitter-pane p-mdtext-smfg-text-body"><pclassName="m(0)fg-text-strong">Files</p><pclassName="mt-smm(0)">theme.css</p><pclassName="m(0)">master.css</p><pclassName="m(0)">components/</p></div><divclassName="splitter-handle"role="separator"tabIndex={0}aria-label="Resize the file list"aria-valuenow={36}aria-valuemin={15}aria-valuemax={85}></div><divclassName="splitter-pane p-mdtext-smfg-text-body"><pclassName="m(0)fg-text-strong">Editor</p><pclassName="mt-smm(0)"> Drag the line between the panes, or focus it and press the arrow keys.</p></div></div>)}
<script>import{ attach }from'@master/ui/behaviors'</script><divclass="splitter sheet overflow-hiddenh(240)"style="--splitter-size: 36%"{@attach attach}><divclass="splitter-pane p-mdtext-smfg-text-body"><pclass="m(0)fg-text-strong">Files</p><pclass="mt-smm(0)">theme.css</p><pclass="m(0)">master.css</p><pclass="m(0)">components/</p></div><divclass="splitter-handle"role="separator"tabindex="0"aria-label="Resize the file list"aria-valuenow="36"aria-valuemin="15"aria-valuemax="85"></div><divclass="splitter-pane p-mdtext-smfg-text-body"><pclass="m(0)fg-text-strong">Editor</p><pclass="mt-smm(0)">Drag the line between the panes, or focus it and press the arrow keys.</p></div></div>
<scriptsetup>import{ onMounted, onUnmounted, ref }from'vue'import{ attach }from'@master/ui/behaviors'const root =ref(null)let detachonMounted(()=>{ detach =attach(root.value)})onUnmounted(()=>detach?.())</script><template><divref="root"class="splitter sheet overflow-hiddenh(240)"style="--splitter-size:36%"><divclass="splitter-pane p-mdtext-smfg-text-body"><pclass="m(0)fg-text-strong">Files</p><pclass="mt-smm(0)">theme.css</p><pclass="m(0)">master.css</p><pclass="m(0)">components/</p></div><divclass="splitter-handle"role="separator"tabindex="0"aria-label="Resize the file list"aria-valuenow="36"aria-valuemin="15"aria-valuemax="85"></div><divclass="splitter-pane p-mdtext-smfg-text-body"><pclass="m(0)fg-text-strong">Editor</p><pclass="mt-smm(0)"> Drag the line between the panes, or focus it and press the arrow keys.</p></div></div></template>
드래그.pointerdown 이벤트가 발생하면 손잡이에서 포인터를 캡처하고, 포인터가 움직이는 동안 컨테이너 안에서의 위치를 백분율로 기록합니다.
키보드 조작. 손잡이가 움직이는 축에 해당하는 방향키를 누르면 한 단계씩 이동합니다. Home 키는 크기를 최솟값으로, End 키는 최댓값으로 설정합니다.
크기가 바뀔 때마다 루트의 --splitter-size와 손잡이의 aria-valuenow 값을 설정합니다. 크기는 손잡이의 aria-valuemin 값과 aria-valuemax 값 사이로 제한되며, 해당 값이 없으면 각각 0과 100을 사용합니다.
이벤트. 손잡이는 크기가 바뀔 때마다 input 이벤트를 발생시키고, 드래그가 끝나거나 키 조작으로 손잡이가 움직이면 change 이벤트를 발생시킵니다. 두 이벤트 모두 버블링됩니다. 값은 손잡이의 aria-valuenow에서 읽으세요.
비활성 상태.aria-disabled="true"가 설정된 손잡이는 움직이지 않습니다.
옵션
설정 항목
step
방향키를 한 번 누를 때 손잡이가 이동하는 비율(%). 기본값은 5
스타일시트는 어떤 크기를 지정하든 첫 번째 패널의 경계가 컨테이너 양 끝에서 최소 --splitter-min 떨어지도록 합니다. 손잡이를 잡고 있는 동안에는 텍스트 선택을 막고, 손잡이 방향에 맞춰 레이아웃을 전환합니다. 동작을 연결하지 않으면 패널은 --splitter-size에서 정한 비율을 유지하며 손잡이는 움직이지 않습니다.
aria-orientation 속성은 경계선의 방향을 지정합니다. 기본값은 수직이며 두 패널은 좌우로 나란히 배치됩니다. aria-orientation="horizontal"로 지정하면 패널이 위아래로 배치되고 손잡이는 수평선이 됩니다. 컨테이너가 속성을 직접 읽으므로 별도의 수정자 클래스를 맞춰 줄 필요가 없습니다.
위아래로 배치한 패널
<divclass="splitter sheet overflow-hiddenh(280)max-w(420)mx-auto"style="--splitter-size: 60%"><divclass="splitter-pane p-mdtext-smfg-text-body"><pclass="m(0)fg-text-strong">Editor</p></div><divclass="splitter-handle"role="separator"tabindex="0"aria-orientation="horizontal"aria-label="Resize the editor"aria-valuenow="60"aria-valuemin="15"aria-valuemax="85"></div><divclass="splitter-pane p-mdtext-smfg-text-body"><pclass="m(0)fg-text-strong">Terminal</p></div></div><scripttype="module">import{ attach }from'@master/ui/behaviors'attach()</script>
손잡이는 포커스할 수 있는 role="separator"입니다. 레이블은 크기가 조절되는 대상을 명시하고, aria-valuenow, aria-valuemin, aria-valuemax 값은 첫 번째 패널의 현재 크기, 최소 크기, 최대 크기를 각각 백분율로 나타냅니다. 이 정보로 보조 기술은 손잡이를 창 분할 조절기로 인식합니다.
포인터로 할 수 있는 모든 조작은 키보드로도 할 수 있어야 합니다. 분할 조절기 동작은 방향키로 손잡이를 이동하고 Home과 End 키로 양 끝에 도달하는 조작을 지원합니다.
레이아웃에서 경계선의 두께는 1픽셀이며, 조작 영역은 경계선에 수직인 방향으로 9px 폭입니다. 터치 화면에서는 조작 영역이 25px이고 손잡이 표시가 항상 나타납니다.
각 패널은 독립적으로 스크롤됩니다. 스크롤 가능한 패널에 포커스할 수 있는 콘텐츠가 없다면, 키보드로 패널에 접근할 수 있도록 레이블과 tabindex="0"을 지정하세요.
splitter 컴포넌트는 동작을 연결하고 크기 값을 입력받아 변경된 값을 외부로 전달합니다. 두 패널의 마크업은 페이지에서 직접 작성합니다. npx master-ui add splitter로 컴포넌트를 프로젝트에 복사하세요. 컴포넌트의 구성과 사용법은 React, Svelte, Vue에서 확인하세요.
ui/splitter.tsx
'use client'import{ useRef, useState,type ComponentProps,type CSSProperties,type ReactNode }from'react'import{ splitter }from'@master/ui/behaviors/splitter.js'import{ useBehavior }from'./use-behavior'exportinterfaceSplitterPropsextendsOmit<ComponentProps<'div'>,'defaultValue'|'children'|'ref'>{/** The first and the second pane. */start:ReactNodeend:ReactNode/** The first pane's size, in percent of the container. */value?:numberdefaultValue?:number/** Called as the handle moves. */onValueChange?:(value:number)=>void/** Called once a drag ends or a key moved the handle. */onValueCommit?:(value:number)=>void/** The least and the greatest size, in percent. */min?:numbermax?:number/** How far an arrow key moves the handle, in percent. */step?:number/** Stack the panes, with a handle that moves up and down. */stacked?:boolean/** The name of the handle: what it resizes. */label:stringdisabled?:boolean}/** Two panes and the handle between them. */exportfunctionSplitter({ start, end, value, defaultValue =50, onValueChange, onValueCommit, min =0, max =100, step =5, stacked, label, disabled, className, style,...root }:SplitterProps){const[first]=useState(value ?? defaultValue)const size =useRef(first)const ref =useBehavior(splitter,{ step },{ value, defaultValue,onValueChange:(next:number)=>{ size.current= next;onValueChange?.(next)},// The handle says change once a drag ends or a key moved it. A field in a pane says change too.on:{change:(event)=>{if((event.targetasElement).parentElement=== event.currentTarget&&(event.targetasElement).classList.contains('splitter-handle'))onValueCommit?.(size.current)}},})return(<divclassName={className ?`splitter ${className}`:'splitter'}style={{'--splitter-size':`${first}%`,...style }asCSSProperties}ref={ref}{...root}><divclassName="splitter-pane">{start}</div><divclassName="splitter-handle"role="separator"tabIndex={disabled ?-1:0}aria-label={label}aria-valuenow={Math.round(first)}aria-valuemin={min}aria-valuemax={max}aria-orientation={stacked ?'horizontal':undefined}aria-disabled={disabled ||undefined}/><divclassName="splitter-pane">{end}</div></div>)}
ui/Splitter.svelte
<scriptlang="ts"module>importtype{ Snippet }from'svelte'importtype{ HTMLAttributes }from'svelte/elements'exportinterfaceSplitterPropsextendsOmit<HTMLAttributes<HTMLDivElement>,'children'>{/** The first and the second pane. */start:Snippetend:Snippet/** The first pane's size, in percent of the container. Bind it, or leave it out: it starts at 50. */value?:number/** Called as the handle moves. */onValueChange?:(value:number)=>void/** Called once a drag ends or a key moved the handle. */onValueCommit?:(value:number)=>void/** The least and the greatest size, in percent. */min?:numbermax?:number/** How far an arrow key moves the handle, in percent. */step?:number/** Stack the panes, with a handle that moves up and down. */stacked?:boolean/** The name of the handle: what it resizes. */label:stringdisabled?:boolean}</script><scriptlang="ts">import{ untrack }from'svelte'import{ splitter }from'@master/ui/behaviors/splitter.js'import{ behavior }from'./behavior.svelte.js'let{ start, end, value =$bindable(), onValueChange, onValueCommit, min =0, max =100, step =5, stacked, label, disabled,class: className,...root }:SplitterProps=$props()const first =untrack(()=> value)??50// Svelte writes a style again whenever its owner changes it, so it writes the size the behavior holds.let size =$state(first)const attach =behavior(splitter,()=>({ step }),{value:()=> value,change:(next)=>{ value = size = next;onValueChange?.(next)},settled:(held)=>{ size = held },// The handle says change once a drag ends or a key moved it. A field in a pane says change too.on:{change:(event)=>{if((event.targetasElement).parentElement=== event.currentTarget&&(event.targetasElement).classList.contains('splitter-handle'))onValueCommit?.(size)}},})</script><!--@component Two panes and the handle between them.--><divclass={['splitter', className]}style:--splitter-size="{size}%"{@attach attach}{...root}><divclass="splitter-pane">{@renderstart()}</div><!-- A separator that takes focus is a control: the keys move it. --><!-- svelte-ignore a11y_no_noninteractive_tabindex --><divclass="splitter-handle"role="separator"tabindex={disabled ?-1:0}aria-label={label}aria-valuenow={Math.round(first)}aria-valuemin={min}aria-valuemax={max}aria-orientation={stacked ?'horizontal':undefined}aria-disabled={disabled ||undefined}></div><divclass="splitter-pane">{@renderend()}</div></div>
ui/Splitter.vue
<scriptsetuplang="ts">import{ useTemplateRef }from'vue'import{ splitter }from'@master/ui/behaviors/splitter.js'import{ useBehavior }from'./use-behavior'defineOptions({inheritAttrs:false})const{ min =0, max =100, step =5}=defineProps<{/** The least and the greatest size, in percent. */min?:numbermax?:number/** How far an arrow key moves the handle, in percent. */step?:number/** Stack the panes, with a handle that moves up and down. */stacked?:boolean/** The name of the handle: what it resizes. */label:stringdisabled?:boolean}>()/** The first pane's size, in percent of the container: `v-model`. It changes as the handle moves. */const model =defineModel<number>({default:50})const emit =defineEmits<{/** The size, once a drag ends or a key moved the handle. */valueCommit:[value:number]}>()defineSlots<{/** The first and the second pane. */start?:()=>unknownend?:()=>unknown}>()/* Two panes and the handle between them. */const first = model.valueconst root =useTemplateRef<HTMLDivElement>('root')const handle =useTemplateRef<HTMLDivElement>('handle')const current =useBehavior(root, splitter,()=>({ step }), model,{// The handle says change once a drag ends or a key moved it. A field in a pane says change too.change:(event)=>{if(event.target=== handle.value)emit('valueCommit',size())},})// Vue writes a style again each time it renders, so it writes the size the behavior holds, not the first one.constsize=()=>{const held =current()return held !==undefined&& Number.isFinite(held)? held : first}</script><template><divclass="splitter":style="{'--splitter-size':`${size()}%`}"ref="root"v-bind="$attrs"><divclass="splitter-pane"><slotname="start" /></div><divclass="splitter-handle"role="separator"ref="handle":tabindex="disabled ?-1:0":aria-label="label":aria-valuenow="Math.round(first)":aria-valuemin="min":aria-valuemax="max":aria-orientation="stacked ?'horizontal':undefined":aria-disabled="disabled ||undefined" /><divclass="splitter-pane"><slotname="end" /></div></div></template>
컨테이너에는 첫 번째 패널, 손잡이, 두 번째 패널이 차례로 들어갑니다. 손잡이의 aria-orientation에 따라 가로 또는 세로로 배치합니다.
splitter-pane
독립적으로 스크롤되는 패널입니다.
splitter-handle
두 패널 사이에 있는 포커스 가능한 role="separator" 요소입니다. 가는 선으로 표시되며 조작 영역은 9px, 터치 화면에서는 25px입니다. 레이블에는 크기를 조절할 대상을 명시합니다. aria-valuenow, aria-valuemin, aria-valuemax는 첫 번째 패널 크기의 현재값, 최솟값, 최댓값을 각각 백분율로 나타냅니다.
/* * Splitter: two panes and the handle between them that sets how they share the space. * The stylesheet draws it and lays it out; a script moves it. The script writes the first pane's size to * --splitter-size and the same number to the handle's aria-valuenow, on pointer drag and on the arrow keys. * The handle is a role="separator" that can take focus. Its aria-orientation says which way the line runs: * vertical (the default) between panes side by side, horizontal between panes stacked. * The line is a hairline until it is touched; then a grip appears on it and the line takes ink. */@layer components.ui {.splitter{--splitter-size:50%;--splitter-min:4rem;/* The first pane's track: the size asked for, kept --splitter-min away from both ends. */--splitter-track:clamp(var(--splitter-min),var(--splitter-size),calc(100%-var(--splitter-min)-1px));/* The handle stands over the panes inside the splitter, not over a sticky header that scrolls past it. */isolation:isolate;display:grid;grid-template-columns:var(--splitter-track)autominmax(0,1fr);min-width:0;min-height:0;&:has(.splitter-handle[aria-orientation="horizontal"]){grid-template-rows:var(--splitter-track)autominmax(0,1fr);grid-template-columns:none;}/* While the handle is held, nothing in the panes is selected by the drag. */&:has(.splitter-handle:active){user-select:none;-webkit-user-select:none;}}/* A pane scrolls by itself, so a long one never moves its neighbor. */.splitter-pane{min-width:0;min-height:0;overflow:auto;scrollbar-width:thin;scrollbar-color:var(--color-line-strong)transparent;}/* * The handle is one pixel of line in the layout, with a target of 9px across it, so the panes meet at * a hairline and the hand still finds it. */.splitter-handle{position:relative;z-index:1;width:1px;margin:0;padding:0;border:0;outline:none;background:var(--color-line-divider);cursor:col-resize;touch-action:none;-webkit-tap-highlight-color:transparent;transition: background-color var(--duration-quick)var(--easing-glide);/* The target, wider than the line. */&::before{content:'';position:absolute;inset:0-4px;}/* The grip: a small pill of sheet on the line, shown when the handle is touched or focused. */&::after{content:'';position:absolute;top:calc(50%-.75rem);left:-2.5px;width:6px;height:1.5rem;border-radius:999px;@apply--surface-sheet;box-shadow:var(--shadow-raised);opacity:0;scale:.6.8;transition-property: opacity, scale;transition-duration:var(--duration-quick);transition-timing-function:var(--easing-glide);}@media(hover:hover){&:hover{background:var(--color-line-mark);}&:hover::after{opacity:1;scale:1;}}&:is(:focus-visible,:active){background:var(--color-focus);}&:is(:focus-visible,:active)::after{opacity:1;scale:1;}&:focus-visible::after{@apply--focus-ring;}&[aria-orientation="horizontal"]{width:auto;height:1px;cursor:row-resize;&::before{inset:-4px0;}&::after{top:-2.5px;left:calc(50%-.75rem);width:1.5rem;height:6px;scale:.8.6;}&:is(:focus-visible,:active)::after{scale:1;}@media(hover:hover){&:hover::after{scale:1;}}}&[aria-disabled="true"]{background:var(--color-line-divider);cursor:default;pointer-events:none;}@media(pointer:coarse){&::before{inset:0-12px;}&[aria-orientation="horizontal"]::before{inset:-12px0;}/* Without a pointer to hover, the grip is always there to be found, at its full size either way. */&::after,&[aria-orientation="horizontal"]::after{opacity:1;scale:1;}}/* The grip fades in without growing, whichever way the line runs. */@media(prefers-reduced-motion:reduce){&::after,&[aria-orientation="horizontal"]::after{scale:none;}}/* Each state's line is written again in a system color, at the weight of its own rule above. */@media(forced-colors:active){background: CanvasText;&:hover{background: CanvasText;}&:is(:focus-visible,:active){background: Highlight;}&[aria-disabled="true"]{background: GrayText;}/* An outline, not a border, so the grip keeps its size and stays centered on the line. */&::after{outline:1pxsolid CanvasText;outline-offset:-1px;background: Canvas;}}}}