@orbitkit/components 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/astro/accordion/Accordion.astro +34 -34
- package/dist/astro/accordion/AccordionItem.astro +19 -19
- package/dist/astro/accordion/AccordionTrigger.astro +33 -33
- package/dist/astro/accordion/AcordionContent.astro +23 -23
- package/dist/astro/accordion/accordion.ts +151 -151
- package/dist/astro/accordion/index.ts +6 -6
- package/dist/astro/collapsible/Collapsible.astro +34 -34
- package/dist/astro/collapsible/CollapsibleContent.astro +20 -20
- package/dist/astro/collapsible/collapsible.ts +81 -81
- package/dist/astro/collapsible/index.ts +4 -4
- package/dist/astro/drawer/DrawerContent.astro +74 -74
- package/dist/astro/drawer/drawer.ts +104 -104
- package/dist/astro/drawer/index.ts +17 -17
- package/dist/astro/dropdown/DropdownMenu.astro +19 -19
- package/dist/astro/dropdown/DropdownMenuContent.astro +42 -42
- package/dist/astro/dropdown/DropdownMenuGroup.astro +3 -3
- package/dist/astro/dropdown/DropdownMenuItem.astro +27 -27
- package/dist/astro/dropdown/DropdownMenuLabel.astro +3 -3
- package/dist/astro/dropdown/DropdownMenuSeparator.astro +6 -6
- package/dist/astro/dropdown/dropdown.ts +157 -157
- package/dist/astro/dropdown/dropdownVariants.ts +134 -134
- package/dist/astro/dropdown/index.ts +23 -23
- package/dist/astro/marquee/Marquee.astro +53 -0
- package/dist/astro/marquee/index.ts +3 -0
- package/dist/astro/modal/Modal.astro +19 -19
- package/dist/astro/modal/ModalContent.astro +71 -71
- package/dist/astro/modal/ModalDescription.astro +12 -12
- package/dist/astro/modal/ModalFooter.astro +15 -15
- package/dist/astro/modal/ModalHeader.astro +12 -12
- package/dist/astro/modal/ModalTitle.astro +18 -18
- package/dist/astro/modal/index.ts +15 -15
- package/dist/astro/modal/modal.ts +101 -101
- package/dist/astro/pagination/index.ts +15 -15
- package/dist/astro/popover/Popover.astro +17 -17
- package/dist/astro/popover/PopoverContent.astro +39 -39
- package/dist/astro/popover/index.ts +5 -5
- package/dist/astro/popover/popover.ts +113 -113
- package/dist/astro/popover/popoverVariants.ts +115 -115
- package/dist/astro/scroll-progress/ScrollProgress.astro +41 -0
- package/dist/astro/scroll-progress/ScrollProgressBar.astro +19 -0
- package/dist/astro/scroll-progress/index.ts +4 -0
- package/dist/astro/stat/Stat.astro +12 -12
- package/dist/astro/stat/StatDescription.astro +12 -12
- package/dist/astro/stat/StatTitle.astro +18 -18
- package/dist/astro/stat/StatValue.astro +12 -12
- package/dist/astro/stat/index.ts +6 -6
- package/dist/astro/tab/TabList.astro +19 -19
- package/dist/astro/toast/Toast.astro +36 -0
- package/dist/astro/toast/ToastDescription.astro +10 -0
- package/dist/astro/toast/ToastTitle.astro +18 -0
- package/dist/astro/toast/Toaster.astro +78 -0
- package/dist/astro/toast/assets.ts +6 -0
- package/dist/astro/toast/index.ts +30 -0
- package/dist/astro/toast/toast.ts +277 -0
- package/dist/astro/tooltip/Tooltip.astro +40 -40
- package/dist/astro/tooltip/TooltipContent.astro +39 -39
- package/dist/astro/tooltip/index.ts +5 -5
- package/dist/astro/tooltip/tooltip.ts +137 -137
- package/dist/astro/tooltip/tooltipVariants.ts +115 -115
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/package.json +54 -54
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
---
|
|
2
|
-
import { cn } from "@/utils/cn";
|
|
3
|
-
import type { HTMLAttributes } from "astro/types";
|
|
4
|
-
import type { VariantProps } from "class-variance-authority";
|
|
5
|
-
import {
|
|
6
|
-
dropdownArrowVariants,
|
|
7
|
-
dropdownMenuVariants,
|
|
8
|
-
} from "./dropdownVariants";
|
|
9
|
-
|
|
10
|
-
interface Props
|
|
11
|
-
extends HTMLAttributes<"div">,
|
|
12
|
-
VariantProps<typeof dropdownMenuVariants> {
|
|
13
|
-
sideOffset?: number;
|
|
14
|
-
arrow?: boolean;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const {
|
|
18
|
-
class: className,
|
|
19
|
-
side,
|
|
20
|
-
alignment,
|
|
21
|
-
sideOffset = 2,
|
|
22
|
-
arrow = false,
|
|
23
|
-
...attrs
|
|
24
|
-
} = Astro.props;
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
<div
|
|
28
|
-
{...attrs}
|
|
29
|
-
role="menu"
|
|
30
|
-
data-dropdown-content
|
|
31
|
-
aria-hidden="true"
|
|
32
|
-
data-state="closed"
|
|
33
|
-
data-side={sideOffset}
|
|
34
|
-
data-alignment={alignment}
|
|
35
|
-
class={cn(dropdownMenuVariants({ side, alignment, className }))}
|
|
36
|
-
style={{
|
|
37
|
-
"--tooltip-offset": `calc(var(--spacing) * ${sideOffset})`,
|
|
38
|
-
}}
|
|
39
|
-
>
|
|
40
|
-
<slot />
|
|
41
|
-
{arrow && <span class={cn(dropdownArrowVariants({ side, alignment }))} />}
|
|
42
|
-
</div>
|
|
1
|
+
---
|
|
2
|
+
import { cn } from "@/utils/cn";
|
|
3
|
+
import type { HTMLAttributes } from "astro/types";
|
|
4
|
+
import type { VariantProps } from "class-variance-authority";
|
|
5
|
+
import {
|
|
6
|
+
dropdownArrowVariants,
|
|
7
|
+
dropdownMenuVariants,
|
|
8
|
+
} from "./dropdownVariants";
|
|
9
|
+
|
|
10
|
+
interface Props
|
|
11
|
+
extends HTMLAttributes<"div">,
|
|
12
|
+
VariantProps<typeof dropdownMenuVariants> {
|
|
13
|
+
sideOffset?: number;
|
|
14
|
+
arrow?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
class: className,
|
|
19
|
+
side,
|
|
20
|
+
alignment,
|
|
21
|
+
sideOffset = 2,
|
|
22
|
+
arrow = false,
|
|
23
|
+
...attrs
|
|
24
|
+
} = Astro.props;
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
<div
|
|
28
|
+
{...attrs}
|
|
29
|
+
role="menu"
|
|
30
|
+
data-dropdown-content
|
|
31
|
+
aria-hidden="true"
|
|
32
|
+
data-state="closed"
|
|
33
|
+
data-side={sideOffset}
|
|
34
|
+
data-alignment={alignment}
|
|
35
|
+
class={cn(dropdownMenuVariants({ side, alignment, className }))}
|
|
36
|
+
style={{
|
|
37
|
+
"--tooltip-offset": `calc(var(--spacing) * ${sideOffset})`,
|
|
38
|
+
}}
|
|
39
|
+
>
|
|
40
|
+
<slot />
|
|
41
|
+
{arrow && <span class={cn(dropdownArrowVariants({ side, alignment }))} />}
|
|
42
|
+
</div>
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
<div role="group">
|
|
2
|
-
<slot />
|
|
3
|
-
</div>
|
|
1
|
+
<div role="group">
|
|
2
|
+
<slot />
|
|
3
|
+
</div>
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
---
|
|
2
|
-
import { cn } from "@/utils/cn";
|
|
3
|
-
import type { VariantProps } from "class-variance-authority";
|
|
4
|
-
import { dropdownMenuItemVariants } from "./dropdownVariants";
|
|
5
|
-
|
|
6
|
-
import type { HTMLTag, Polymorphic } from "astro/types";
|
|
7
|
-
|
|
8
|
-
type Props<Tag extends HTMLTag> = Polymorphic<{ as: Tag }> &
|
|
9
|
-
VariantProps<typeof dropdownMenuItemVariants>;
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
class: className,
|
|
13
|
-
as: Tag = "div",
|
|
14
|
-
disabled = false,
|
|
15
|
-
...attrs
|
|
16
|
-
} = Astro.props;
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
<Tag
|
|
20
|
-
role="menuitem"
|
|
21
|
-
tabindex={disabled ? "-1" : "0"}
|
|
22
|
-
data-disabled={disabled}
|
|
23
|
-
class={cn(dropdownMenuItemVariants({ disabled, className }))}
|
|
24
|
-
{...attrs}
|
|
25
|
-
>
|
|
26
|
-
<slot />
|
|
27
|
-
</Tag>
|
|
1
|
+
---
|
|
2
|
+
import { cn } from "@/utils/cn";
|
|
3
|
+
import type { VariantProps } from "class-variance-authority";
|
|
4
|
+
import { dropdownMenuItemVariants } from "./dropdownVariants";
|
|
5
|
+
|
|
6
|
+
import type { HTMLTag, Polymorphic } from "astro/types";
|
|
7
|
+
|
|
8
|
+
type Props<Tag extends HTMLTag> = Polymorphic<{ as: Tag }> &
|
|
9
|
+
VariantProps<typeof dropdownMenuItemVariants>;
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
class: className,
|
|
13
|
+
as: Tag = "div",
|
|
14
|
+
disabled = false,
|
|
15
|
+
...attrs
|
|
16
|
+
} = Astro.props;
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
<Tag
|
|
20
|
+
role="menuitem"
|
|
21
|
+
tabindex={disabled ? "-1" : "0"}
|
|
22
|
+
data-disabled={disabled}
|
|
23
|
+
class={cn(dropdownMenuItemVariants({ disabled, className }))}
|
|
24
|
+
{...attrs}
|
|
25
|
+
>
|
|
26
|
+
<slot />
|
|
27
|
+
</Tag>
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
<div class="px-2 py-1.5 text-sm font-medium">
|
|
2
|
-
<slot />
|
|
3
|
-
</div>
|
|
1
|
+
<div class="px-2 py-1.5 text-sm font-medium">
|
|
2
|
+
<slot />
|
|
3
|
+
</div>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<div
|
|
2
|
-
role="separator"
|
|
3
|
-
aria-orientation="horizontal"
|
|
4
|
-
class="bg-border -mx-1 my-1 h-px"
|
|
5
|
-
>
|
|
6
|
-
</div>
|
|
1
|
+
<div
|
|
2
|
+
role="separator"
|
|
3
|
+
aria-orientation="horizontal"
|
|
4
|
+
class="bg-border -mx-1 my-1 h-px"
|
|
5
|
+
>
|
|
6
|
+
</div>
|
|
@@ -1,157 +1,157 @@
|
|
|
1
|
-
export class DowndownMenu {
|
|
2
|
-
// References to tooltip elements
|
|
3
|
-
private dropdownMenu: HTMLElement;
|
|
4
|
-
private trigger: HTMLElement | null;
|
|
5
|
-
private content: HTMLElement | null;
|
|
6
|
-
private menuItems: HTMLElement[] = [];
|
|
7
|
-
|
|
8
|
-
constructor(dropowndMenu: HTMLElement) {
|
|
9
|
-
this.dropdownMenu = dropowndMenu;
|
|
10
|
-
this.content = this.dropdownMenu.querySelector("[data-dropdown-content]");
|
|
11
|
-
this.trigger = this.dropdownMenu.querySelector("[data-trigger]");
|
|
12
|
-
this.menuItems = Array.from(
|
|
13
|
-
this.content?.querySelectorAll(
|
|
14
|
-
'[role="menuitem"]:not([data-disabled="true"])',
|
|
15
|
-
) || [],
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
if (!this.content || !this.trigger) {
|
|
19
|
-
console.error("Dropdown not initialized properly", {
|
|
20
|
-
content: this.content,
|
|
21
|
-
trigger: this.trigger,
|
|
22
|
-
});
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
this.init();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private init() {
|
|
30
|
-
this.setupAccessibility();
|
|
31
|
-
this.setupEventListeners();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
private setupAccessibility() {
|
|
35
|
-
if (!this.trigger || !this.content) return;
|
|
36
|
-
|
|
37
|
-
const id =
|
|
38
|
-
this.content.id ||
|
|
39
|
-
`dropdown-id-${Math.random().toString(36).substring(2, 9)}`;
|
|
40
|
-
this.content.id = id;
|
|
41
|
-
this.trigger.setAttribute("aria-describedby", id);
|
|
42
|
-
this.setState("closed");
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private setupEventListeners() {
|
|
46
|
-
if (!this.trigger || !this.content) return;
|
|
47
|
-
|
|
48
|
-
this.trigger.addEventListener("click", () => this.toggleDropdown());
|
|
49
|
-
|
|
50
|
-
this.content.addEventListener("click", (e) => {
|
|
51
|
-
const target = e.target as HTMLElement;
|
|
52
|
-
const item = target.closest('[role="menuitem"]') as HTMLElement;
|
|
53
|
-
|
|
54
|
-
if (item && item.dataset.disabled !== "true") {
|
|
55
|
-
this.closeDropdown();
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
document.addEventListener("click", (e) => {
|
|
60
|
-
const target = e.target as HTMLElement;
|
|
61
|
-
if (
|
|
62
|
-
this.content &&
|
|
63
|
-
!this.content.contains(target) &&
|
|
64
|
-
target !== this.trigger
|
|
65
|
-
) {
|
|
66
|
-
this.closeDropdown();
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
this.trigger.addEventListener("keydown", (e) => {
|
|
71
|
-
const isOpen = this.content?.dataset.state === "open";
|
|
72
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
73
|
-
e.preventDefault();
|
|
74
|
-
this.toggleDropdown();
|
|
75
|
-
} else if (e.key === "Escape" && isOpen) {
|
|
76
|
-
e.preventDefault();
|
|
77
|
-
this.closeDropdown();
|
|
78
|
-
} else if (isOpen && e.key === "ArrowDown") {
|
|
79
|
-
e.preventDefault();
|
|
80
|
-
this.setFocusItem(0);
|
|
81
|
-
} else if (isOpen && e.key === "ArrowUp") {
|
|
82
|
-
e.preventDefault();
|
|
83
|
-
this.setFocusItem(this.menuItems.length - 1);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
this.menuItems.forEach((menuItem) => {
|
|
88
|
-
menuItem.addEventListener("keydown", (e) =>
|
|
89
|
-
this.handleMenuKeydown(e, menuItem),
|
|
90
|
-
);
|
|
91
|
-
});
|
|
92
|
-
document.addEventListener("keydown", (e) => this.handleKeydown(e));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
private toggleDropdown() {
|
|
96
|
-
if (this.content?.dataset.state === "open") {
|
|
97
|
-
this.closeDropdown();
|
|
98
|
-
} else {
|
|
99
|
-
this.openDropdown();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private openDropdown() {
|
|
104
|
-
this.content?.classList.remove("hidden");
|
|
105
|
-
|
|
106
|
-
window.setTimeout(() => {
|
|
107
|
-
this.setState("open");
|
|
108
|
-
}, 0);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private closeDropdown() {
|
|
112
|
-
this.trigger?.focus();
|
|
113
|
-
this.setState("closed");
|
|
114
|
-
window.setTimeout(() => {
|
|
115
|
-
this.content?.classList.add("hidden");
|
|
116
|
-
}, 100);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private setState(state: "open" | "closed") {
|
|
120
|
-
this.content?.setAttribute("aria-hidden", `${state === "closed"}`);
|
|
121
|
-
this.content?.setAttribute("data-state", state);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private handleKeydown = (event: KeyboardEvent) => {
|
|
125
|
-
if (event.key === "Escape" && this.content!.dataset.state === "open") {
|
|
126
|
-
this.closeDropdown();
|
|
127
|
-
event.preventDefault();
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
private handleMenuKeydown(event: KeyboardEvent, item: HTMLElement) {
|
|
132
|
-
const currentItemIndex = this.menuItems.indexOf(item);
|
|
133
|
-
|
|
134
|
-
const keyActions: Record<string, () => void> = {
|
|
135
|
-
ArrowDown: () => this.setFocusItem(currentItemIndex + 1),
|
|
136
|
-
ArrowUp: () => this.setFocusItem(currentItemIndex - 1),
|
|
137
|
-
Home: () => this.setFocusItem(0),
|
|
138
|
-
End: () => this.setFocusItem(this.menuItems.length - 1),
|
|
139
|
-
Enter: () => item.click(),
|
|
140
|
-
" ": () => item.click(),
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const action = keyActions[event.key];
|
|
144
|
-
if (action) {
|
|
145
|
-
event.preventDefault();
|
|
146
|
-
action();
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
private setFocusItem(index: number) {
|
|
151
|
-
const newIndex = (index + this.menuItems.length) % this.menuItems.length;
|
|
152
|
-
|
|
153
|
-
if (this.menuItems[newIndex]) {
|
|
154
|
-
this.menuItems[newIndex].focus();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
1
|
+
export class DowndownMenu {
|
|
2
|
+
// References to tooltip elements
|
|
3
|
+
private dropdownMenu: HTMLElement;
|
|
4
|
+
private trigger: HTMLElement | null;
|
|
5
|
+
private content: HTMLElement | null;
|
|
6
|
+
private menuItems: HTMLElement[] = [];
|
|
7
|
+
|
|
8
|
+
constructor(dropowndMenu: HTMLElement) {
|
|
9
|
+
this.dropdownMenu = dropowndMenu;
|
|
10
|
+
this.content = this.dropdownMenu.querySelector("[data-dropdown-content]");
|
|
11
|
+
this.trigger = this.dropdownMenu.querySelector("[data-trigger]");
|
|
12
|
+
this.menuItems = Array.from(
|
|
13
|
+
this.content?.querySelectorAll(
|
|
14
|
+
'[role="menuitem"]:not([data-disabled="true"])',
|
|
15
|
+
) || [],
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
if (!this.content || !this.trigger) {
|
|
19
|
+
console.error("Dropdown not initialized properly", {
|
|
20
|
+
content: this.content,
|
|
21
|
+
trigger: this.trigger,
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this.init();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private init() {
|
|
30
|
+
this.setupAccessibility();
|
|
31
|
+
this.setupEventListeners();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private setupAccessibility() {
|
|
35
|
+
if (!this.trigger || !this.content) return;
|
|
36
|
+
|
|
37
|
+
const id =
|
|
38
|
+
this.content.id ||
|
|
39
|
+
`dropdown-id-${Math.random().toString(36).substring(2, 9)}`;
|
|
40
|
+
this.content.id = id;
|
|
41
|
+
this.trigger.setAttribute("aria-describedby", id);
|
|
42
|
+
this.setState("closed");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private setupEventListeners() {
|
|
46
|
+
if (!this.trigger || !this.content) return;
|
|
47
|
+
|
|
48
|
+
this.trigger.addEventListener("click", () => this.toggleDropdown());
|
|
49
|
+
|
|
50
|
+
this.content.addEventListener("click", (e) => {
|
|
51
|
+
const target = e.target as HTMLElement;
|
|
52
|
+
const item = target.closest('[role="menuitem"]') as HTMLElement;
|
|
53
|
+
|
|
54
|
+
if (item && item.dataset.disabled !== "true") {
|
|
55
|
+
this.closeDropdown();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
document.addEventListener("click", (e) => {
|
|
60
|
+
const target = e.target as HTMLElement;
|
|
61
|
+
if (
|
|
62
|
+
this.content &&
|
|
63
|
+
!this.content.contains(target) &&
|
|
64
|
+
target !== this.trigger
|
|
65
|
+
) {
|
|
66
|
+
this.closeDropdown();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
this.trigger.addEventListener("keydown", (e) => {
|
|
71
|
+
const isOpen = this.content?.dataset.state === "open";
|
|
72
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
this.toggleDropdown();
|
|
75
|
+
} else if (e.key === "Escape" && isOpen) {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
this.closeDropdown();
|
|
78
|
+
} else if (isOpen && e.key === "ArrowDown") {
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
this.setFocusItem(0);
|
|
81
|
+
} else if (isOpen && e.key === "ArrowUp") {
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
this.setFocusItem(this.menuItems.length - 1);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
this.menuItems.forEach((menuItem) => {
|
|
88
|
+
menuItem.addEventListener("keydown", (e) =>
|
|
89
|
+
this.handleMenuKeydown(e, menuItem),
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
document.addEventListener("keydown", (e) => this.handleKeydown(e));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private toggleDropdown() {
|
|
96
|
+
if (this.content?.dataset.state === "open") {
|
|
97
|
+
this.closeDropdown();
|
|
98
|
+
} else {
|
|
99
|
+
this.openDropdown();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private openDropdown() {
|
|
104
|
+
this.content?.classList.remove("hidden");
|
|
105
|
+
|
|
106
|
+
window.setTimeout(() => {
|
|
107
|
+
this.setState("open");
|
|
108
|
+
}, 0);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private closeDropdown() {
|
|
112
|
+
this.trigger?.focus();
|
|
113
|
+
this.setState("closed");
|
|
114
|
+
window.setTimeout(() => {
|
|
115
|
+
this.content?.classList.add("hidden");
|
|
116
|
+
}, 100);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private setState(state: "open" | "closed") {
|
|
120
|
+
this.content?.setAttribute("aria-hidden", `${state === "closed"}`);
|
|
121
|
+
this.content?.setAttribute("data-state", state);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private handleKeydown = (event: KeyboardEvent) => {
|
|
125
|
+
if (event.key === "Escape" && this.content!.dataset.state === "open") {
|
|
126
|
+
this.closeDropdown();
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
private handleMenuKeydown(event: KeyboardEvent, item: HTMLElement) {
|
|
132
|
+
const currentItemIndex = this.menuItems.indexOf(item);
|
|
133
|
+
|
|
134
|
+
const keyActions: Record<string, () => void> = {
|
|
135
|
+
ArrowDown: () => this.setFocusItem(currentItemIndex + 1),
|
|
136
|
+
ArrowUp: () => this.setFocusItem(currentItemIndex - 1),
|
|
137
|
+
Home: () => this.setFocusItem(0),
|
|
138
|
+
End: () => this.setFocusItem(this.menuItems.length - 1),
|
|
139
|
+
Enter: () => item.click(),
|
|
140
|
+
" ": () => item.click(),
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const action = keyActions[event.key];
|
|
144
|
+
if (action) {
|
|
145
|
+
event.preventDefault();
|
|
146
|
+
action();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private setFocusItem(index: number) {
|
|
151
|
+
const newIndex = (index + this.menuItems.length) % this.menuItems.length;
|
|
152
|
+
|
|
153
|
+
if (this.menuItems[newIndex]) {
|
|
154
|
+
this.menuItems[newIndex].focus();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|