Skip to content

Commit 1af22d7

Browse files
committed
fix: make TabButton aria compliant as a button
Allows using the keyboard to select tabs by pressing the Tab key to switch between elements on the page, and then pressing "enter" or space " " to select the highlighted tab. Signed-off-by: Christian Stewart <[email protected]>
1 parent a3327e6 commit 1af22d7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/view/TabButton.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,23 @@ export const TabButton = (props: ITabButtonProps) => {
167167
);
168168
}
169169

170+
const onKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
171+
if (event.key === "Enter" || event.key === " ") {
172+
event.preventDefault();
173+
onClick();
174+
}
175+
};
176+
170177
return (
171178
<div
172179
ref={selfRef}
180+
role="button"
181+
tabIndex={0}
182+
aria-pressed={selected}
173183
data-layout-path={path}
174184
className={classNames}
175185
onClick={onClick}
186+
onKeyDown={onKeyDown}
176187
onAuxClick={onAuxMouseClick}
177188
onContextMenu={onContextMenu}
178189
title={node.getHelpText()}

0 commit comments

Comments
 (0)