Skip to content

Commit

Permalink
Merge pull request #826 from commercelayer/fix-empty-dropdown-visibility
Browse files Browse the repository at this point in the history
Dropdown when empty is no more visible
  • Loading branch information
marcomontalbano authored Nov 5, 2024
2 parents cad76a0 + 8a692bb commit ec04859
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ describe('PageHeadingToolbar', () => {

expect(queryAllByTestId('toolbar-button').length).toEqual(2)
expect(queryAllByTestId('toolbar-dropdown-button').length).toEqual(1)
expect(queryByTestId('toolbar-dropdown-button')).not.toHaveClass(
'md:hidden'
)
const dropDownButton = queryByTestId('toolbar-dropdown-button')
if (dropDownButton != null) {
act(() => {
Expand All @@ -73,4 +76,25 @@ describe('PageHeadingToolbar', () => {
})
}
})

it('Should not display the dropdown button when empty', async () => {
const { queryAllByTestId, queryByTestId } = render(
<PageHeadingToolbar
buttons={[
{
label: 'Primary',
size: 'small',
onClick: () => {
console.log('Primary')
}
}
]}
dropdownItems={[[]]}
/>
)

expect(queryAllByTestId('toolbar-button').length).toEqual(1)
expect(queryAllByTestId('toolbar-dropdown-button').length).toEqual(1)
expect(queryByTestId('toolbar-dropdown-button')).toHaveClass('md:hidden')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const PageHeadingToolbar = withSkeletonTemplate<PageHeadingToolbarProps>(
icon: 'dotsThree',
size: 'small',
variant: 'secondary',
className: dropdownItems.length > 0 ? '' : 'flex md:hidden',
className: dropdownItems.flat().length > 0 ? '' : 'flex md:hidden',
dropdownItems: combinedDropdownItems
})
}
Expand Down

0 comments on commit ec04859

Please sign in to comment.