nextui-org / nextui

🚀 Beautiful, fast and modern React UI library.
https://nextui.org
MIT License
21.96k stars 1.53k forks source link

[Feature Request] Selection Mode in Button Group #639

Closed ghost closed 2 years ago

ghost commented 2 years ago

Is your feature request related to a problem? Please describe.

I got a requirement that displays selected button in button group. (Like radio button!) But there is no selected prop or selection mode in Button Group.

Describe the solution you'd like

So I overwrite selected button's css like this:

<Button.Group flat>
  <Button css={someBoolean ? { color: "$primarySolidContrast", bgColor: "$primary" } : undefined}>
    Selected Button
  </Button>
</Button.Group>

image

Describe alternatives you've considered

Do you have a roadmap about this already? I would be very happy if this feature is built in :)

Screenshots or Videos

No response

MForMarlon commented 2 years ago

Here's a workaround where I am using the ButtonGroup like tabs:

const [activeTab, setActiveTab] = useState('a');
...
<Button.Group size="xl">
  <Button
    onClick={() => setActiveTab('a')}
    light={activeTab !== 'a'}
    bordered={activeTab === 'a'}>a</Button>
  <Button
    onClick={() => setActiveTab('b')}
    light={activeTab !== 'b'}
    bordered={activeTab === 'b'}>b</Button>
  <Button
    onClick={() => setActiveTab('c')}
    light={activeTab !== 'c'}
    bordered={activeTab === 'c'}>c</Button>
</Button.Group>
aed0nis commented 2 years ago

Would be good to have this in the documentation.