Button Group

A Button Group component is a UI element that groups multiple buttons together, allowing users to select from a set of related actions or options. It helps organize buttons in a compact, cohesive layout, typically displayed in a horizontal or vertical row. Button Groups are useful for actions that are closely related or mutually exclusive, providing a clean and structured way to present multiple controls.

Demo

Rendered live, with the same build of the library you install.

Usage

ButtonGroup.tsx
import { useState } from 'react';
import { NButtonGroup } from '@nayan-ui/react';
const items = ['Startup', 'Business', 'Enterprise'];
const ButtonGroup = () => {
const [selected, setSelected] = useState(items[0]);
return (
<div>
<NButtonGroup items={items} selected={selected} onChange={setSelected} />
</div>
);
};
export default ButtonGroup;

Attributes

13 props
NameTypeDefaultDetails
classNamestring' 'You can customise by passing tailwind classes.
buttonClassNamestring' 'You can customise by passing tailwind classes.
itemsT[]RequiredYou can pass items for the button group.
selectedTRequiredYou can pass default selected item.
disabledbooleanfalseYou can pass disable state to disable items.
onChange(selected: T) => voidRequiredYou can get callback when button group changed.
keyExtractor(item: T, idx: number) => string | numberOptionalCustom key extractor function.
renderButton(item: T, selected: boolean, idx: number) => React.ReactNodeOptionalCustom render function for buttons.
ariaLabelstringOptionalARIA label for accessibility.
valueTOptionalAlias of selected.
getKey(item: T, index: number) => React.KeyOptionalCustom key extractor for items.
renderItem(item: T, index: number) => ReactNodeOptionalCustom render function for button items.
size'sm' | 'md' | 'lg''md'Size of the button group.

Tags

Other components solving nearby problems.