Skip to content

Commit

Permalink
fix: fix #tabs tabIndex vs content – fixes #779
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Mar 30, 2021
1 parent cd78bfc commit 54f0f29
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
14 changes: 14 additions & 0 deletions packages/dnb-eufemia/src/components/tabs/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,19 @@ export default class Tabs extends React.PureComponent {
) // Delay so Chrome/Safari makes the transition / animation smooth
}

onKeyDownHandler = (event) => {
switch (keycode(event)) {
case 'enter':
try {
const elem = document.getElementById(`${this._id}-content`)
elem.focus()
} catch (e) {
warn(e)
}
break
}
}

onClickHandler = (event) => {
let selected_key
try {
Expand Down Expand Up @@ -1042,6 +1055,7 @@ Tip: Check out other solutions like <Tabs.Content id="unique">Your content, outs
isSelected && 'selected'
)}
onClick={this.onClickHandler}
onKeyUp={this.onKeyDownHandler}
data-tab-key={key}
{...itemParams}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default class ContentWrapper extends React.PureComponent {
return (
<Element
role="tabpanel"
tabIndex="0"
tabIndex="-1"
id={`${id}-content`}
spacing={content_style ? false : undefined}
style_type={content_style ? content_style : undefined}
Expand Down
13 changes: 6 additions & 7 deletions packages/dnb-eufemia/src/components/tabs/TabsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ class TabsController {
}
}

const inst =
typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: TabsController
const inst = typeof window !== 'undefined' ? window : TabsController

export default {
use: (id) => {
return (inst[id] || (inst[id] = new TabsController(id))).init()
inst.__tabsController = inst.__tabsController || {}
return (
inst.__tabsController[id] ||
(inst.__tabsController[id] = new TabsController(id))
).init()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ exports[`A single Tab component has to work with "Tabs.Content" from outside 1`]
data-tab-key="first"
id="linked-tab-first"
onClick={[Function]}
onKeyUp={[Function]}
role="tab"
tabIndex="-1"
type="button"
Expand Down Expand Up @@ -236,6 +237,7 @@ exports[`A single Tab component has to work with "Tabs.Content" from outside 1`]
data-tab-key="second"
id="linked-tab-second"
onClick={[Function]}
onKeyUp={[Function]}
role="tab"
tabIndex="-1"
type="button"
Expand Down Expand Up @@ -267,6 +269,7 @@ exports[`A single Tab component has to work with "Tabs.Content" from outside 1`]
data-tab-key="third"
id="linked-tab-third"
onClick={[Function]}
onKeyUp={[Function]}
role="tab"
tabIndex="-1"
type="button"
Expand Down Expand Up @@ -460,7 +463,7 @@ exports[`A single Tab component has to work with "Tabs.Content" from outside 1`]
className="dnb-tabs__content dnb-no-focus dnb-tabs__content--spacing"
id="linked-content"
role="tabpanel"
tabIndex="0"
tabIndex="-1"
>
third
</div>
Expand Down Expand Up @@ -717,6 +720,7 @@ exports[`Tabs component have to match snapshot 1`] = `
data-tab-key="first"
id="id-tab-first"
onClick={[Function]}
onKeyUp={[Function]}
role="tab"
tabIndex="-1"
type="button"
Expand Down Expand Up @@ -748,6 +752,7 @@ exports[`Tabs component have to match snapshot 1`] = `
data-tab-key="second"
id="id-tab-second"
onClick={[Function]}
onKeyUp={[Function]}
role="tab"
tabIndex="-1"
type="button"
Expand Down Expand Up @@ -778,6 +783,7 @@ exports[`Tabs component have to match snapshot 1`] = `
data-tab-key="third"
id="id-tab-third"
onClick={[Function]}
onKeyUp={[Function]}
role="tab"
tabIndex="-1"
type="button"
Expand Down Expand Up @@ -952,7 +958,7 @@ exports[`Tabs component have to match snapshot 1`] = `
className="dnb-tabs__content dnb-no-focus dnb-tabs__content--spacing"
id="id-content"
role="tabpanel"
tabIndex="0"
tabIndex="-1"
>
<second>
<h2>
Expand Down

0 comments on commit 54f0f29

Please sign in to comment.