Skip to content

Commit

Permalink
fix: fix tertiary #button with component given and icon_position left
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Feb 26, 2021
1 parent dbebc05 commit 4222da0
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import { bell_medium as Bell, question } from 'dnb-ui-lib/src/icons'

### Tertiary button

<ComponentBox>
<ComponentBox data-visual-test="button-tertiary-all">
{
/* @jsx */ `
<Button
Expand All @@ -108,11 +108,19 @@ import { bell_medium as Bell, question } from 'dnb-ui-lib/src/icons'
icon="chevron_left"
data-visual-test="button-tertiary"
/>
<Button
variant="tertiary"
text={<span>Text inside additional span</span>}
icon_position="left"
icon="chevron_left"
left
/>
<Button
variant="tertiary"
text="With medium icon"
icon="chevron_right"
icon_size="medium"
left
/>
`
}
Expand Down
15 changes: 8 additions & 7 deletions packages/dnb-ui-lib/src/components/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,14 @@ export default class Button extends React.PureComponent {
let usedVariant = variant
let usedSize = size
let iconSize = icon_size
let content = Button.getContent(this.props) || text
const content = Button.getContent(this.props)

if (variant === 'tertiary' && content && !icon && icon !== false) {
if (
variant === 'tertiary' &&
(content || text) &&
!icon &&
icon !== false
) {
warn(
`A Tertiary Button requires an icon. Please declare an icon to: ${content}`
)
Expand Down Expand Up @@ -373,11 +378,7 @@ class Content extends React.PureComponent {
)
}

if (
typeof content === 'string'
// ||
// (Array.isArray(content) && typeof content[0] === 'string')
) {
if (typeof content === 'string') {
text = content
} else if (content) {
ret.push(content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ describe('Button tertiary screenshot', () => {
})
expect(screenshot).toMatchImageSnapshot()
})
it('have to match all tertiary buttons', async () => {
const screenshot = await testPageScreenshot({
selector: '[data-visual-test="button-tertiary-all"]'
})
expect(screenshot).toMatchImageSnapshot()
})
})

describe('Button signal screenshot', () => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ exports[`GlobalError snapshot have to match component snapshot 1`] = `
bounding={false}
class={null}
className="dnb-global-error__back"
content="back"
content={null}
custom_element={null}
custom_method={null}
disabled={null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ exports[`GlobalStatus snapshot have to match component snapshot 1`] = `
bounding={false}
class={null}
className="dnb-global-status__close-button"
content="close_text"
content={null}
custom_element={null}
custom_method={null}
disabled={null}
Expand Down Expand Up @@ -1230,7 +1230,7 @@ Array [
bounding={false}
class={null}
className="dnb-global-status__close-button"
content="Lukk"
content={null}
custom_element={null}
custom_method={null}
disabled={null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ exports[`Modal component have to match snapshot 1`] = `
bounding={false}
class={null}
className="dnb-modal__close-button"
content="close_title"
content={null}
custom_element={null}
custom_method={null}
disabled={null}
Expand Down
6 changes: 6 additions & 0 deletions packages/dnb-ui-lib/stories/components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ export const ButtonSandbox = () => (
icon_position="left"
icon="chevron_left"
/>
<Button
text={<span>Button text in span</span>}
variant="tertiary"
icon_position="left"
icon="chevron_left"
/>
<Button text="Button text" variant="tertiary" icon="chevron_right" />
<Button
text="Button text"
Expand Down

0 comments on commit 4222da0

Please sign in to comment.