-
Notifications
You must be signed in to change notification settings - Fork 7
feat(design-system): add DsSplitButton component [AR-54024]
#347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iromanchuk-dn
merged 17 commits into
drivenets:main
from
iromanchuk-dn:AR-54024-design-system-split-button
Apr 15, 2026
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
51977d0
feat(design-system): add `DsSplitButton` component [AR-54024]
iromanchuk-dn 6f82b6c
Update inline comment
iromanchuk-dn 29a2d5a
Merge branch 'main' of github.com:drivenets/design-system into AR-540…
iromanchuk-dn 2f53c07
Merge branch 'main' of github.com:drivenets/design-system into AR-540…
iromanchuk-dn cca6e3c
use DsButtonV3 and fixes to Input based components
iromanchuk-dn 2e13f71
add browser tests
iromanchuk-dn 6ce88da
Merge branch 'main' of github.com:drivenets/design-system into AR-540…
iromanchuk-dn 179ff73
fix styles; exclude some props
iromanchuk-dn 696432a
Merge branch 'main' of github.com:drivenets/design-system into AR-540…
iromanchuk-dn 6e700bb
Merge branch 'main' into AR-54024-design-system-split-button
iromanchuk-dn b9883c2
fox some PR comments
iromanchuk-dn 541034e
Move DistributiveOmit into type-utils.ts
iromanchuk-dn 01e7d28
cleanup tests
iromanchuk-dn 9846ece
Reuse the same scss variable across components
iromanchuk-dn b3939c9
Merge branch 'main' of github.com:drivenets/design-system into AR-540…
iromanchuk-dn 061d838
Make size a responsive property
iromanchuk-dn b44107b
Merge branch 'main' into AR-54024-design-system-split-button
iromanchuk-dn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@drivenets/design-system': minor | ||
| --- | ||
|
|
||
| Add `DsSplitButton` component |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 191 additions & 0 deletions
191
...s/design-system/src/components/ds-split-button/__tests__/ds-split-button.browser.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| import { useState } from 'react'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { page } from 'vitest/browser'; | ||
| import DsSplitButton from '../ds-split-button'; | ||
| import type { DsSelectProps } from '../../ds-select'; | ||
|
|
||
| const refreshOptions = [ | ||
| { label: '30s', value: '30' }, | ||
| { label: '1m', value: '60' }, | ||
| { label: '5m', value: '300' }, | ||
| ]; | ||
|
|
||
| const defaultSelect = { | ||
| options: refreshOptions, | ||
| value: '30', | ||
| onValueChange: vi.fn(), | ||
| multiple: false, | ||
| } satisfies DsSelectProps; | ||
|
|
||
| describe('DsSplitButton', () => { | ||
| it('calls slotProps.button.onClick when primary action is clicked', async () => { | ||
| const onClick = vi.fn(); | ||
|
|
||
| await page.render( | ||
| <DsSplitButton | ||
| slotProps={{ | ||
| button: { | ||
| icon: 'refresh', | ||
| 'aria-label': 'Refresh', | ||
| onClick, | ||
| }, | ||
| select: defaultSelect, | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| await page.getByRole('button', { name: 'Refresh' }).click(); | ||
|
|
||
| expect(onClick).toHaveBeenCalledOnce(); | ||
| }); | ||
|
|
||
| it('updates select value when an option is chosen', async () => { | ||
| const onValueChange = vi.fn(); | ||
|
|
||
| function Controlled() { | ||
| const [value, setValue] = useState('30'); | ||
|
|
||
| return ( | ||
| <DsSplitButton | ||
| slotProps={{ | ||
| button: { | ||
| icon: 'refresh', | ||
| 'aria-label': 'Refresh', | ||
| onClick: vi.fn(), | ||
| }, | ||
| select: { | ||
| options: refreshOptions, | ||
| value, | ||
| onValueChange: (v) => { | ||
| onValueChange(v); | ||
| setValue(v); | ||
| }, | ||
| multiple: false, | ||
| }, | ||
| }} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| await page.render(<Controlled />); | ||
|
|
||
| await page.getByRole('combobox').click(); | ||
| await page.getByRole('option', { name: /1m/i }).click(); | ||
|
|
||
| expect(onValueChange).toHaveBeenCalledWith('60'); | ||
|
|
||
| const combobox = page.getByRole('combobox'); | ||
| await expect.element(combobox).toHaveTextContent(/1m/); | ||
| }); | ||
|
|
||
| it('disables primary button and select when disabled', async () => { | ||
| const onClick = vi.fn(); | ||
| const onValueChange = vi.fn(); | ||
|
|
||
| await page.render( | ||
| <DsSplitButton | ||
| disabled | ||
| slotProps={{ | ||
| button: { | ||
| icon: 'refresh', | ||
| 'aria-label': 'Refresh', | ||
| onClick, | ||
| }, | ||
| select: { | ||
| options: refreshOptions, | ||
| value: '30', | ||
| onValueChange, | ||
| multiple: false, | ||
| }, | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| const primary = page.getByRole('button', { name: 'Refresh', disabled: true }); | ||
| const combobox = page.getByRole('combobox', { disabled: true }); | ||
|
|
||
| await expect.element(primary).toBeDisabled(); | ||
| await expect.element(combobox).toBeDisabled(); | ||
|
|
||
| await primary.click({ force: true }); | ||
| await combobox.click({ force: true }); | ||
|
|
||
| expect(onClick).not.toHaveBeenCalled(); | ||
| expect(onValueChange).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('sets loading state on primary button and blocks click', async () => { | ||
| const onClick = vi.fn(); | ||
|
|
||
| await page.render( | ||
| <DsSplitButton | ||
| slotProps={{ | ||
| button: { | ||
| loading: true, | ||
| icon: 'refresh', | ||
| 'aria-label': 'Refresh', | ||
| onClick, | ||
| }, | ||
| select: defaultSelect, | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| const primary = page.getByRole('button', { name: 'Refresh' }); | ||
|
|
||
| await expect.element(primary).toHaveAttribute('aria-busy', 'true'); | ||
| await expect.element(primary).toHaveAttribute('data-loading', ''); | ||
|
|
||
| await primary.click({ force: true }); | ||
|
|
||
| expect(onClick).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('keeps primary button and select the same height at medium size', async () => { | ||
| await page.render( | ||
| <DsSplitButton | ||
| size="medium" | ||
| slotProps={{ | ||
| button: { | ||
| icon: 'refresh', | ||
| 'aria-label': 'Refresh', | ||
| }, | ||
| select: defaultSelect, | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| const buttonHeight = page | ||
| .getByRole('button', { name: 'Refresh' }) | ||
| .element() | ||
| .getBoundingClientRect().height; | ||
| const selectControl = page.getByRole('combobox').element().parentElement as HTMLElement; | ||
| const selectHeight = selectControl.getBoundingClientRect().height; | ||
|
|
||
| expect(buttonHeight).toBe(selectHeight); | ||
| }); | ||
|
|
||
| it('keeps primary button and select the same height at small size', async () => { | ||
| await page.render( | ||
| <DsSplitButton | ||
| size="small" | ||
| slotProps={{ | ||
| button: { | ||
| icon: 'refresh', | ||
| 'aria-label': 'Refresh', | ||
| }, | ||
| select: defaultSelect, | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| const buttonHeight = page | ||
| .getByRole('button', { name: 'Refresh' }) | ||
| .element() | ||
| .getBoundingClientRect().height; | ||
| const selectControl = page.getByRole('combobox').element().parentElement as HTMLElement; | ||
| const selectHeight = selectControl.getBoundingClientRect().height; | ||
|
|
||
| expect(buttonHeight).toBe(selectHeight); | ||
| }); | ||
| }); |
99 changes: 99 additions & 0 deletions
99
packages/design-system/src/components/ds-split-button/ds-split-button.module.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| @use '../../styles/shared/button' as button; | ||
|
|
||
| $highlighted-z-index: 1; | ||
| $divider-z-index: $highlighted-z-index + 1; | ||
| $divider-width: 1px; | ||
| $border-width: 1px; | ||
|
|
||
| @mixin when-button-disabled { | ||
| .root:has(.actionButton:disabled) & { | ||
| @content; | ||
| } | ||
| } | ||
|
|
||
| @mixin when-select-disabled { | ||
| .root:has(.select[data-disabled]) & { | ||
| @content; | ||
| } | ||
| } | ||
|
|
||
| @mixin when-button-highlighted { | ||
| .root:has(.actionButton:not(:disabled):is(:hover, :focus-visible, :active, [data-selected='true'])) & { | ||
| @content; | ||
| } | ||
| } | ||
|
|
||
| @mixin when-select-highlighted { | ||
| .root:has( | ||
| .select:not([data-disabled]):is(:hover, :active, [data-state='open']), | ||
| .select:not([data-disabled]) :focus-visible | ||
| ) | ||
| & { | ||
| @content; | ||
| } | ||
| } | ||
|
|
||
| .root { | ||
| display: inline-flex; | ||
|
|
||
| .actionButton { | ||
| border-top-right-radius: 0; | ||
| border-bottom-right-radius: 0; | ||
| } | ||
| } | ||
|
|
||
| .actionButton { | ||
| @include when-button-highlighted { | ||
| z-index: $highlighted-z-index; | ||
| transition: border-color button.$transition-duration-quick; | ||
| } | ||
|
|
||
| &:not(:disabled):is(:hover, :active, [data-selected='true']) { | ||
| border-right-color: var(--border-border-secondary-hover); | ||
| } | ||
|
|
||
| &:not(:disabled):focus-visible { | ||
| border-right-color: var(--border-border-inverse); | ||
| } | ||
| } | ||
|
|
||
| .select { | ||
| margin-left: -$divider-width; | ||
| border-top-left-radius: 0; | ||
| border-bottom-left-radius: 0; | ||
| } | ||
|
|
||
| .dividerAnchor { | ||
| position: relative; | ||
| } | ||
|
|
||
| .dividerWrapper { | ||
| position: absolute; | ||
| top: $border-width; | ||
| bottom: $border-width; | ||
| left: -$divider-width; | ||
| z-index: $divider-z-index; | ||
| width: $divider-width; | ||
| padding: var(--spacing-3xs) 0; | ||
| background-color: var(--background-background); | ||
|
|
||
| @include when-button-highlighted { | ||
| display: none; | ||
| } | ||
| @include when-select-highlighted { | ||
| display: none; | ||
| } | ||
| } | ||
|
|
||
| .divider { | ||
| background-color: var(--color-border-secondary); | ||
| width: $divider-width; | ||
| height: 100%; | ||
|
|
||
| @include when-button-disabled { | ||
| background-color: var(--border-border-disabled); | ||
| } | ||
| @include when-select-disabled { | ||
| background-color: var(--border-border-disabled); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like there are some padding-top issues with the small size (maybe bug in the select component itself?):

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a known bug in the DsSelect component.
https://drivenets.atlassian.net/browse/AR-52305