Resizable
Panels that a person resizes with a pointer or the keyboard on the handles between them.
Editor
The code of the page.
Preview
The page as a visitor sees it.
<script setup lang="ts">
import { Resizable } from '@vase-ui/vue/resizable';
import styles from './index.module.css';
</script>
<template>
<Resizable.Root :class="styles.Root">
<Resizable.Panel id="navigation" default-size="25" min-size="15" :class="styles.Panel">
<p :class="styles.Label">Navigation</p>
<p :class="styles.Description">The pages of the project.</p>
</Resizable.Panel>
<Resizable.Handle aria-label="Resize the navigation" :class="styles.Handle" />
<Resizable.Panel id="editor" :class="styles.Panel">
<p :class="styles.Label">Editor</p>
<p :class="styles.Description">The code of the page.</p>
</Resizable.Panel>
<Resizable.Handle primary-panel="next" aria-label="Resize the preview" :class="styles.Handle" />
<Resizable.Panel id="preview" default-size="30" :class="styles.Panel">
<p :class="styles.Label">Preview</p>
<p :class="styles.Description">The page as a visitor sees it.</p>
</Resizable.Panel>
</Resizable.Root>
</template>.Root {
box-sizing: border-box;
width: 100%;
height: 12rem;
overflow: hidden;
border: 1px solid oklch(92.2% 0 0deg);
border-radius: 0.375rem;
@media (prefers-color-scheme: dark) {
border-color: oklch(26.9% 0 0deg);
}
}
.Panel {
box-sizing: border-box;
padding: 1rem;
overflow: hidden;
}
.Label {
margin: 0;
font-size: 0.875rem;
font-weight: 500;
line-height: 1.25rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Description {
margin: 0.25rem 0 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Handle {
flex: none;
width: 1px;
background-color: oklch(92.2% 0 0deg);
outline: none;
cursor: col-resize;
@media (pointer: coarse) {
--resizable-handle-hit-area-size: 24px;
}
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
&[data-at-min] {
cursor: e-resize;
}
&[data-at-max] {
cursor: w-resize;
}
&[data-at-min][data-at-max] {
cursor: default;
}
&[aria-disabled='true'] {
cursor: default;
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}<script setup lang="ts">
import { Resizable } from '@vase-ui/vue/resizable';
</script>
<template>
<Resizable.Root
class="box-border h-48 w-full overflow-hidden rounded-md border border-neutral-200 dark:border-neutral-800"
>
<Resizable.Panel
id="navigation"
default-size="25"
min-size="15"
class="box-border overflow-hidden p-4"
>
<p class="text-sm font-medium text-neutral-950 dark:text-white">Navigation</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">The pages of the project.</p>
</Resizable.Panel>
<Resizable.Handle
aria-label="Resize the navigation"
class="w-px flex-none cursor-col-resize pointer-coarse:[--resizable-handle-hit-area-size:24px] bg-neutral-200 outline-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 data-at-max:cursor-w-resize data-at-min:cursor-e-resize data-at-min:data-at-max:cursor-default aria-disabled:cursor-default dark:bg-neutral-800 dark:focus-visible:outline-white"
/>
<Resizable.Panel id="editor" class="box-border overflow-hidden p-4">
<p class="text-sm font-medium text-neutral-950 dark:text-white">Editor</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">The code of the page.</p>
</Resizable.Panel>
<Resizable.Handle
primary-panel="next"
aria-label="Resize the preview"
class="w-px flex-none cursor-col-resize pointer-coarse:[--resizable-handle-hit-area-size:24px] bg-neutral-200 outline-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 data-at-max:cursor-w-resize data-at-min:cursor-e-resize data-at-min:data-at-max:cursor-default aria-disabled:cursor-default dark:bg-neutral-800 dark:focus-visible:outline-white"
/>
<Resizable.Panel id="preview" default-size="30" class="box-border overflow-hidden p-4">
<p class="text-sm font-medium text-neutral-950 dark:text-white">Preview</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">
The page as a visitor sees it.
</p>
</Resizable.Panel>
</Resizable.Root>
</template>Usage guidelines
- Keep the parts flex items of the root. Each panel and each handle must be a flex item of the root element. A wrapper element between them needs
display: contents. - Name each handle. Give each handle a name that says which panel it resizes, such as
aria-label="Resize the navigation". - Give the value words. The value of a handle is the size of its primary panel in percent, and a screen reader reads it as a number. To give it words, bind
aria-valuetextto a text fromsizesof the default slot of the root. Control the layout shows how. - Give a coarse pointer a larger target. The pointer target of a handle is at least 10 px on the axis of the move. WCAG 2.5.8 asks for a target of at least 24 by 24 CSS pixels. Set
--resizable-handle-hit-area-sizeto24pxin@media (pointer: coarse), as each demo does.
Anatomy
Import the component and assemble its parts:
<script setup lang="ts">
import { Resizable } from '@vase-ui/vue/resizable';
</script>
<template>
<Resizable.Root>
<Resizable.Panel />
<Resizable.Handle />
<Resizable.Panel />
</Resizable.Root>
</template>Examples
Sizes and units
A size is a number, or a string of a number with a unit. A number, a string with no unit, such as '30', and a string with %, such as '30%', are percent of the panel space. The panel space is the room of the root, less the handles, the elements that are not panels, and the padding and the border of each panel.
A length is px, em, rem, vh or vw. em is the font size of the panel, and rem is the font size of the root element of the document. vh is 1% of innerHeight, which differs from the CSS vh on a phone while its toolbar shows.
<script setup lang="ts">
import { Resizable } from '@vase-ui/vue/resizable';
</script>
<template>
<Resizable.Root>
<Resizable.Panel :default-size="20" min-size="10%" max-size="40" />
<Resizable.Handle aria-label="Resize the first panel" />
<Resizable.Panel default-size="240px" min-size="12em" max-size="30rem" />
<Resizable.Handle aria-label="Resize the second panel" />
<Resizable.Panel min-size="20vw" max-size="80vh" />
</Resizable.Root>
</template>Each size prop of a panel, each entry of the layout, and step, largeStep and dragStep of the root take these forms. In the props of the root, em is the font size of the root. For equal sizes, give no size. For a preferred size, give a defaultSize and a minSize.
A size in another form has no effect, and a development build shows a warning. A size prop then has its default. The panel of such an entry of the layout takes its defaultSize, or an equal share of the space that is left. A layout that the app reads from a cookie or a storage thus needs no check.
Control the layout
v-model makes the layout controlled. Start with an empty layout, ref({}), and each panel takes its defaultSize, or an equal share. Write {} to give each panel its first size again.
<script setup lang="ts">
import { ref } from 'vue';
import { Resizable, type ResizableLayout } from '@vase-ui/vue/resizable';
const layout = ref<ResizableLayout>({});
</script>
<template>
<button type="button" @click="layout = {}">Give the first sizes</button>
<Resizable.Root v-slot="{ sizes }" v-model="layout">
<Resizable.Panel id="navigation" :default-size="25" />
<Resizable.Handle
aria-label="Resize the navigation"
:aria-valuetext="`${Math.round(sizes.navigation ?? 25)} percent`"
/>
<Resizable.Panel id="editor" />
</Resizable.Root>
</template>The layout is the layout that the app asks for. The panels show it as far as their constraints allow. A new object with the same entries changes nothing, so each fixed panel keeps its pixels until the next change of the layout.
sizes of the default slot of the root has the size of each mounted panel in percent. The sample makes the aria-valuetext of the handle from it. To read the size of a panel in pixels, observe its element with a ResizeObserver.
Collapse a panel
A panel with collapsible collapses to its collapsedSize, which is 0 by default. A drag collapses the panel when it goes below minSize by more than collapseThreshold. A drag expands a collapsed panel when it goes above collapsedSize by more than collapseThreshold. Enter on a handle collapses or expands its primary panel at once, as collapse() and expand() of a template ref do.
The size of a panel is its flex-grow, so a CSS transition of flex-grow animates a collapse. The panels get their sizes at the mount. Add the class of the transition in the second animation frame after the mount, so that it does not animate them. The root has data-dragging during a drag. Remove the transition then, or each move of the pointer animates.
Main
Drag the handle to the left, or press Enter on it.
<script setup lang="ts">
import { onMounted, shallowRef, useTemplateRef } from 'vue';
import { Resizable } from '@vase-ui/vue/resizable';
import CollapseButton from './CollapseButton.vue';
import styles from './index.module.css';
const sidebar = useTemplateRef('sidebar');
// The panels get their sizes at the mount. The transition starts two frames later, so that it
// does not animate them.
const animated = shallowRef(false);
onMounted(() => requestAnimationFrame(() => requestAnimationFrame(() => (animated.value = true))));
function toggle(collapsed: boolean) {
if (collapsed) sidebar.value?.expand();
else sidebar.value?.collapse();
}
</script>
<template>
<Resizable.Root :class="styles.Root">
<Resizable.Panel
id="sidebar"
ref="sidebar"
v-slot="{ state }"
default-size="30"
min-size="160px"
collapsible
collapsed-size="48px"
:class="[styles.Sidebar, animated && styles.Animated]"
>
<div :class="styles.SidebarHeader">
<CollapseButton
:collapsed="state.collapsed"
controls="sidebar"
@toggle="toggle(state.collapsed)"
/>
<p :class="styles.Label">Sidebar</p>
</div>
</Resizable.Panel>
<Resizable.Handle aria-label="Resize the sidebar" :class="styles.Handle" />
<Resizable.Panel id="main" :class="styles.Panel">
<p :class="styles.Label">Main</p>
<p :class="styles.Description">Drag the handle to the left, or press Enter on it.</p>
</Resizable.Panel>
</Resizable.Root>
</template>.Root {
box-sizing: border-box;
width: 100%;
height: 12rem;
overflow: hidden;
border: 1px solid oklch(92.2% 0 0deg);
border-radius: 0.375rem;
@media (prefers-color-scheme: dark) {
border-color: oklch(26.9% 0 0deg);
}
}
.Sidebar {
box-sizing: border-box;
overflow: hidden;
white-space: nowrap;
}
.Animated {
transition: flex-grow 200ms;
@media (prefers-reduced-motion: reduce) {
transition: none;
}
}
.Root[data-dragging] > .Animated {
transition: none;
}
.SidebarHeader {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.5rem;
}
.Panel {
box-sizing: border-box;
padding: 1rem;
overflow: hidden;
}
.Button {
box-sizing: border-box;
display: flex;
flex: none;
align-items: center;
justify-content: center;
width: 2rem;
height: 2rem;
padding: 0;
border: 1px solid oklch(92.2% 0 0deg);
border-radius: 0.375rem;
background-color: transparent;
color: oklch(14.5% 0 0deg);
outline: none;
@media (prefers-color-scheme: dark) {
border-color: oklch(26.9% 0 0deg);
color: white;
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: 2px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Button[aria-expanded='false'] > .Icon {
rotate: 180deg;
}
.Label {
margin: 0;
font-size: 0.875rem;
font-weight: 500;
line-height: 1.25rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Description {
margin: 0.25rem 0 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Handle {
flex: none;
width: 1px;
background-color: oklch(92.2% 0 0deg);
outline: none;
cursor: col-resize;
@media (pointer: coarse) {
--resizable-handle-hit-area-size: 24px;
}
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
&[data-at-min] {
cursor: e-resize;
}
&[data-at-max] {
cursor: w-resize;
}
&[data-at-min][data-at-max] {
cursor: default;
}
&[aria-disabled='true'] {
cursor: default;
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}<script setup lang="ts">
import styles from './index.module.css';
defineProps<{
/** The panel is collapsed. */
collapsed: boolean;
/** The `id` of the panel. */
controls: string;
}>();
defineEmits<{ toggle: [] }>();
</script>
<template>
<button
type="button"
aria-label="Sidebar"
:aria-expanded="!collapsed"
:aria-controls="controls"
:class="styles.Button"
@click="$emit('toggle')"
>
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="currentColor"
aria-hidden="true"
:class="styles.Icon"
>
<path d="M10 4v8L5.5 8z" />
</svg>
</button>
</template><script setup lang="ts">
import { onMounted, shallowRef, useTemplateRef } from 'vue';
import { Resizable } from '@vase-ui/vue/resizable';
import CollapseButton from './CollapseButton.vue';
const sidebar = useTemplateRef('sidebar');
// The panels get their sizes at the mount. The transition starts two frames later, so that it
// does not animate them.
const animated = shallowRef(false);
onMounted(() => requestAnimationFrame(() => requestAnimationFrame(() => (animated.value = true))));
function toggle(collapsed: boolean) {
if (collapsed) sidebar.value?.expand();
else sidebar.value?.collapse();
}
</script>
<template>
<Resizable.Root
class="h-48 box-border w-full overflow-hidden rounded-md border border-neutral-200 dark:border-neutral-800 [&[data-dragging]>*]:transition-none"
>
<Resizable.Panel
id="sidebar"
ref="sidebar"
v-slot="{ state }"
default-size="30"
min-size="160px"
collapsible
collapsed-size="48px"
:class="[
'box-border overflow-hidden whitespace-nowrap',
animated && 'transition-[flex-grow] duration-200 ease-[ease] motion-reduce:transition-none',
]"
>
<div class="flex items-center gap-2 p-2">
<CollapseButton
:collapsed="state.collapsed"
controls="sidebar"
@toggle="toggle(state.collapsed)"
/>
<p class="text-sm font-medium text-neutral-950 dark:text-white">Sidebar</p>
</div>
</Resizable.Panel>
<Resizable.Handle
aria-label="Resize the sidebar"
class="w-px flex-none cursor-col-resize pointer-coarse:[--resizable-handle-hit-area-size:24px] bg-neutral-200 outline-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 data-at-max:cursor-w-resize data-at-min:cursor-e-resize data-at-min:data-at-max:cursor-default aria-disabled:cursor-default dark:bg-neutral-800 dark:focus-visible:outline-white"
/>
<Resizable.Panel id="main" class="box-border overflow-hidden p-4">
<p class="text-sm font-medium text-neutral-950 dark:text-white">Main</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">
Drag the handle to the left, or press Enter on it.
</p>
</Resizable.Panel>
</Resizable.Root>
</template><script setup lang="ts">
defineProps<{
/** The panel is collapsed. */
collapsed: boolean;
/** The `id` of the panel. */
controls: string;
}>();
defineEmits<{ toggle: [] }>();
</script>
<template>
<button
type="button"
aria-label="Sidebar"
:aria-expanded="!collapsed"
:aria-controls="controls"
class="group box-border flex size-8 flex-none items-center justify-center rounded-md border border-neutral-200 p-0 text-neutral-950 outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950 dark:border-neutral-800 dark:text-white dark:focus-visible:outline-white"
@click="$emit('toggle')"
>
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="currentColor"
aria-hidden="true"
class="group-aria-[expanded=false]:rotate-180"
>
<path d="M10 4v8L5.5 8z" />
</svg>
</button>
</template>To hide a panel and keep it mounted, give it collapsible and a collapsedSize of 0, and call collapse(). Its content keeps its state.
Accordion
Three collapsible panels in a vertical root make an accordion. Each header button gets the state of its panel, and calls collapse() or expand() of the template ref of the panel.
The pages of the project.
The headings of the page.
The changes to the page.
<script setup lang="ts">
import { onMounted, shallowRef, useTemplateRef } from 'vue';
import { Resizable } from '@vase-ui/vue/resizable';
import AccordionHeader from './AccordionHeader.vue';
import styles from './index.module.css';
const files = useTemplateRef('files');
const outline = useTemplateRef('outline');
const timeline = useTemplateRef('timeline');
// The panels get their sizes at the mount. The transition starts two frames later, so that it
// does not animate them.
const animated = shallowRef(false);
onMounted(() => requestAnimationFrame(() => requestAnimationFrame(() => (animated.value = true))));
function toggle(panel: { collapse(): void; expand(): void } | null, collapsed: boolean) {
if (collapsed) panel?.expand();
else panel?.collapse();
}
</script>
<template>
<Resizable.Root orientation="vertical" :class="styles.Root">
<Resizable.Panel
id="files"
ref="files"
v-slot="{ state }"
collapsible
collapsed-size="40px"
min-size="80px"
:class="[styles.Panel, animated && styles.Animated]"
>
<AccordionHeader
:expanded="!state.collapsed"
controls="files"
@toggle="toggle(files, state.collapsed)"
>
Files
</AccordionHeader>
<p :class="styles.Description">The pages of the project.</p>
</Resizable.Panel>
<Resizable.Handle aria-label="Resize the files" :class="styles.Handle" />
<Resizable.Panel
id="outline"
ref="outline"
v-slot="{ state }"
collapsible
collapsed-size="40px"
min-size="80px"
:class="[styles.Panel, animated && styles.Animated]"
>
<AccordionHeader
:expanded="!state.collapsed"
controls="outline"
@toggle="toggle(outline, state.collapsed)"
>
Outline
</AccordionHeader>
<p :class="styles.Description">The headings of the page.</p>
</Resizable.Panel>
<Resizable.Handle
primary-panel="next"
aria-label="Resize the timeline"
:class="styles.Handle"
/>
<Resizable.Panel
id="timeline"
ref="timeline"
v-slot="{ state }"
collapsible
collapsed-size="40px"
min-size="80px"
:class="[styles.Panel, animated && styles.Animated]"
>
<AccordionHeader
:expanded="!state.collapsed"
controls="timeline"
@toggle="toggle(timeline, state.collapsed)"
>
Timeline
</AccordionHeader>
<p :class="styles.Description">The changes to the page.</p>
</Resizable.Panel>
</Resizable.Root>
</template>.Root {
box-sizing: border-box;
width: 100%;
height: 16rem;
overflow: hidden;
border: 1px solid oklch(92.2% 0 0deg);
border-radius: 0.375rem;
@media (prefers-color-scheme: dark) {
border-color: oklch(26.9% 0 0deg);
}
}
.Panel {
box-sizing: border-box;
overflow: hidden;
}
.Animated {
transition: flex-grow 200ms;
@media (prefers-reduced-motion: reduce) {
transition: none;
}
}
.Root[data-dragging] > .Animated {
transition: none;
}
.Header {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
height: 2.5rem;
padding: 0 1rem;
border: 0;
background-color: transparent;
font: inherit;
font-size: 0.875rem;
font-weight: 500;
line-height: 1.25rem;
color: oklch(14.5% 0 0deg);
outline: none;
@media (prefers-color-scheme: dark) {
color: white;
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -2px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Header[aria-expanded='false'] > .Icon {
rotate: -90deg;
}
.Description {
margin: 0;
padding: 0 1rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Handle {
flex: none;
height: 1px;
background-color: oklch(92.2% 0 0deg);
outline: none;
cursor: row-resize;
@media (pointer: coarse) {
--resizable-handle-hit-area-size: 24px;
}
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
&[data-at-min] {
cursor: s-resize;
}
&[data-at-max] {
cursor: n-resize;
}
&[data-at-min][data-at-max] {
cursor: default;
}
&[aria-disabled='true'] {
cursor: default;
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}<script setup lang="ts">
import styles from './index.module.css';
defineProps<{
/** The panel is expanded. */
expanded: boolean;
/** The `id` of the panel. */
controls: string;
}>();
defineEmits<{ toggle: [] }>();
</script>
<template>
<button
type="button"
:aria-expanded="expanded"
:aria-controls="controls"
:class="styles.Header"
@click="$emit('toggle')"
>
<slot />
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="currentColor"
aria-hidden="true"
:class="styles.Icon"
>
<path d="M4 6h8l-4 4.5z" />
</svg>
</button>
</template><script setup lang="ts">
import { onMounted, shallowRef, useTemplateRef } from 'vue';
import { Resizable } from '@vase-ui/vue/resizable';
import AccordionHeader from './AccordionHeader.vue';
const files = useTemplateRef('files');
const outline = useTemplateRef('outline');
const timeline = useTemplateRef('timeline');
// The panels get their sizes at the mount. The transition starts two frames later, so that it
// does not animate them.
const animated = shallowRef(false);
onMounted(() => requestAnimationFrame(() => requestAnimationFrame(() => (animated.value = true))));
function toggle(panel: { collapse(): void; expand(): void } | null, collapsed: boolean) {
if (collapsed) panel?.expand();
else panel?.collapse();
}
</script>
<template>
<Resizable.Root
orientation="vertical"
class="h-64 box-border w-full overflow-hidden rounded-md border border-neutral-200 dark:border-neutral-800 [&[data-dragging]>*]:transition-none"
>
<Resizable.Panel
id="files"
ref="files"
v-slot="{ state }"
collapsible
collapsed-size="40px"
min-size="80px"
:class="[
'box-border overflow-hidden',
animated && 'transition-[flex-grow] duration-200 ease-[ease] motion-reduce:transition-none',
]"
>
<AccordionHeader
:expanded="!state.collapsed"
controls="files"
@toggle="toggle(files, state.collapsed)"
>
Files
</AccordionHeader>
<p class="px-4 text-sm text-neutral-600 dark:text-neutral-400">The pages of the project.</p>
</Resizable.Panel>
<Resizable.Handle
aria-label="Resize the files"
class="h-px flex-none cursor-row-resize pointer-coarse:[--resizable-handle-hit-area-size:24px] bg-neutral-200 outline-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 data-at-max:cursor-n-resize data-at-min:cursor-s-resize data-at-min:data-at-max:cursor-default aria-disabled:cursor-default dark:bg-neutral-800 dark:focus-visible:outline-white"
/>
<Resizable.Panel
id="outline"
ref="outline"
v-slot="{ state }"
collapsible
collapsed-size="40px"
min-size="80px"
:class="[
'box-border overflow-hidden',
animated && 'transition-[flex-grow] duration-200 ease-[ease] motion-reduce:transition-none',
]"
>
<AccordionHeader
:expanded="!state.collapsed"
controls="outline"
@toggle="toggle(outline, state.collapsed)"
>
Outline
</AccordionHeader>
<p class="px-4 text-sm text-neutral-600 dark:text-neutral-400">The headings of the page.</p>
</Resizable.Panel>
<Resizable.Handle
primary-panel="next"
aria-label="Resize the timeline"
class="h-px flex-none cursor-row-resize pointer-coarse:[--resizable-handle-hit-area-size:24px] bg-neutral-200 outline-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 data-at-max:cursor-n-resize data-at-min:cursor-s-resize data-at-min:data-at-max:cursor-default aria-disabled:cursor-default dark:bg-neutral-800 dark:focus-visible:outline-white"
/>
<Resizable.Panel
id="timeline"
ref="timeline"
v-slot="{ state }"
collapsible
collapsed-size="40px"
min-size="80px"
:class="[
'box-border overflow-hidden',
animated && 'transition-[flex-grow] duration-200 ease-[ease] motion-reduce:transition-none',
]"
>
<AccordionHeader
:expanded="!state.collapsed"
controls="timeline"
@toggle="toggle(timeline, state.collapsed)"
>
Timeline
</AccordionHeader>
<p class="px-4 text-sm text-neutral-600 dark:text-neutral-400">The changes to the page.</p>
</Resizable.Panel>
</Resizable.Root>
</template><script setup lang="ts">
defineProps<{
/** The panel is expanded. */
expanded: boolean;
/** The `id` of the panel. */
controls: string;
}>();
defineEmits<{ toggle: [] }>();
</script>
<template>
<button
type="button"
:aria-expanded="expanded"
:aria-controls="controls"
class="group box-border flex h-10 w-full items-center justify-between border-0 bg-transparent px-4 text-sm font-medium text-neutral-950 outline-none focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-neutral-950 dark:text-white dark:focus-visible:outline-white"
@click="$emit('toggle')"
>
<slot />
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="currentColor"
aria-hidden="true"
class="group-aria-[expanded=false]:-rotate-90"
>
<path d="M4 6h8l-4 4.5z" />
</svg>
</button>
</template>Fixed panels
A panel with rootResizeBehavior="fixed" keeps its pixels when the root changes size. The other panels share the rest in the ratio that they have. When the other panels cannot take a change of the root, the fixed panels change size in the order of rootResizePriority: the greater number first.
A drag, a key, a method and the layout of the app give a fixed panel new pixels. The layout of each event gives a fixed panel in pixels, with three decimals at the most, such as '240px'. Give that layout back to v-model or to defaultLayout, and each fixed panel gets its pixels again at each size of the root.
Editor
The editor takes the rest of the width.
The layout: {}
<script setup lang="ts">
import { ref } from 'vue';
import { Resizable, type ResizableLayout } from '@vase-ui/vue/resizable';
import styles from './index.module.css';
// The layout has the width of the navigation in pixels.
const layout = ref<ResizableLayout>({});
</script>
<template>
<Resizable.Root v-model="layout" :class="styles.Root">
<Resizable.Panel
id="navigation"
default-size="240px"
min-size="10rem"
max-size="50vw"
root-resize-behavior="fixed"
:class="styles.Panel"
>
<p :class="styles.Label">Navigation</p>
<p :class="styles.Description">Resize the window: the navigation keeps its width.</p>
</Resizable.Panel>
<Resizable.Handle aria-label="Resize the navigation" :class="styles.Handle" />
<Resizable.Panel id="editor" :class="styles.Panel">
<p :class="styles.Label">Editor</p>
<p :class="styles.Description">The editor takes the rest of the width.</p>
<p :class="styles.Description">The layout: {{ JSON.stringify(layout) }}</p>
</Resizable.Panel>
</Resizable.Root>
</template>.Root {
box-sizing: border-box;
width: 100%;
height: 12rem;
overflow: hidden;
border: 1px solid oklch(92.2% 0 0deg);
border-radius: 0.375rem;
@media (prefers-color-scheme: dark) {
border-color: oklch(26.9% 0 0deg);
}
}
.Panel {
box-sizing: border-box;
padding: 1rem;
overflow: hidden;
}
.Label {
margin: 0;
font-size: 0.875rem;
font-weight: 500;
line-height: 1.25rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Description {
margin: 0.25rem 0 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Handle {
flex: none;
width: 1px;
background-color: oklch(92.2% 0 0deg);
outline: none;
cursor: col-resize;
@media (pointer: coarse) {
--resizable-handle-hit-area-size: 24px;
}
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
&[data-at-min] {
cursor: e-resize;
}
&[data-at-max] {
cursor: w-resize;
}
&[data-at-min][data-at-max] {
cursor: default;
}
&[aria-disabled='true'] {
cursor: default;
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}<script setup lang="ts">
import { ref } from 'vue';
import { Resizable, type ResizableLayout } from '@vase-ui/vue/resizable';
// The layout has the width of the navigation in pixels.
const layout = ref<ResizableLayout>({});
</script>
<template>
<Resizable.Root
v-model="layout"
class="box-border h-48 w-full overflow-hidden rounded-md border border-neutral-200 dark:border-neutral-800"
>
<Resizable.Panel
id="navigation"
default-size="240px"
min-size="10rem"
max-size="50vw"
root-resize-behavior="fixed"
class="box-border overflow-hidden p-4"
>
<p class="text-sm font-medium text-neutral-950 dark:text-white">Navigation</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">
Resize the window: the navigation keeps its width.
</p>
</Resizable.Panel>
<Resizable.Handle
aria-label="Resize the navigation"
class="w-px flex-none cursor-col-resize pointer-coarse:[--resizable-handle-hit-area-size:24px] bg-neutral-200 outline-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 data-at-max:cursor-w-resize data-at-min:cursor-e-resize data-at-min:data-at-max:cursor-default aria-disabled:cursor-default dark:bg-neutral-800 dark:focus-visible:outline-white"
/>
<Resizable.Panel id="editor" class="box-border overflow-hidden p-4">
<p class="text-sm font-medium text-neutral-950 dark:text-white">Editor</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">
The editor takes the rest of the width.
</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">
The layout: {{ JSON.stringify(layout) }}
</p>
</Resizable.Panel>
</Resizable.Root>
</template>Vertical
orientation="vertical" puts the panels in a column.
Editor
The code of the page.
Terminal
The output of the build.
<script setup lang="ts">
import { Resizable } from '@vase-ui/vue/resizable';
import styles from './index.module.css';
</script>
<template>
<Resizable.Root orientation="vertical" :class="styles.Root">
<Resizable.Panel id="editor" :class="styles.Panel">
<p :class="styles.Label">Editor</p>
<p :class="styles.Description">The code of the page.</p>
</Resizable.Panel>
<Resizable.Handle
primary-panel="next"
aria-label="Resize the terminal"
:class="styles.Handle"
/>
<Resizable.Panel id="terminal" default-size="30" min-size="20" :class="styles.Panel">
<p :class="styles.Label">Terminal</p>
<p :class="styles.Description">The output of the build.</p>
</Resizable.Panel>
</Resizable.Root>
</template>.Root {
box-sizing: border-box;
width: 100%;
height: 12rem;
overflow: hidden;
border: 1px solid oklch(92.2% 0 0deg);
border-radius: 0.375rem;
@media (prefers-color-scheme: dark) {
border-color: oklch(26.9% 0 0deg);
}
}
.Panel {
box-sizing: border-box;
padding: 1rem;
overflow: hidden;
}
.Label {
margin: 0;
font-size: 0.875rem;
font-weight: 500;
line-height: 1.25rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Description {
margin: 0.25rem 0 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Handle {
flex: none;
height: 1px;
background-color: oklch(92.2% 0 0deg);
outline: none;
cursor: row-resize;
@media (pointer: coarse) {
--resizable-handle-hit-area-size: 24px;
}
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
&[data-at-min] {
cursor: s-resize;
}
&[data-at-max] {
cursor: n-resize;
}
&[data-at-min][data-at-max] {
cursor: default;
}
&[aria-disabled='true'] {
cursor: default;
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}<script setup lang="ts">
import { Resizable } from '@vase-ui/vue/resizable';
</script>
<template>
<Resizable.Root
orientation="vertical"
class="box-border h-48 w-full overflow-hidden rounded-md border border-neutral-200 dark:border-neutral-800"
>
<Resizable.Panel id="editor" class="box-border overflow-hidden p-4">
<p class="text-sm font-medium text-neutral-950 dark:text-white">Editor</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">The code of the page.</p>
</Resizable.Panel>
<Resizable.Handle
primary-panel="next"
aria-label="Resize the terminal"
class="h-px flex-none cursor-row-resize pointer-coarse:[--resizable-handle-hit-area-size:24px] bg-neutral-200 outline-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 data-at-max:cursor-n-resize data-at-min:cursor-s-resize data-at-min:data-at-max:cursor-default aria-disabled:cursor-default dark:bg-neutral-800 dark:focus-visible:outline-white"
/>
<Resizable.Panel
id="terminal"
default-size="30"
min-size="20"
class="box-border overflow-hidden p-4"
>
<p class="text-sm font-medium text-neutral-950 dark:text-white">Terminal</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">The output of the build.</p>
</Resizable.Panel>
</Resizable.Root>
</template>Nested roots
A root can be in a panel of another root. Each root keeps its own layout. Where a handle of one root crosses a handle of the other root, a press drags both handles. A layer over the page, such as a dialog, covers the handles under it.
Editor
Press at the crossing to move both handles.
Terminal
The output of the build.
<script setup lang="ts">
import { Resizable } from '@vase-ui/vue/resizable';
import styles from './index.module.css';
</script>
<template>
<Resizable.Root :class="styles.Root">
<Resizable.Panel id="navigation" default-size="30" :class="styles.Panel">
<p :class="styles.Label">Navigation</p>
<p :class="styles.Description">The pages of the project.</p>
</Resizable.Panel>
<Resizable.Handle aria-label="Resize the navigation" :class="styles.Handle" />
<Resizable.Panel id="main" :class="styles.Main">
<Resizable.Root orientation="vertical" :class="styles.InnerRoot">
<Resizable.Panel id="editor" :class="styles.Panel">
<p :class="styles.Label">Editor</p>
<p :class="styles.Description">Press at the crossing to move both handles.</p>
</Resizable.Panel>
<Resizable.Handle
primary-panel="next"
aria-label="Resize the terminal"
:class="styles.Handle"
/>
<Resizable.Panel id="terminal" default-size="35" :class="styles.Panel">
<p :class="styles.Label">Terminal</p>
<p :class="styles.Description">The output of the build.</p>
</Resizable.Panel>
</Resizable.Root>
</Resizable.Panel>
</Resizable.Root>
</template>.Root {
box-sizing: border-box;
width: 100%;
height: 12rem;
overflow: hidden;
border: 1px solid oklch(92.2% 0 0deg);
border-radius: 0.375rem;
@media (prefers-color-scheme: dark) {
border-color: oklch(26.9% 0 0deg);
}
}
.Main {
overflow: hidden;
}
.InnerRoot {
height: 100%;
}
.Panel {
box-sizing: border-box;
padding: 1rem;
overflow: hidden;
}
.Label {
margin: 0;
font-size: 0.875rem;
font-weight: 500;
line-height: 1.25rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Description {
margin: 0.25rem 0 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Handle {
flex: none;
width: 1px;
background-color: oklch(92.2% 0 0deg);
outline: none;
cursor: col-resize;
@media (pointer: coarse) {
--resizable-handle-hit-area-size: 24px;
}
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
&[data-at-min] {
cursor: e-resize;
}
&[data-at-max] {
cursor: w-resize;
}
&[aria-orientation='horizontal'] {
width: auto;
height: 1px;
cursor: row-resize;
}
/*
* :where() adds no specificity, so each state rule below has the same specificity. The sequence
* of the rules then decides: an end, both ends, a crossing, disabled.
*/
&:where([aria-orientation='horizontal'])[data-at-min] {
cursor: s-resize;
}
&:where([aria-orientation='horizontal'])[data-at-max] {
cursor: n-resize;
}
&[data-at-min]:where([data-at-max]) {
cursor: default;
}
&[data-crossing] {
cursor: move;
}
&[aria-disabled='true'] {
cursor: default;
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}<script setup lang="ts">
import { Resizable } from '@vase-ui/vue/resizable';
</script>
<template>
<Resizable.Root
class="box-border h-48 w-full overflow-hidden rounded-md border border-neutral-200 dark:border-neutral-800"
>
<Resizable.Panel id="navigation" default-size="30" class="box-border overflow-hidden p-4">
<p class="text-sm font-medium text-neutral-950 dark:text-white">Navigation</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">The pages of the project.</p>
</Resizable.Panel>
<Resizable.Handle
aria-label="Resize the navigation"
class="w-px flex-none cursor-col-resize pointer-coarse:[--resizable-handle-hit-area-size:24px] bg-neutral-200 outline-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 data-at-max:cursor-w-resize data-at-min:cursor-e-resize data-at-min:data-at-max:cursor-default data-crossing:cursor-move data-at-min:data-at-max:data-crossing:cursor-move aria-disabled:cursor-default dark:bg-neutral-800 dark:focus-visible:outline-white"
/>
<Resizable.Panel id="main" class="overflow-hidden">
<Resizable.Root orientation="vertical" class="h-full">
<Resizable.Panel id="editor" class="box-border overflow-hidden p-4">
<p class="text-sm font-medium text-neutral-950 dark:text-white">Editor</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">
Press at the crossing to move both handles.
</p>
</Resizable.Panel>
<Resizable.Handle
primary-panel="next"
aria-label="Resize the terminal"
class="h-px flex-none cursor-row-resize pointer-coarse:[--resizable-handle-hit-area-size:24px] bg-neutral-200 outline-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 data-at-max:cursor-n-resize data-at-min:cursor-s-resize data-at-min:data-at-max:cursor-default data-crossing:cursor-move data-at-min:data-at-max:data-crossing:cursor-move aria-disabled:cursor-default dark:bg-neutral-800 dark:focus-visible:outline-white"
/>
<Resizable.Panel id="terminal" default-size="35" class="box-border overflow-hidden p-4">
<p class="text-sm font-medium text-neutral-950 dark:text-white">Terminal</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">
The output of the build.
</p>
</Resizable.Panel>
</Resizable.Root>
</Resizable.Panel>
</Resizable.Root>
</template>A handle with no size
A handle can have no size, such as a handle at the border of two panels. Its pointer target takes a press within 5 px of its center. The handle also has the keys, the focus and the role of each other handle. In the element slot, end your element with <span v-bind="targetProps" />, the pointer target of the handle.
Editor
Each handle has no size.
Preview
Its pointer target takes the press.
<script setup lang="ts">
import { Resizable } from '@vase-ui/vue/resizable';
import styles from './index.module.css';
</script>
<template>
<Resizable.Root :class="styles.Root">
<Resizable.Panel id="navigation" default-size="25" :class="styles.Panel">
<p :class="styles.Label">Navigation</p>
<p :class="styles.Description">Drag the line between two panels.</p>
</Resizable.Panel>
<Resizable.Handle aria-label="Resize the navigation" :class="styles.Handle" />
<Resizable.Panel id="editor" :class="styles.Panel">
<p :class="styles.Label">Editor</p>
<p :class="styles.Description">Each handle has no size.</p>
</Resizable.Panel>
<Resizable.Handle primary-panel="next" aria-label="Resize the preview" :class="styles.Handle" />
<Resizable.Panel id="preview" default-size="25" :class="styles.Panel">
<p :class="styles.Label">Preview</p>
<p :class="styles.Description">Its pointer target takes the press.</p>
</Resizable.Panel>
</Resizable.Root>
</template>.Root {
box-sizing: border-box;
width: 100%;
height: 12rem;
overflow: hidden;
border: 1px solid oklch(92.2% 0 0deg);
border-radius: 0.375rem;
@media (prefers-color-scheme: dark) {
border-color: oklch(26.9% 0 0deg);
}
}
.Panel {
box-sizing: border-box;
padding: 1rem;
overflow: hidden;
}
.Label {
margin: 0;
font-size: 0.875rem;
font-weight: 500;
line-height: 1.25rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Description {
margin: 0.25rem 0 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Handle + .Panel {
border-left: 1px solid oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
border-left-color: oklch(26.9% 0 0deg);
}
}
.Handle {
flex: none;
width: 0;
outline: none;
cursor: col-resize;
@media (pointer: coarse) {
--resizable-handle-hit-area-size: 24px;
}
&[data-at-min] {
cursor: e-resize;
}
&[data-at-max] {
cursor: w-resize;
}
&[data-at-min][data-at-max] {
cursor: default;
}
&[aria-disabled='true'] {
cursor: default;
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}<script setup lang="ts">
import { Resizable } from '@vase-ui/vue/resizable';
</script>
<template>
<Resizable.Root
class="box-border h-48 w-full overflow-hidden rounded-md border border-neutral-200 dark:border-neutral-800"
>
<Resizable.Panel id="navigation" default-size="25" class="box-border overflow-hidden p-4">
<p class="text-sm font-medium text-neutral-950 dark:text-white">Navigation</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">
Drag the line between two panels.
</p>
</Resizable.Panel>
<Resizable.Handle
aria-label="Resize the navigation"
class="w-0 flex-none cursor-col-resize pointer-coarse:[--resizable-handle-hit-area-size:24px] outline-none focus-visible:outline-2 focus-visible:outline-neutral-950 data-at-max:cursor-w-resize data-at-min:cursor-e-resize data-at-min:data-at-max:cursor-default aria-disabled:cursor-default dark:focus-visible:outline-white"
/>
<Resizable.Panel
id="editor"
class="box-border overflow-hidden p-4 border-l border-neutral-200 dark:border-neutral-800"
>
<p class="text-sm font-medium text-neutral-950 dark:text-white">Editor</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">Each handle has no size.</p>
</Resizable.Panel>
<Resizable.Handle
primary-panel="next"
aria-label="Resize the preview"
class="w-0 flex-none cursor-col-resize pointer-coarse:[--resizable-handle-hit-area-size:24px] outline-none focus-visible:outline-2 focus-visible:outline-neutral-950 data-at-max:cursor-w-resize data-at-min:cursor-e-resize data-at-min:data-at-max:cursor-default aria-disabled:cursor-default dark:focus-visible:outline-white"
/>
<Resizable.Panel
id="preview"
default-size="25"
class="box-border overflow-hidden p-4 border-l border-neutral-200 dark:border-neutral-800"
>
<p class="text-sm font-medium text-neutral-950 dark:text-white">Preview</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">
Its pointer target takes the press.
</p>
</Resizable.Panel>
</Resizable.Root>
</template>Panels that mount later
A panel that mounts with no entry in the layout gets its defaultSize, or an equal share, and the other panels make room for it. The root then emits update:modelValue alone, so v-model follows. A panel that unmounts keeps its entry in the layout, so it gets its size again when it mounts again. A keyed list that moves its panels keeps the size of each panel. A panel that KeepAlive holds gives its room to the other panels, and gets it again when it shows.
Editor
The code of the page.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Resizable } from '@vase-ui/vue/resizable';
import styles from './index.module.css';
const showPreview = shallowRef(false);
</script>
<template>
<div :class="styles.Wrapper">
<label :class="styles.Checkbox">
<input v-model="showPreview" type="checkbox" />
Show the preview
</label>
<Resizable.Root :class="styles.Root">
<Resizable.Panel id="editor" :class="styles.Panel">
<p :class="styles.Label">Editor</p>
<p :class="styles.Description">The code of the page.</p>
</Resizable.Panel>
<template v-if="showPreview">
<Resizable.Handle
primary-panel="next"
aria-label="Resize the preview"
:class="styles.Handle"
/>
<Resizable.Panel id="preview" default-size="40" :class="styles.Panel">
<p :class="styles.Label">Preview</p>
<p :class="styles.Description">The root gives room to this panel when it mounts.</p>
</Resizable.Panel>
</template>
</Resizable.Root>
</div>
</template>.Wrapper {
display: flex;
flex-direction: column;
gap: 0.75rem;
width: 100%;
}
.Checkbox {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Root {
box-sizing: border-box;
width: 100%;
height: 12rem;
overflow: hidden;
border: 1px solid oklch(92.2% 0 0deg);
border-radius: 0.375rem;
@media (prefers-color-scheme: dark) {
border-color: oklch(26.9% 0 0deg);
}
}
.Panel {
box-sizing: border-box;
padding: 1rem;
overflow: hidden;
}
.Label {
margin: 0;
font-size: 0.875rem;
font-weight: 500;
line-height: 1.25rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Description {
margin: 0.25rem 0 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Handle {
flex: none;
width: 1px;
background-color: oklch(92.2% 0 0deg);
outline: none;
cursor: col-resize;
@media (pointer: coarse) {
--resizable-handle-hit-area-size: 24px;
}
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
&[data-at-min] {
cursor: e-resize;
}
&[data-at-max] {
cursor: w-resize;
}
&[data-at-min][data-at-max] {
cursor: default;
}
&[aria-disabled='true'] {
cursor: default;
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}<script setup lang="ts">
import { shallowRef } from 'vue';
import { Resizable } from '@vase-ui/vue/resizable';
const showPreview = shallowRef(false);
</script>
<template>
<div class="flex w-full flex-col gap-3">
<label class="flex items-center gap-2 text-sm text-neutral-950 dark:text-white">
<input v-model="showPreview" type="checkbox" />
Show the preview
</label>
<Resizable.Root
class="box-border h-48 w-full overflow-hidden rounded-md border border-neutral-200 dark:border-neutral-800"
>
<Resizable.Panel id="editor" class="box-border overflow-hidden p-4">
<p class="text-sm font-medium text-neutral-950 dark:text-white">Editor</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">The code of the page.</p>
</Resizable.Panel>
<template v-if="showPreview">
<Resizable.Handle
primary-panel="next"
aria-label="Resize the preview"
class="w-px flex-none cursor-col-resize pointer-coarse:[--resizable-handle-hit-area-size:24px] bg-neutral-200 outline-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 data-at-max:cursor-w-resize data-at-min:cursor-e-resize data-at-min:data-at-max:cursor-default aria-disabled:cursor-default dark:bg-neutral-800 dark:focus-visible:outline-white"
/>
<Resizable.Panel id="preview" default-size="40" class="box-border overflow-hidden p-4">
<p class="text-sm font-medium text-neutral-950 dark:text-white">Preview</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">
The root gives room to this panel when it mounts.
</p>
</Resizable.Panel>
</template>
</Resizable.Root>
</div>
</template>Resize a panel from a script
A template ref of a panel gives collapse(), expand(), resize(size) and isCollapsed(). A method does not snap, and it does not collapse another panel. It works on a disabled panel and in a disabled root.
<script setup lang="ts">
import { nextTick, ref, useTemplateRef } from 'vue';
import { Resizable, type ResizableLayout } from '@vase-ui/vue/resizable';
const layout = ref<ResizableLayout>({});
const navigation = useTemplateRef('navigation');
function toggleNavigation() {
if (navigation.value?.isCollapsed()) navigation.value.expand();
else navigation.value?.collapse();
}
// The root is controlled, so the second method waits for the layout that the first one gave.
async function narrowThenCollapse() {
navigation.value?.resize('10rem');
await nextTick();
navigation.value?.collapse();
}
</script>
<template>
<button type="button" @click="toggleNavigation">Toggle the navigation</button>
<button type="button" @click="narrowThenCollapse">Narrow, then collapse</button>
<Resizable.Root v-model="layout">
<Resizable.Panel id="navigation" ref="navigation" collapsible :min-size="15" />
<Resizable.Handle aria-label="Resize the navigation" />
<Resizable.Panel id="editor" />
</Resizable.Root>
</template>In an uncontrolled root, a second method starts from the layout of the first. In a controlled root, each method starts from the layout of the parent, and the panel shows the change only after the parent writes it. Call a second method after await nextTick(), and read isCollapsed() after it.
Save the layout
Give v-model a ref that you keep in a storage, so that the user gets the layout again at the next visit. Read the storage after the mount, because a server has no storage. Put try and catch around the read, JSON.parse and the write: a browser that blocks the data of the site throws. Save at layoutCommitted to write one time for each change of the user.
Editor
The layout stays in the storage of the browser.
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { Resizable, type ResizableLayout } from '@vase-ui/vue/resizable';
import styles from './index.module.css';
const key = 'vase-ui-docs-resizable';
const layout = ref<ResizableLayout>({});
// A server has no storage, so the page reads it after the mount. A browser that blocks the data
// of the site throws. The root ignores an entry that is not a size.
onMounted(() => {
try {
const saved: unknown = JSON.parse(localStorage.getItem(key) ?? '{}');
if (saved !== null && typeof saved === 'object') layout.value = saved as ResizableLayout;
} catch {
layout.value = {};
}
});
// One commit comes for each change of the user.
function save(committed: ResizableLayout) {
try {
localStorage.setItem(key, JSON.stringify(committed));
} catch {
// The layout stays for this visit only.
}
}
</script>
<template>
<Resizable.Root v-model="layout" :class="styles.Root" @layout-committed="save">
<Resizable.Panel id="navigation" default-size="30" :class="styles.Panel">
<p :class="styles.Label">Navigation</p>
<p :class="styles.Description">Resize the panels, then load the page again.</p>
</Resizable.Panel>
<Resizable.Handle aria-label="Resize the navigation" :class="styles.Handle" />
<Resizable.Panel id="editor" :class="styles.Panel">
<p :class="styles.Label">Editor</p>
<p :class="styles.Description">The layout stays in the storage of the browser.</p>
</Resizable.Panel>
</Resizable.Root>
</template>.Root {
box-sizing: border-box;
width: 100%;
height: 12rem;
overflow: hidden;
border: 1px solid oklch(92.2% 0 0deg);
border-radius: 0.375rem;
@media (prefers-color-scheme: dark) {
border-color: oklch(26.9% 0 0deg);
}
}
.Panel {
box-sizing: border-box;
padding: 1rem;
overflow: hidden;
}
.Label {
margin: 0;
font-size: 0.875rem;
font-weight: 500;
line-height: 1.25rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Description {
margin: 0.25rem 0 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Handle {
flex: none;
width: 1px;
background-color: oklch(92.2% 0 0deg);
outline: none;
cursor: col-resize;
@media (pointer: coarse) {
--resizable-handle-hit-area-size: 24px;
}
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
&[data-at-min] {
cursor: e-resize;
}
&[data-at-max] {
cursor: w-resize;
}
&[data-at-min][data-at-max] {
cursor: default;
}
&[aria-disabled='true'] {
cursor: default;
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { Resizable, type ResizableLayout } from '@vase-ui/vue/resizable';
const key = 'vase-ui-docs-resizable';
const layout = ref<ResizableLayout>({});
// A server has no storage, so the page reads it after the mount. A browser that blocks the data
// of the site throws. The root ignores an entry that is not a size.
onMounted(() => {
try {
const saved: unknown = JSON.parse(localStorage.getItem(key) ?? '{}');
if (saved !== null && typeof saved === 'object') layout.value = saved as ResizableLayout;
} catch {
layout.value = {};
}
});
// One commit comes for each change of the user.
function save(committed: ResizableLayout) {
try {
localStorage.setItem(key, JSON.stringify(committed));
} catch {
// The layout stays for this visit only.
}
}
</script>
<template>
<Resizable.Root
v-model="layout"
class="box-border h-48 w-full overflow-hidden rounded-md border border-neutral-200 dark:border-neutral-800"
@layout-committed="save"
>
<Resizable.Panel id="navigation" default-size="30" class="box-border overflow-hidden p-4">
<p class="text-sm font-medium text-neutral-950 dark:text-white">Navigation</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">
Resize the panels, then load the page again.
</p>
</Resizable.Panel>
<Resizable.Handle
aria-label="Resize the navigation"
class="w-px flex-none cursor-col-resize pointer-coarse:[--resizable-handle-hit-area-size:24px] bg-neutral-200 outline-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 data-at-max:cursor-w-resize data-at-min:cursor-e-resize data-at-min:data-at-max:cursor-default aria-disabled:cursor-default dark:bg-neutral-800 dark:focus-visible:outline-white"
/>
<Resizable.Panel id="editor" class="box-border overflow-hidden p-4">
<p class="text-sm font-medium text-neutral-950 dark:text-white">Editor</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">
The layout stays in the storage of the browser.
</p>
</Resizable.Panel>
</Resizable.Root>
</template>The layout of each event has the pixels of each fixed panel, so each fixed panel keeps its pixels. The page reads the storage after the mount, so the server HTML has the first layout, and the panels move to the stored layout at the mount. For an exact server HTML, keep the layout in a cookie and give it to v-model, as this Nuxt component does. The useCookie ref of Nuxt is a ref that the server reads too:
<script setup lang="ts">
import { ref } from 'vue';
import { useCookie } from '#imports';
import { Resizable, type ResizableLayout } from '@vase-ui/vue/resizable';
const saved = useCookie<ResizableLayout | undefined>('resizable-layout');
// The server reads the cookie too, so its HTML has the saved layout. A visitor can change the
// cookie. The root ignores an entry that is not a size, so the cookie needs no check.
const layout = ref<ResizableLayout>(saved.value ?? { 'c-a': 25, 'c-b': 75 });
// One commit comes for each change of the user. The layout has the pixels of the fixed panel,
// so the panel keeps its width at the next visit.
function save(committed: ResizableLayout) {
saved.value = committed;
}
</script>
<template>
<Resizable.Root
v-model="layout"
data-testid="cookie"
style="width: 600px; height: 80px"
@layout-committed="save"
>
<Resizable.Panel id="c-a" data-testid="c-a" root-resize-behavior="fixed" />
<Resizable.Handle
data-testid="cookie-handle"
aria-label="Resize the first panel"
style="width: 0"
/>
<Resizable.Panel id="c-b" data-testid="c-b" />
</Resizable.Root>
</template>Resize at the release
With resizeMode="on-release", a drag leaves the layout as it is, and the release changes it one time. During the drag, each handle that the drag moves has the CSS variable --resizable-handle-preview-offset: the distance to the place that the release gives it. Use it to show a line at that place.
Editor
The code of the page.
<script setup lang="ts">
import { Resizable } from '@vase-ui/vue/resizable';
import styles from './index.module.css';
</script>
<template>
<Resizable.Root resize-mode="on-release" :class="styles.Root">
<Resizable.Panel id="navigation" default-size="30" :class="styles.Panel">
<p :class="styles.Label">Navigation</p>
<p :class="styles.Description">A drag shows a line, and the panels change at the release.</p>
</Resizable.Panel>
<Resizable.Handle aria-label="Resize the navigation" :class="styles.Handle" />
<Resizable.Panel id="editor" :class="styles.Panel">
<p :class="styles.Label">Editor</p>
<p :class="styles.Description">The code of the page.</p>
</Resizable.Panel>
</Resizable.Root>
</template>.Root {
box-sizing: border-box;
width: 100%;
height: 12rem;
overflow: hidden;
border: 1px solid oklch(92.2% 0 0deg);
border-radius: 0.375rem;
@media (prefers-color-scheme: dark) {
border-color: oklch(26.9% 0 0deg);
}
}
.Panel {
box-sizing: border-box;
padding: 1rem;
overflow: hidden;
}
.Label {
margin: 0;
font-size: 0.875rem;
font-weight: 500;
line-height: 1.25rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Description {
margin: 0.25rem 0 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Handle {
flex: none;
width: 1px;
background-color: oklch(92.2% 0 0deg);
outline: none;
cursor: col-resize;
@media (pointer: coarse) {
--resizable-handle-hit-area-size: 24px;
}
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
&[data-at-min] {
cursor: e-resize;
}
&[data-at-max] {
cursor: w-resize;
}
&[data-at-min][data-at-max] {
cursor: default;
}
&::after {
content: '';
position: absolute;
inset: 0;
display: none;
background-color: oklch(14.5% 0 0deg);
translate: var(--resizable-handle-preview-offset, 0px) 0;
@media (prefers-color-scheme: dark) {
background-color: white;
}
}
&[data-dragging]::after {
display: block;
}
&[aria-disabled='true'] {
cursor: default;
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}<script setup lang="ts">
import { Resizable } from '@vase-ui/vue/resizable';
</script>
<template>
<Resizable.Root
resize-mode="on-release"
class="box-border h-48 w-full overflow-hidden rounded-md border border-neutral-200 dark:border-neutral-800"
>
<Resizable.Panel id="navigation" default-size="30" class="box-border overflow-hidden p-4">
<p class="text-sm font-medium text-neutral-950 dark:text-white">Navigation</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">
A drag shows a line, and the panels change at the release.
</p>
</Resizable.Panel>
<Resizable.Handle
aria-label="Resize the navigation"
class="w-px flex-none cursor-col-resize pointer-coarse:[--resizable-handle-hit-area-size:24px] bg-neutral-200 outline-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 data-at-max:cursor-w-resize data-at-min:cursor-e-resize data-at-min:data-at-max:cursor-default after:absolute after:inset-0 after:hidden after:translate-x-(--resizable-handle-preview-offset) after:bg-neutral-950 data-dragging:after:block dark:after:bg-white aria-disabled:cursor-default dark:bg-neutral-800 dark:focus-visible:outline-white"
/>
<Resizable.Panel id="editor" class="box-border overflow-hidden p-4">
<p class="text-sm font-medium text-neutral-950 dark:text-white">Editor</p>
<p class="mt-1 text-sm text-neutral-600 dark:text-neutral-400">The code of the page.</p>
</Resizable.Panel>
</Resizable.Root>
</template>Stop F6
F6 moves the focus from panel to panel, also in a disabled root. To stop it, call event.preventDefault() in a keydown listener in a panel, or in a capture listener of the root:
<script setup lang="ts">
import { Resizable } from '@vase-ui/vue/resizable';
</script>
<template>
<Resizable.Root
@keydown.capture="
(event: KeyboardEvent) => {
if (event.key === 'F6') event.preventDefault();
}
"
>
<Resizable.Panel />
<Resizable.Handle aria-label="Resize the first panel" />
<Resizable.Panel />
</Resizable.Root>
</template>Render on the server
The server HTML has the layout of all the parts: the size of each panel, and the value and the ends of each handle. A server cannot measure the page, so a panel whose first size is a length renders flex: 0 1 <length> until the first measurement, which comes after the mount. The other panels share the rest. Each handle of that root gets its value at the first measurement. The hydration moves no panel and shows no message.
These can move at the mount:
- A panel below an async
setupor in a lazy component. The panels beside it render the server HTML without it. - A length constraint, such as
min-size="12rem", that the first layout breaks. A length constraint applies from the first measurement. - A layout that the page reads after the mount, such as a layout in a storage.
- A handle that is not disabled, before the first panel or after the last panel. The server HTML gives it a tab stop and a pointer target that takes a press. After the mount, it has neither.
A server reads only the dir attribute of Resizable.Root. In a right-to-left page, set dir="rtl" on Resizable.Root, so that the server HTML has the correct data-at-min and data-at-max of each handle.
Keyboard
| Key | Action |
|---|---|
| Arrow keys | Move the handle on the axis of the root by step, in the direction of the key on the screen. |
| Shift and an arrow key | Move the handle by largeStep. |
| Page Up and Page Down | Grow and shrink the primary panel by largeStep. |
| Home and End | Give the primary panel its least and its greatest size. |
| Enter | Collapse a collapsible primary panel, or give it its size again. |
| F6 and Shift+F6 | Move the focus to the first control of the next or the previous panel. A panel with a size of 0 or with no control gets no focus. At its end, a root in a panel of another root gives the key to that root. Another root starts again at its other end. |
| A key with Ctrl, Alt or Meta | Nothing. The browser gets the key. |
API reference
Resizable.Root
Groups the panels and the handles of the layout, with display: flex in the direction of
orientation. An element in the root that is not a panel or a handle, such as a toolbar, keeps
its CSS size.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
defaultLayout | ResizableLayout | null | undefined | The first layout of an uncontrolled root, and the first sizes for a double click. | |
disabled | boolean | undefined | Each handle ignores the user. | |
dragStep | number | string | undefined | A drag moves a handle in steps of this size. A size, as step. A key and a method do not use
it. | |
largeStep | number | string | undefined | 10 | The move of Shift with an arrow key, of Page Up and of Page Down. A size, as step. |
modelValue | ResizableLayout | null | undefined | The layout. {} and null give each panel its first size, and the root stays controlled. An
entry that is not a size has no effect. | |
orientation | "horizontal" | "vertical" | undefined | 'horizontal' | 'vertical' puts the panels in a column, and ArrowUp and ArrowDown move the handles. |
pushPanels | boolean | undefined | true | A move continues into the panels after the panel beside the handle. |
resizeMode | ResizableRootResizeMode | undefined | 'live' | When a drag changes the layout. A key, a double click and a method change it at once. |
step | number | string | undefined | 1 | The move of an arrow key. A size: a number is percent of the panel space, and em is the font
size of the root. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ResizableRootStatesizes: Readonly<Record<string, number>> | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ResizableRootState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Events
| Event | Arguments | Description |
|---|---|---|
layoutChange | [layout: ResizableLayout, details: ResizableRootChangeEventDetails] | The user changes the layout. details.cancel() keeps the layout. A listener can then write its
own layout to v-model, such as a layout that snaps to a rule of the app. |
update:modelValue | [layout: ResizableLayout] | Comes after layoutChange, unless a listener cancelled it. Also comes alone after a method of a
panel, and after a panel that mounts with no entry. A change of the size of the root emits
nothing. |
layoutCommitted | [layout: ResizableLayout, details: ResizableRootCommitEventDetails] | The user ends a change: the release of a drag, a key, a double click. |
draggingChange | [dragging: boolean] | A drag starts, and it ends. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-orientation] | The orientation of the root: horizontal or vertical. |
[data-disabled] | The root is disabled. |
[data-dragging] | The user drags a handle of the root. |
Resizable.Panel
A part of the layout that a handle resizes. A collapsible panel can collapse to a small size.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
collapsedSize | number | string | undefined | 0 | The size of the collapsed panel, in the form of defaultSize. A panel whose first size is
collapsedSize starts collapsed, with no event. |
collapseThreshold | number | string | undefined | The distance that a drag passes below minSize to collapse the panel, or above
collapsedSize to expand it. The default is half of the distance between the two sizes. | |
collapsible | boolean | undefined | The panel collapses to collapsedSize below minSize. Give it a minSize greater than its
collapsedSize. | |
defaultSize | number | string | undefined | The first size, when the layout has no entry for the panel. A number is percent of the panel
space. A string can have a unit: %, px, em (the font size of the panel), rem, vw or
vh. The panels with no first size share the rest of the space in equal parts. A later change
has no effect. | |
disabled | boolean | undefined | A move of a handle goes through the panel to the next panel, and leaves its size. The methods of the panel and the layout of the root still change its size. | |
id | string | undefined | The id of the element, and the key of the panel in the layout. With none, the panel gets a
generated id. | |
maxSize | number | string | undefined | 100 | The greatest size, in the form of defaultSize. |
minSize | number | string | undefined | 0 | The least size, in the form of defaultSize. |
rootResizeBehavior | "proportional" | "fixed" | undefined | 'proportional' | 'fixed' keeps the pixels of the panel when the root changes size. |
rootResizePriority | number | undefined | 0 | When the other panels cannot take a size change of the root, the fixed panel with the greater number changes size first. |
snapPoints | readonly (string | number)[] | undefined | A drag that comes within snapTolerance of a point gives the panel that size. A key and a
method do not snap. | |
snapTolerance | number | string | undefined | '10px' | The distance from a snap point at which a drag snaps to it. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ResizablePanelState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ResizablePanelState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Events
| Event | Arguments | Description |
|---|---|---|
collapsedChange | [collapsed: boolean] | The panel collapses or expands, after the DOM update. Not at the mount. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
collapse | () => void | Collapses the panel to its collapsedSize. No other panel collapses for it. |
expand | () => void | Gives a collapsed panel the size from before the collapse, else its minSize. No other panel
collapses for it. |
resize | (wanted: string | number) => void | Gives the panel a size, as far as the constraints allow. No other panel collapses for it. |
isCollapsed | () => boolean | Returns true while the panel is collapsed. |
Selectors
| Selector | Description |
|---|---|
[data-orientation] | The orientation of the root: horizontal or vertical. |
[data-collapsed] | The panel is collapsed. |
[data-disabled] | The panel is disabled. |
CSS variables
| Variable | Description |
|---|---|
--resizable-panel-size | The size of the panel in percent of the panel space, as a number with no unit. A panel whose first size is a length gets it at the first measurement. |
Resizable.Handle
The separator between two panels. The user drags it or presses a key on it to resize the panels.
Enter collapses or expands the primary panel, and a double click gives it its first size.
The handle ends with a <span>, its pointer target. The handle has position: relative to
contain it. In the element slot, render the span with targetProps.
A press focuses the handle with no focus ring, where the browser has the focusVisible option of
focus(). A handle before the first panel or after the last panel moves nothing, and it has no
tab stop and no value.
Renders a <div> element with the role separator.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | undefined | The handle ignores the user. | |
primaryPanel | "previous" | "next" | undefined | 'previous' | The panel that the value, aria-controls, Home, End, Page Up, Page Down, Enter and the double
click are about. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ResizableHandleState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ResizableHandleStatetargetProps: Record<string, unknown> | Renders your element in place of the element of the handle. Bind props with v-bind and
elementRef with :ref. End your element with <span v-bind="targetProps" />, the pointer
target of the handle. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[aria-orientation] | The orientation of the handle: vertical in a horizontal root, and horizontal in a vertical root. |
[aria-disabled="true"] | The handle or the root is disabled. The handle then has no tab stop. |
[data-dragging] | The user drags the handle. |
[data-crossing] | The pointer is where the handle crosses a handle of another root, and a press there drags both. |
[data-at-min] | The handle cannot move left, or up in a vertical root. The sides are those of the screen, also in a right-to-left root. |
[data-at-max] | The handle cannot move right, or down in a vertical root. The sides are those of the screen, also in a right-to-left root. |
CSS variables
| Variable | Description |
|---|---|
--resizable-handle-hit-area-size | The least size of the pointer target on the axis of the move. Set it to give another size than 10px. |
--resizable-handle-preview-offset | In the resize mode on-release, the distance from the handle to the place that the release gives it, during a drag. |
ResizableLayout
The size of each panel by panel id. An entry is a number in percent, or a string of a number with a unit, such as '240px'.
ResizableRootResizeMode
When a drag changes the layout: at each move, or one time at the release.
'live' | 'on-release'
ResizableRootChangeEventReason
The action of the user that changes the layout: 'drag' is a drag of a handle, 'keyboard' a key on a handle, and 'reset' a double click on a handle.
'drag' | 'keyboard' | 'reset'
ResizableRootChangeEventDetails
The details of layoutChange.
| Property | Type | Description |
|---|---|---|
cancel | () => void | |
event | Event | |
isCanceled | boolean | |
reason | ResizableRootChangeEventReason |
ResizableRootCommitEventDetails
The details of layoutCommitted.
| Property | Type | Description |
|---|---|---|
event | Event | |
reason | ResizableRootChangeEventReason |
Differences from Base UI
Base UI has no Resizable. A person drags a handle, or presses a key on it, to give the panels beside it new sizes, as the window splitter pattern describes.
- https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/
- https://www.w3.org/TR/wai-aria-1.2/#separator
- https://www.w3.org/TR/WCAG22/#target-size-minimum
The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.