Skip to content
Harness Design System Harness Design System Harness Design System

ButtonWithOptions

The ButtonWithOptions component provides a flexible UI element combining a button with a dropdown menu of options. It can be used in two different modes:

  • Regular dropdown menu (default behavior)
  • Radio button selection group (when selectedValue is provided)

Note: Unlike the standard Button component, ButtonWithOptions does not support different sizes. It automatically inherits the default size from the underlying Button component.

Usage

import { ButtonWithOptions } from '@harnessio/ui/components'
// Basic usage with default solid+primary combination
const options = [
{ value: 'option1', label: 'Option 1', description: 'Description for option 1' },
{ value: 'option2', label: 'Option 2', description: 'Description for option 2' },
]
// Default combination (solid variant with primary theme)
<ButtonWithOptions
id="my-button"
handleButtonClick={() => console.log('Button clicked')}
options={options}
handleOptionChange={(value) => console.log('Selected:', value)}
>
Default Button
</ButtonWithOptions>
// Surface variant with success theme
<ButtonWithOptions
id="success-button"
variant="surface"
theme="success"
handleButtonClick={() => console.log('Button clicked')}
options={options}
handleOptionChange={(value) => console.log('Selected:', value)}
>
Success Button
</ButtonWithOptions>
// As a radio button group
<ButtonWithOptions
id="radio-button"
handleButtonClick={() => console.log('Button clicked')}
selectedValue="option1"
options={options}
handleOptionChange={(value) => console.log('Selected:', value)}
>
With Selected Value
</ButtonWithOptions>

Allowed Combinations

The ButtonWithOptions component has specific rules for variant and theme combinations.

Radio Button Selection

When providing a selectedValue, the dropdown behaves as a radio button group.

States

The component supports various states like loading and disabled.

API Reference

PropRequiredDefaultType
idtruestring
handleButtonClicktrue(e: MouseEvent) => void
optionstrue{ value: string; label: string; description?: string }[]
handleOptionChangetrue(val: string) => void
selectedValuefalsestring
loadingfalsefalseboolean
disabledfalsefalseboolean
variantfalse'solid''solid' | 'surface'
themefalse'primary''primary' | 'success' | 'danger' | 'muted'
childrentrueReactNode
classNamefalsestring
buttonClassNamefalsestring
dropdownContentClassNamefalsestring