The initial splitter position is determined by the default size of the two content area components.
Their height and width affect the position when using a vertical and horizontal orientation, respectively.
The initial split position can also be explicitly set using a percentage value.
When using vertical orientation, the split layout must have an explicit height for this to work.
This can be either an absolute or a percentage value.
When using a percentage value, ensure that ancestors have an explicit height as well.
package com.vaadin.demo.component.splitlayout;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.splitlayout.SplitLayout;
import com.vaadin.flow.router.Route;
@Route("split-layout-initial-splitter-position")
public class SplitLayoutInitialSplitterPosition extends Div {
public SplitLayoutInitialSplitterPosition() {
// tag::snippet[]
MasterContent master = new MasterContent();
DetailContent detail = new DetailContent();
SplitLayout splitLayout = new SplitLayout(master, detail);
// Sets the width for the first child to 70%, giving
// the second child the remaining width of 30%
splitLayout.setSplitterPosition(70);
// end::snippet[]
splitLayout.setMaxHeight("280px");
add(splitLayout);
}
}
split-layout-initial-splitter-position.tsx
import React from 'react';
import { SplitLayout } from '@vaadin/react-components/SplitLayout.js';
import DetailContent from './detail-content';
import MasterContent from './master-content';
function Example() {
return (
// tag::snippet[]
<SplitLayout style={{ maxHeight: '280px' }}>
<MasterContent style={{ width: '70%' }} />
<DetailContent style={{ width: '30%' }} />
</SplitLayout>
// end::snippet[]
);
}
The split handle can be focused and operated with the keyboard, allowing users to resize the content areas without a pointing device. Clicking the handle moves focus to it, while dragging it leaves focus unchanged so as not to interrupt pointer interaction.
When the handle has focus, it can be moved with the following keys:
Shortcut
Function
Right / Down
Grows the primary content area by a small step.
Left / Up
Shrinks the primary content area by a small step.
Page Down
Grows the primary content area by a larger step.
Page Up
Shrinks the primary content area by a larger step.
Home
Collapses the primary content area.
End
Collapses the secondary content area.
The arrow key directions are reversed automatically for right-to-left languages.
The handle has a default accessible name, Resize separator, which can be customized:
Source code
Java
SplitLayout layout = new SplitLayout();
SplitLayoutI18n i18n = new SplitLayoutI18n()
.setSeparator("Resize separator");
layout.setI18n(i18n);
Don’t use Split Layout when either content area has, or should have, a fixed size.
Split Layouts can be difficult to use in responsive applications, due to the splitter position being percentage-based, so that the content scales with the viewport.
Use Split Layout to give the user the ability to adjust the layout.
However, if only specific positions, such as collapsed and expanded, are useful to the user, use a toggle button instead.
Non-adjustable layouts should use Ordered Layouts or Flex Layout.