+import classNames from "classnames";
import { Component, InfernoNode, linkEvent } from "inferno";
interface TabItem {
key: string;
- getNode: () => InfernoNode;
+ getNode: (isSelected: boolean) => InfernoNode;
label: string;
}
render() {
return (
<div>
- <ul className="nav nav-tabs mb-2">
+ <ul className="nav nav-tabs mb-2" role="tablist">
{this.props.tabs.map(({ key, label }) => (
<li key={key} className="nav-item">
<button
type="button"
- className={`nav-link btn${
- this.state?.currentTab === key ? " active" : ""
- }`}
+ className={classNames("nav-link", {
+ active: this.state?.currentTab === key,
+ })}
onClick={linkEvent({ ctx: this, tab: key }, handleSwitchTab)}
+ aria-controls={`${key}-tab-pane`}
+ {...(this.state?.currentTab === key && {
+ ...{
+ "aria-current": "page",
+ "aria-selected": "true",
+ },
+ })}
>
{label}
</button>
</li>
))}
</ul>
- {this.props.tabs
- .find(tab => tab.key === this.state?.currentTab)
- ?.getNode()}
+ <div className="tab-content">
+ {this.props.tabs.map(({ key, getNode }) => {
+ return getNode(this.state?.currentTab === key);
+ })}
+ </div>
</div>
);
}