Skip to content

Commit fa4c7bb

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 5e9227a commit fa4c7bb

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/view/TabButton.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,23 @@ export const TabButton = (props: ITabButtonProps) => {
196196
);
197197
}
198198

199+
const onKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
200+
if (event.key === "Enter" || event.key === " ") {
201+
event.preventDefault();
202+
onClick();
203+
}
204+
};
205+
199206
return (
200207
<div
201208
ref={selfRef}
209+
role="button"
210+
tabIndex={0}
211+
aria-pressed={selected}
202212
data-layout-path={path}
203213
className={classNames}
204214
onMouseDown={onMouseDown}
215+
onKeyDown={onKeyDown}
205216
onClick={onAuxMouseClick}
206217
onAuxClick={onAuxMouseClick}
207218
onContextMenu={onContextMenu}

0 commit comments

Comments
 (0)