Skip to content

Commit d3ca2fc

Browse files
committed
feat: #button: pass props along to the button markup
1 parent 5581706 commit d3ca2fc

3 files changed

Lines changed: 28 additions & 13 deletions

File tree

packages/dnb-ui-lib/src/components/button/Button.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,42 +133,51 @@ export default class Button extends PureComponent {
133133
class: class_name,
134134
className,
135135
type,
136+
variant,
137+
size,
136138
title,
137139
id,
138140
disabled,
139141
text,
140142
icon,
141143
icon_position,
142144
href,
145+
attributes, // eslint-disable-line
146+
innerRef, // eslint-disable-line
143147
...props
144148
} = this.props
145149

146-
let { variant, size } = props
150+
let usedVariant = variant
151+
let usedSize = size
152+
153+
// let { size } = props
147154

148155
// if only has Icon, then resize it and define it as secondary
149156
const isIconOnly = Boolean(!text && icon)
150157
if (isIconOnly) {
151-
if (!variant) {
152-
variant = 'secondary'
158+
if (!usedVariant) {
159+
usedVariant = 'secondary'
153160
}
154-
if (!size) {
155-
size = 'medium'
161+
if (!usedSize) {
162+
usedSize = 'medium'
156163
}
157164
} else if (text) {
158-
if (!variant) {
159-
variant = 'primary'
165+
if (!usedVariant) {
166+
usedVariant = 'primary'
160167
}
161-
if (!size) {
162-
size = 'default'
168+
if (!usedSize) {
169+
usedSize = 'default'
163170
}
164171
}
165172

166173
const content = Button.getContent(this.props)
167174

168175
const classes = classnames(
169176
'dnb-button',
170-
`dnb-button--${variant}`,
171-
size && size !== 'default' ? `dnb-button--size-${size}` : null,
177+
`dnb-button--${usedVariant}`,
178+
usedSize && usedSize !== 'default'
179+
? `dnb-button--size-${usedSize}`
180+
: null,
172181
icon && icon_position
173182
? `dnb-button--icon-position-${icon_position}`
174183
: null,
@@ -185,10 +194,12 @@ export default class Button extends PureComponent {
185194
className: classes,
186195
type,
187196
title: title || text,
197+
['aria-label']: title || text,
188198
id,
189199
disabled,
190-
onMouseOut: this.onMouseOutHandler,
191-
onClick: this.onClickHandler
200+
onMouseOut: this.onMouseOutHandler, // for resetting the button to the default state
201+
onClick: this.onClickHandler,
202+
...props
192203
}
193204

194205
// also used for code markup simulation

packages/dnb-ui-lib/src/components/button/__tests__/__snapshots__/Button.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ exports[`Button component have to match default button snapshot 1`] = `
2222
variant="primary"
2323
>
2424
<button
25+
aria-label="This is a button title"
2526
className="dnb-button dnb-button--primary dnb-button--icon-position-right dnb-button--has-text dnb-button--has-icon id class className"
2627
disabled="disabled"
2728
id="id"
@@ -122,6 +123,7 @@ exports[`Button component have to match href="..." snapshot 1`] = `
122123
variant="primary"
123124
>
124125
<a
126+
aria-label="This is a button title"
125127
className="dnb-button dnb-button--primary dnb-button--icon-position-right dnb-button--has-text dnb-button--has-icon id class className dnb-no-anchor-underline dnb-no-anchor-hover"
126128
disabled="disabled"
127129
href="https://url"

packages/dnb-ui-lib/src/components/modal/__tests__/__snapshots__/Modal.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ exports[`Modal component have to match snapshot 1`] = `
9090
variant="secondary"
9191
>
9292
<button
93+
aria-label="Open Modal"
9394
className="dnb-button dnb-button--secondary dnb-button--size-medium dnb-button--icon-position-right dnb-button--has-icon"
9495
onClick={[Function]}
9596
onMouseOut={[Function]}
@@ -328,6 +329,7 @@ exports[`Modal component have to match snapshot 1`] = `
328329
variant="secondary"
329330
>
330331
<button
332+
aria-label="Close"
331333
className="dnb-button dnb-button--secondary dnb-button--size-medium dnb-button--icon-position-right dnb-button--has-icon dnb-modal__close-button"
332334
onClick={[Function]}
333335
onMouseOut={[Function]}

0 commit comments

Comments
 (0)