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.
<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:
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>
Name | Type | Default | Description |
---|---|---|---|
size | String: 'xs', 'sm', 'md', 'lg', or 'xl' | 'md' | Size to be used for all child Button components |
class | String | 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 |
Name | Type | Default | Description |
---|---|---|---|
--ui-button-group-border-width | Numeric | 0 | Border width |
--ui-button-group-border-color | Color | none | Border color |
--ui-button-group-border-radius | Numeric | --ui-button-border-radius , --ui-border-radius , 3px | Border radius |
--ui-button-group-shadow | Box shadow shorthand | --ui-button-shadow ,0 2px 2px 0 rgba(0, 0, 0, 0.2) | CSS box shadow shorthand |
--ui-button-background
and the Buttons
contained within the group will be styled accordingly.