Skip to content

Commit bc4c3d1

Browse files
committed
fix(ui): add accessibility attrs and click-outside handling to dropdown components
CortexDropdownMenu: add role="menu" to container div, add onClickOutside optional prop with document mousedown listener registered in onMount and cleaned up in onCleanup, using a ref on the container div. CortexDropdownItem: add role="menuitem" and tabindex="0" to the button element for proper keyboard accessibility and ARIA semantics. CortexGitPanel: move document.addEventListener("mousedown", ...) into an onMount() block to follow SolidJS lifecycle best practices (was previously called at component top-level which is a SolidJS antipattern).
1 parent f37e659 commit bc4c3d1

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/components/cortex/CortexGitPanel.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ export const CortexGitPanel: Component = () => {
138138
const handleClickOutside = (e: MouseEvent) => {
139139
if (showDotsMenu() && dotsRef && !dotsRef.contains(e.target as Node)) setShowDotsMenu(false);
140140
};
141-
document.addEventListener("mousedown", handleClickOutside);
141+
onMount(() => {
142+
document.addEventListener("mousedown", handleClickOutside);
143+
});
142144
onCleanup(() => document.removeEventListener("mousedown", handleClickOutside));
143145

144146
onMount(() => { if (repo()) fetchStashes(); });

src/components/cortex/primitives/CortexDropdownItem.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ export const CortexDropdownItem: Component<CortexDropdownItemProps> = (props) =>
106106
return (
107107
<button
108108
type="button"
109+
role="menuitem"
110+
tabindex="0"
109111
class={local.class}
110112
style={baseStyle()}
111113
onClick={handleClick}

src/components/cortex/primitives/CortexDropdownMenu.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
* Figma "Dropdown Menu": standalone container with dark bg and border
44
*/
55

6-
import { Component, JSX, splitProps } from "solid-js";
6+
import { Component, JSX, splitProps, onMount, onCleanup } from "solid-js";
77

88
export interface CortexDropdownMenuProps {
99
children?: JSX.Element;
1010
width?: number;
1111
class?: string;
1212
style?: JSX.CSSProperties;
13+
onClickOutside?: () => void;
1314
}
1415

1516
export const CortexDropdownMenu: Component<CortexDropdownMenuProps> = (props) => {
@@ -18,8 +19,21 @@ export const CortexDropdownMenu: Component<CortexDropdownMenuProps> = (props) =>
1819
"width",
1920
"class",
2021
"style",
22+
"onClickOutside",
2123
]);
2224

25+
let menuRef: HTMLDivElement | undefined;
26+
27+
onMount(() => {
28+
const handleMouseDown = (e: MouseEvent) => {
29+
if (menuRef && !menuRef.contains(e.target as Node)) {
30+
local.onClickOutside?.();
31+
}
32+
};
33+
document.addEventListener("mousedown", handleMouseDown);
34+
onCleanup(() => document.removeEventListener("mousedown", handleMouseDown));
35+
});
36+
2337
const menuWidth = () => local.width ?? 243;
2438

2539
const containerStyle = (): JSX.CSSProperties => ({
@@ -38,6 +52,8 @@ export const CortexDropdownMenu: Component<CortexDropdownMenuProps> = (props) =>
3852

3953
return (
4054
<div
55+
ref={menuRef}
56+
role="menu"
4157
class={local.class}
4258
style={containerStyle()}
4359
{...others}

0 commit comments

Comments
 (0)