Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1870 from oliv37/fix/1852-button-toolbar-alignment
Browse files Browse the repository at this point in the history
fix(button toolbar): align buttons to the right in the toolbar
  • Loading branch information
matteovivona authored Feb 29, 2020
2 parents 3068090 + 9b2e721 commit 34be01d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/__tests__/page-header/ButtonToolBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@ describe('Button Tool Bar', () => {
jest.spyOn(ButtonBarProvider, 'useButtons')
mocked(ButtonBarProvider).useButtons.mockReturnValue(buttons)

const wrapper = mount(<ButtonToolBar />)
const wrapper = mount(<ButtonToolBar />).find('.button-toolbar')

expect(wrapper.childAt(0).getElement()).toEqual(buttons[0])
expect(wrapper.childAt(1).getElement()).toEqual(buttons[1])
})

it('should return null when there is no button in the provider', () => {
jest.spyOn(ButtonBarProvider, 'useButtons')
mocked(ButtonBarProvider).useButtons.mockReturnValue([])

const wrapper = mount(<ButtonToolBar />)

expect(wrapper.html()).toBeNull()
})
})
4 changes: 4 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@ code {
padding: 0;
background-color: white;
}

.button-toolbar > button {
margin-left: .5rem;
}
7 changes: 6 additions & 1 deletion src/page-header/ButtonToolBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { useButtons } from './ButtonBarProvider'

const ButtonToolBar = () => {
const buttons = useButtons()
return <>{buttons.map((button) => button)}</>

if (buttons.length === 0) {
return null
}

return <div className="button-toolbar">{buttons.map((button) => button)}</div>
}

export default ButtonToolBar

1 comment on commit 34be01d

@vercel
Copy link

@vercel vercel bot commented on 34be01d Feb 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.