Button Group

A container that groups related buttons together with consistent styling.

Installation

npx nx g @spartan-ng/cli:ui button-group

Usage

import { 
	HlmButtonGroup, 
	HlmButtonGroupSeparator, 
	HlmButtonGroupText 
} from '@spartan-ng/helm/button-group';
<div hlmButtonGroup>
	<div hlmButtonGroup>
		<button hlmBtn variant="outline">Button 1</button>
		<button hlmBtn variant="outline">Button 2</button>
	</div>
	<hlm-button-group-separator />
	<div hlmButtonGroup>
		<span hlmButtonGroupText>Text</span>
	</div>
</div>

Accessibility

  • The HlmButtonGroup directive has the role attribute set to group .
  • Use Tab to navigate between the buttons in the group.
  • Use aria-label or aria-labelledby to label the button group.
<div hlmButtonGroup aria-label="Button group">
	<button hlmBtn variant="outline">Button 1</button>
	<button hlmBtn variant="outline">Button 2</button>
</div>

ButtonGroup vs ToggleGroup

  • Use the ButtonGroup component when you want to group buttons that perform an action.
  • Use the ToggleGroup component when you want to group buttons that toggle a state.

Examples

Orientation

Set the orientation prop to change the button group layout.

Size

Control the size of buttons using the size prop on individual buttons.

Nested

Nest HlmButtonGroup to create button groups with spacing.

Separator

The HlmButtonGroupSeparator component visually divides buttons within a group.

Buttons with variant outline do not need a separator since they have a border. For other variants, a separator is recommended to improve the visual hierarchy.

Split

Create a split button group by adding two buttons separated by a HlmButtonGroupSeparator .

With text

Add text to the button group using the HlmButtonGroupText component.

https://

Input

Wrap an Input component with buttons.

Dropdown Menu

Create a split button group with a HlmDropdownMenu component .

Select

Pair with a Select component.

Popover

Use with a Popover component.

Helm API

HlmButtonGroupSeparator

Selector: [hlmButtonGroupSeparator],hlm-button-group-separator

Inputs

PropTypeDefaultDescription
class ClassValue --

HlmButtonGroupText

Selector: [hlmButtonGroupText]

Inputs

PropTypeDefaultDescription
class ClassValue --

HlmButtonGroup

Selector: [hlmButtonGroup]

Inputs

PropTypeDefaultDescription
class ClassValue --
orientation 'horizontal' | 'vertical' horizontal -
Calendar Button