Skip to content

Commit

Permalink
feat: make it possible to set a button element as not focus able with…
Browse files Browse the repository at this point in the history
… tabindex="-1"
  • Loading branch information
tujoworker committed Jan 4, 2019
1 parent 9133eff commit cd8c6da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/dnb-ui-lib/src/components/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ export default class Button extends PureComponent {
disabled,
text,
icon,
icon_position
icon_position,
href,
...props
} = this.props

let { variant, size } = this.props
let { variant, size } = props

// if only has Icon, then resize it and define it as secondary
if (!text && icon) {
Expand Down Expand Up @@ -174,7 +176,7 @@ export default class Button extends PureComponent {
id,
class_name,
className,
this.props.href ? 'no-underline no-underline-hover' : null
href ? 'no-underline no-underline-hover' : null
)

const params = {
Expand All @@ -194,8 +196,8 @@ export default class Button extends PureComponent {
// also used for code markup simulation
validateDOMAttributes(this.props, params)

return this.props.href ? (
<a href={this.props.href} ref={this._ref} {...params}>
return href ? (
<a href={href} ref={this._ref} {...params}>
<Content {...this.props} content={content} />
</a>
) : (
Expand Down
8 changes: 8 additions & 0 deletions packages/dnb-ui-lib/src/shared/component-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ export const validateDOMAttributes = (props, params) => {
delete params.disabled
}

if (props && props.tabindex) {
let tabIndex = props.tabindex
if (tabIndex === 'off') {
tabIndex = '-1'
}
params['tabIndex'] = tabIndex
}

// add web component event handler
if (props && typeof props.on_click === 'function') {
params['onClick'] = props.on_click
Expand Down

0 comments on commit cd8c6da

Please sign in to comment.