Layout

Group

Visually connect related controls.

Installation

pnpm dlx @mielui/svelte add group

Usage

Put controls directly inside Group.Root with a Group.Separator between each pair, including outline buttons; separators draw the seams. Name the group with aria-label or aria-labelledby. Tab moves between controls as usual.

<script lang="ts">
    import { Button } from '@mielui/svelte/components/button';
    import * as Group from '@mielui/svelte/components/group';
</script>

<Group.Root aria-label="Page navigation">
    <Button variant="outline">Previous</Button>
    <Group.Separator />
    <Button variant="outline">Next</Button>
</Group.Root>

In a horizontal group, inputs and text match the height of the buttons. Give every button in a group the same size.

Use Group for actions and Toggle Group for controls that select a state. Group adds no arrow-key navigation or selection.

Examples

Undo and redo

Two joined buttons step through a list of revisions and disable at each end.

Vertical

Set orientation="vertical" on Root and orientation="horizontal" on each Separator to stack controls.

Text and labels

Group.Text renders a div. Set as="label" and for when the text labels an input.

With input

Nested groups

Nested roots keep their own rounded ends with a gap between them.

With popover

With menu

Composition

Controls keep their own sizes, variants, focus rings, events, and disabled states. Joined controls share one hairline seam and flat inner corners; the outer ends keep the control radius, and a focused control sits above its neighbors. Filled buttons keep their ring. Hidden form inputs do not affect which visible control gets the rounded ends.

Root and Separator take orientation, horizontal or vertical. Root defaults to horizontal and Separator to vertical; Separator is hidden from assistive technology. Text takes an element name through as. Every part passes native attributes, class, and event handlers to its element.

API reference

Group.Root

Connects related controls.

  • orientation
    "horizontal" | "vertical"

    Direction the controls are joined in.

    Default 'horizontal'

Group.Separator

Divides adjacent controls.

  • orientation
    "horizontal" | "vertical"

    Direction of the line. Use vertical between controls in a horizontal group.

    Default 'vertical'

Group.Text

Renders a prefix, suffix or label.

  • as
    keyof HTMLElementTagNameMap

    Element to render, such as label or span. Defaults to div.

    Default 'div'

  • for
    string

    Id of the control a label element describes.