Alert Avatar AvatarGroup Button ButtonGroup Checkbox CheckboxGroup FilePicker Form FormRow Hamburger Input Modal Option Radio RadioGroup Rating Select Spinner Textarea Toast Tooltip Toggle

ButtonGroup

A ButtonGroup is used to group child Button components together as a single element. They can be used to create a segmented control for plain buttons with an on:click directive.

Example

<script>
  import { ButtonGroup, Button } from '$lib/ui';
  let whichway = $state();

  function handleClick(val) {
    whichway = val;
  }
</script>

<ButtonGroup>
  <Button
    on:click={() => handleClick('left')}
    active={whichway === 'left'}
  >
    Left
  </Button>
  <Button
    on:click={() => handleClick('middle')}
    active={whichway === 'middle'}
  >
    Middle
  </Button>
  <Button
    on:click={() => handleClick('right')}
    active={whichway === 'right'}
  >
    Right
  </Button>
</ButtonGroup>

<p>whichway: {whichway}</p>

whichway:


Size

Use the size prop on the ButtonGroup to set the size for all child Buttons.

<ButtonGroup size="sm">
  <Button>A</Button>
  <Button>B</Button>
  <Button>C</Button>
</ButtonGroup>

ButtonGroup Component Props

Name Type Default Description
sizeString: 'xs', 'sm', 'md', 'lg', or 'xl''md'Size to be used for all child Button components
classString CSS classes declared in global scope can be applied to the outermost element
...  Additional props will be passed through to the HTML element enabling support for things like disabled, on:click, target="_blank", etc

ButtonGroup CSS Custom Properties

Name Type Default Description
--ui-button-group-border-widthNumeric0Border width
--ui-button-group-border-colorColornoneBorder color
--ui-button-group-border-radiusNumeric--ui-button-border-radius, --ui-border-radius, 3pxBorder radius
--ui-button-group-shadowBox shadow shorthand--ui-button-shadow,
0 2px 2px 0 rgba(0, 0, 0, 0.2)
CSS box shadow shorthand
Remember that because the ButtonGroup component is a wrapper for Button components, you can also set style-props for Buttons like --ui-button-background and the Buttons contained within the group will be styled accordingly.