Skip to content

Commit 616cf91

Browse files
committed
fix: improve indexes and ensure order
1 parent 8d02b55 commit 616cf91

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/client/editor/Editor.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export const Editor: FC<EditorProps> = ({
108108
{snippets.map(
109109
({ name, label, icon: Icon, snippet }, index) => (
110110
<DropdownMenuItem
111-
key={index}
111+
key={`${label}-${index}`}
112112
onClick={() => onAddSnippet(name, snippet)}
113113
>
114114
<Icon size={24} />
@@ -131,21 +131,26 @@ export const Editor: FC<EditorProps> = ({
131131

132132
<DropdownMenuPortal>
133133
<DropdownMenuContent>
134-
{Object.entries(examples).map(([slug, title]) => {
135-
const href = `${window.location.origin}/parameters/example/${slug}`;
136-
return (
137-
<DropdownMenuItem key={slug} asChild={true}>
138-
<a href={href} target="_blank" rel="noreferrer">
139-
<span className="sr-only">
140-
{" "}
141-
(link opens in new tab)
142-
</span>
143-
<ExternalLinkIcon />
144-
{title}
145-
</a>
146-
</DropdownMenuItem>
147-
);
148-
})}
134+
{Object.entries(examples)
135+
.sort()
136+
.map(([slug, title], index) => {
137+
const href = `${window.location.origin}/parameters/example/${slug}`;
138+
return (
139+
<DropdownMenuItem
140+
key={`${slug}-${index}`}
141+
asChild={true}
142+
>
143+
<a href={href} target="_blank" rel="noreferrer">
144+
<span className="sr-only">
145+
{" "}
146+
(link opens in new tab)
147+
</span>
148+
<ExternalLinkIcon />
149+
{title}
150+
</a>
151+
</DropdownMenuItem>
152+
);
153+
})}
149154
</DropdownMenuContent>
150155
</DropdownMenuPortal>
151156
</DropdownMenu>

0 commit comments

Comments
 (0)