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

fix(button toolbar): align buttons to the right in the toolbar #1870

Merged
merged 1 commit into from
Feb 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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