Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

♿ Give CommandDialog a default accessible name (#2766)

Luke Vella59a71fab20be
diff --git a/apps/web/src/features/navigation/components/command-menu/command-menu.tsx b/apps/web/src/features/navigation/components/command-menu/command-menu.tsx
index a56ba6d29..f147a2d47 100644
--- a/apps/web/src/features/navigation/components/command-menu/command-menu.tsx
+++ b/apps/web/src/features/navigation/components/command-menu/command-menu.tsx
@@ -8,7 +8,7 @@ import {
CommandItem,
CommandList,
} from "@rallly/ui/command";
-import { DialogDescription, DialogTitle, useDialog } from "@rallly/ui/dialog";
+import { useDialog } from "@rallly/ui/dialog";
import { Icon } from "@rallly/ui/icon";
import { PlusIcon } from "lucide-react";
import { useRouter } from "next/navigation";
@@ -49,13 +49,13 @@ export function CommandMenu() {
return (
<>
<CommandGlobalShortcut trigger={trigger} />
- <CommandDialog {...dialogProps}>
- <DialogTitle className="sr-only">
- <Trans i18nKey="commandMenu" defaults="Command Menu" />
- </DialogTitle>
- <DialogDescription className="sr-only">
+ <CommandDialog
+ {...dialogProps}
+ title={<Trans i18nKey="commandMenu" defaults="Command Menu" />}
+ description={
<Trans i18nKey="commandMenuDescription" defaults="Select a command" />
- </DialogDescription>
+ }
+ >
<CommandInput
autoFocus={true}
placeholder={t("commandMenuSearchPlaceholder", {
diff --git a/packages/ui/src/command.tsx b/packages/ui/src/command.tsx
index 07d4f8b2a..7ddfd01e8 100644
--- a/packages/ui/src/command.tsx
+++ b/packages/ui/src/command.tsx
@@ -5,7 +5,12 @@ import { SearchIcon } from "lucide-react";
import * as React from "react";
import type { DialogProps } from "./dialog";
-import { Dialog, DialogContent } from "./dialog";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogTitle,
+} from "./dialog";
import { usePlatform } from "./hooks/use-platform";
import { Icon } from "./icon";
import { cn } from "./lib/utils";
@@ -25,12 +30,30 @@ const Command = React.forwardRef<
));
Command.displayName = CommandPrimitive.displayName;
-type CommandDialogProps = DialogProps;
+type CommandDialogProps = DialogProps & {
+ /** Accessible name for the dialog. Rendered visually hidden by default so the
+ * dialog always has a name; pass `null` to supply your own `DialogTitle`. */
+ title?: React.ReactNode;
+ description?: React.ReactNode;
+};
-const CommandDialog = ({ children, ...props }: CommandDialogProps) => {
+const CommandDialog = ({
+ children,
+ title = "Command Menu",
+ description,
+ ...props
+}: CommandDialogProps) => {
return (
<Dialog {...props}>
<DialogContent showCloseButton={false} size="xl" className="p-0">
+ {title != null && (
+ <DialogTitle className="sr-only">{title}</DialogTitle>
+ )}
+ {description != null && (
+ <DialogDescription className="sr-only">
+ {description}
+ </DialogDescription>
+ )}
<Command className="[&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:size-4 [&_[cmdk-item]_svg]:size-4 [[cmdk-group-heading]]:**:px-2 [[cmdk-group-heading]]:**:font-medium [[cmdk-group-heading]]:**:text-muted-foreground [[cmdk-group]]:**:px-2 [[cmdk-input]]:**:h-12 [[cmdk-item]]:**:p-2">
{children}
</Command>