Skip to content

Commit 672007f

Browse files
committed
Fix an issue where the selected tab isn't selectable via keyboard navigation (microsoft/rushstack-websites#171)
1 parent fcffaae commit 672007f

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

playground/src/TabPane.tsx

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export interface ITabPaneState {
1717
selectedTabIndex: number;
1818
}
1919

20+
const TAB_STYLE: React.CSSProperties = {
21+
padding: '8px',
22+
marginLeft: '1px',
23+
marginRight: '1px'
24+
};
25+
2026
export class TabPane extends React.Component<ITabPaneProps, ITabPaneState> {
2127
// Saved bindings of _onClickTab() with a tabIndex parameter, to avoid the react/jsx-no-bind issue
2228
private _onClickTabBindings: React.MouseEventHandler<HTMLAnchorElement>[] = [];
@@ -38,49 +44,39 @@ export class TabPane extends React.Component<ITabPaneProps, ITabPaneState> {
3844
for (let i: number = 0; i < this.props.tabs.length; ++i) {
3945
const tabDefinition: ITabDefinition = this.props.tabs[i];
4046

41-
const style: React.CSSProperties = {
42-
padding: '8px',
43-
marginLeft: '1px',
44-
marginRight: '1px'
45-
};
46-
47+
let tabStyleToUse: React.CSSProperties;
4748
if (i === this.state.selectedTabIndex) {
4849
selectedTabDefinition = tabDefinition;
4950

50-
const activeTabStyle: React.CSSProperties = {
51-
...style,
51+
tabStyleToUse = {
52+
...TAB_STYLE,
5253
borderStyle: 'solid',
5354
borderWidth: '2px',
5455
borderColor: '#c0c0c0',
5556
borderBottomStyle: 'none',
5657
borderTopLeftRadius: '4px',
5758
borderTopRightRadius: '4px'
5859
};
59-
60-
buttons.push(
61-
<div key={`tab_${i}`} className="playground-tab-pane-active-tab" style={activeTabStyle} role="tab">
62-
{tabDefinition.title}
63-
</div>
64-
);
6560
} else {
66-
if (!this._onClickTabBindings[i]) {
67-
// Bind _onClickTab() with i as the tabIndex parameter
68-
this._onClickTabBindings[i] = this._onClickTab.bind(this, i);
69-
}
70-
71-
buttons.push(
72-
<div key={`tab_${i}`} className="playground-tab-pane-inactive-tab" style={style}>
73-
<a
74-
href="#"
75-
style={{ textDecorationLine: 'none', color: '#000000' }}
76-
onClick={this._onClickTabBindings[i]}
77-
role="tab"
78-
>
79-
{tabDefinition.title}
80-
</a>
81-
</div>
82-
);
61+
tabStyleToUse = TAB_STYLE;
8362
}
63+
64+
if (!this._onClickTabBindings[i]) {
65+
// Bind _onClickTab() with i as the tabIndex parameter
66+
this._onClickTabBindings[i] = this._onClickTab.bind(this, i);
67+
}
68+
buttons.push(
69+
<div key={`tab_${i}`} className="playground-tab-pane-inactive-tab" style={tabStyleToUse}>
70+
<a
71+
href="#"
72+
style={{ textDecorationLine: 'none', color: '#000000' }}
73+
onClick={this._onClickTabBindings[i]}
74+
role="tab"
75+
>
76+
{tabDefinition.title}
77+
</a>
78+
</div>
79+
);
8480
}
8581

8682
const contentDivStyle: React.CSSProperties = {

0 commit comments

Comments
 (0)