Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Fix: RadioGroupCard accessibility issues (#48527)

Gildas Garcia6cb08304d9d8
diff --git a/apps/design-system/content/docs/components/radio-group-card.mdx b/apps/design-system/content/docs/components/radio-group-card.mdx
index 26adb02c514..f30c838bdf9 100644
--- a/apps/design-system/content/docs/components/radio-group-card.mdx
+++ b/apps/design-system/content/docs/components/radio-group-card.mdx
@@ -18,10 +18,10 @@ import { RadioGroupCard, RadioGroupCardItem } from 'ui'
```
```tsx
-<RadioGroupCard defaultValue="comfortable">
- <RadioGroupCardItem value="default" id="r1" label="Default" />
- <RadioGroupCardItem value="comfortable" id="r2" label="Comfortable" />
- <RadioGroupCardItem value="compact" id="r3" label="Compact" />
+<RadioGroupCard defaultValue="comfortable" aria-label="Size">
+ <RadioGroupCardItem value="default" label="Default" />
+ <RadioGroupCardItem value="comfortable" label="Comfortable" />
+ <RadioGroupCardItem value="compact" label="Compact" />
</RadioGroupCard>
```
diff --git a/apps/design-system/content/docs/components/radio-group-stacked.mdx b/apps/design-system/content/docs/components/radio-group-stacked.mdx
index ff3c80616bf..a10fe095155 100644
--- a/apps/design-system/content/docs/components/radio-group-stacked.mdx
+++ b/apps/design-system/content/docs/components/radio-group-stacked.mdx
@@ -18,7 +18,7 @@ import { RadioGroupStacked, RadioGroupStackedItem } from 'ui'
```
```tsx
-<RadioGroupStacked defaultValue="comfortable">
+<RadioGroupStacked defaultValue="comfortable" aria-label="Size">
<RadioGroupStackedItem value="default" id="r1" label="Default" />
<RadioGroupStackedItem value="comfortable" id="r2" label="Comfortable" />
<RadioGroupStackedItem value="compact" id="r3" label="Compact" />
diff --git a/apps/design-system/content/docs/components/radio-group.mdx b/apps/design-system/content/docs/components/radio-group.mdx
index 8bd7e79ac52..f507c098d60 100644
--- a/apps/design-system/content/docs/components/radio-group.mdx
+++ b/apps/design-system/content/docs/components/radio-group.mdx
@@ -58,7 +58,7 @@ import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'
```
```tsx
-<RadioGroup defaultValue="option-one">
+<RadioGroup defaultValue="option-one" aria-label="Options">
<div className="flex items-center space-x-2">
<RadioGroupItem value="option-one" id="option-one" />
<Label htmlFor="option-one">Option One</Label>
diff --git a/apps/design-system/registry/default/example/radio-group-card-demo.tsx b/apps/design-system/registry/default/example/radio-group-card-demo.tsx
index 85e885d6e28..52cd0d3953c 100644
--- a/apps/design-system/registry/default/example/radio-group-card-demo.tsx
+++ b/apps/design-system/registry/default/example/radio-group-card-demo.tsx
@@ -2,10 +2,10 @@ import { RadioGroupCard, RadioGroupCardItem } from 'ui'
export default function RadioGroupDemo() {
return (
- <RadioGroupCard defaultValue="comfortable" className="flex flex-wrap gap-3">
- <RadioGroupCardItem value="default" id="r1" label="Default" />
- <RadioGroupCardItem value="comfortable" id="r2" label="Comfortable" />
- <RadioGroupCardItem value="compact" id="r3" label="Compact" />
+ <RadioGroupCard defaultValue="comfortable" className="flex flex-wrap gap-3" aria-label="Size">
+ <RadioGroupCardItem value="default" label="Default" />
+ <RadioGroupCardItem value="comfortable" label="Comfortable" />
+ <RadioGroupCardItem value="compact" label="Compact" />
</RadioGroupCard>
)
}
diff --git a/apps/design-system/registry/default/example/radio-group-card-form.tsx b/apps/design-system/registry/default/example/radio-group-card-form.tsx
index c873f87056f..3717507e31a 100644
--- a/apps/design-system/registry/default/example/radio-group-card-form.tsx
+++ b/apps/design-system/registry/default/example/radio-group-card-form.tsx
@@ -53,21 +53,9 @@ export default function RadioGroupForm() {
defaultValue={field.value}
className="flex flex-wrap gap-3"
>
- <FormItem asChild>
- <FormControl>
- <RadioGroupCardItem value="all" label="All new messages" />
- </FormControl>
- </FormItem>
- <FormItem asChild>
- <FormControl>
- <RadioGroupCardItem value="mentions" label="Direct messages and mentions" />
- </FormControl>
- </FormItem>
- <FormItem asChild>
- <FormControl>
- <RadioGroupCardItem value="none" label="Nothing" />
- </FormControl>
- </FormItem>
+ <RadioGroupCardItem value="all" label="All new messages" />
+ <RadioGroupCardItem value="mentions" label="Direct messages and mentions" />
+ <RadioGroupCardItem value="none" label="Nothing" />
</RadioGroupCard>
</FormControl>
<FormMessage />
diff --git a/apps/design-system/registry/default/example/radio-group-card-with-children.tsx b/apps/design-system/registry/default/example/radio-group-card-with-children.tsx
index bb33298a610..e4f1be820b1 100644
--- a/apps/design-system/registry/default/example/radio-group-card-with-children.tsx
+++ b/apps/design-system/registry/default/example/radio-group-card-with-children.tsx
@@ -10,7 +10,7 @@ export default function RadioGroupDemo() {
] as const
return (
- <RadioGroupCard defaultValue="comfortable" className="flex flex-wrap gap-3">
+ <RadioGroupCard defaultValue="dark" className="flex flex-wrap gap-3" aria-label="Theme">
{singleThemes.map((theme) => (
<RadioGroupCardItem key={theme.value} value={theme.value} label={theme.name}>
<SVG src={`${process.env.NEXT_PUBLIC_BASE_PATH}/img/themes/${theme.value}.svg`} />
diff --git a/apps/design-system/registry/default/example/radio-group-demo.tsx b/apps/design-system/registry/default/example/radio-group-demo.tsx
index 69086855cac..677d047905e 100644
--- a/apps/design-system/registry/default/example/radio-group-demo.tsx
+++ b/apps/design-system/registry/default/example/radio-group-demo.tsx
@@ -2,7 +2,7 @@ import { Label, RadioGroup, RadioGroupItem } from 'ui'
export default function RadioGroupDemo() {
return (
- <RadioGroup defaultValue="comfortable">
+ <RadioGroup defaultValue="comfortable" aria-label="Size">
<div className="flex items-center space-x-2">
<RadioGroupItem value="default" id="r1" />
<Label htmlFor="r1">Default</Label>
diff --git a/apps/design-system/registry/default/example/radio-group-form.tsx b/apps/design-system/registry/default/example/radio-group-form.tsx
index edd035db328..8893a529bdb 100644
--- a/apps/design-system/registry/default/example/radio-group-form.tsx
+++ b/apps/design-system/registry/default/example/radio-group-form.tsx
@@ -52,24 +52,24 @@ export default function RadioGroupForm() {
defaultValue={field.value}
className="flex flex-col space-y-1"
>
- <FormItem className="flex items-center space-x-3 space-y-0">
- <FormControl>
- <RadioGroupItem value="all" />
- </FormControl>
- <FormLabel className="font-normal">All new messages</FormLabel>
- </FormItem>
- <FormItem className="flex items-center space-x-3 space-y-0">
- <FormControl>
- <RadioGroupItem value="mentions" />
- </FormControl>
- <FormLabel className="font-normal">Direct messages and mentions</FormLabel>
- </FormItem>
- <FormItem className="flex items-center space-x-3 space-y-0">
- <FormControl>
- <RadioGroupItem value="none" />
- </FormControl>
- <FormLabel className="font-normal">Nothing</FormLabel>
- </FormItem>
+ <div className="flex items-center space-x-3 space-y-0">
+ <RadioGroupItem value="all" id="type-all" />
+ <FormLabel className="font-normal" htmlFor="type-all">
+ All new messages
+ </FormLabel>
+ </div>
+ <div className="flex items-center space-x-3 space-y-0">
+ <RadioGroupItem value="mentions" id="type-mentions" />
+ <FormLabel className="font-normal" htmlFor="type-mentions">
+ Direct messages and mentions
+ </FormLabel>
+ </div>
+ <div className="flex items-center space-x-3 space-y-0">
+ <RadioGroupItem value="none" id="type-none" />
+ <FormLabel className="font-normal" htmlFor="type-none">
+ Nothing
+ </FormLabel>
+ </div>
</RadioGroup>
</FormControl>
<FormMessage />
diff --git a/apps/design-system/registry/default/example/radio-group-stacked-demo.tsx b/apps/design-system/registry/default/example/radio-group-stacked-demo.tsx
index b8de098b5fa..3e833b03244 100644
--- a/apps/design-system/registry/default/example/radio-group-stacked-demo.tsx
+++ b/apps/design-system/registry/default/example/radio-group-stacked-demo.tsx
@@ -2,7 +2,7 @@ import { RadioGroupStacked, RadioGroupStackedItem } from 'ui'
export default function RadioGroupDemo() {
return (
- <RadioGroupStacked defaultValue="comfortable">
+ <RadioGroupStacked defaultValue="comfortable" aria-label="Size">
<RadioGroupStackedItem
value="default"
id="r1"
diff --git a/apps/design-system/registry/default/example/radio-group-stacked-form.tsx b/apps/design-system/registry/default/example/radio-group-stacked-form.tsx
index bda3ef3925c..130bc3b7302 100644
--- a/apps/design-system/registry/default/example/radio-group-stacked-form.tsx
+++ b/apps/design-system/registry/default/example/radio-group-stacked-form.tsx
@@ -49,24 +49,9 @@ export default function RadioGroupForm() {
<FormLabel>Notify me about...</FormLabel>
<FormControl>
<RadioGroupStacked onValueChange={field.onChange} defaultValue={field.value}>
- <FormItem asChild>
- <FormControl>
- <RadioGroupStackedItem value="all" label="All new messages" />
- </FormControl>
- </FormItem>
- <FormItem asChild>
- <FormControl>
- <RadioGroupStackedItem
- value="mentions"
- label="Direct messages and mentions"
- />
- </FormControl>
- </FormItem>
- <FormItem asChild>
- <FormControl>
- <RadioGroupStackedItem value="none" label="Nothing" />
- </FormControl>
- </FormItem>
+ <RadioGroupStackedItem value="all" label="All new messages" />
+ <RadioGroupStackedItem value="mentions" label="Direct messages and mentions" />
+ <RadioGroupStackedItem value="none" label="Nothing" />
</RadioGroupStacked>
</FormControl>
<FormMessage />
diff --git a/apps/studio/components/interfaces/DiskManagement/fields/ComputeSizeField.tsx b/apps/studio/components/interfaces/DiskManagement/fields/ComputeSizeField.tsx
index 7f8b36d6ac5..01d3f17f8d4 100644
--- a/apps/studio/components/interfaces/DiskManagement/fields/ComputeSizeField.tsx
+++ b/apps/studio/components/interfaces/DiskManagement/fields/ComputeSizeField.tsx
@@ -193,7 +193,7 @@ export function ComputeSizeField({ form, disabled }: ComputeSizeFieldProps) {
key={compute.identifier}
value={compute.identifier}
className={cn(
- 'relative text-sm text-left flex flex-col gap-0 px-0 py-3 [&_label]:w-full group w-full h-[110px]',
+ 'relative text-sm text-left flex flex-col gap-0 px-0 py-3 group w-full h-[110px]',
lockedOption && 'opacity-50'
)}
disabled={disabled || lockedOption}
diff --git a/apps/studio/components/interfaces/LogDrains/LogDrainDestinationSheetForm.tsx b/apps/studio/components/interfaces/LogDrains/LogDrainDestinationSheetForm.tsx
index 56c288a0ef6..0fdbf8eab0f 100644
--- a/apps/studio/components/interfaces/LogDrains/LogDrainDestinationSheetForm.tsx
+++ b/apps/studio/components/interfaces/LogDrains/LogDrainDestinationSheetForm.tsx
@@ -502,16 +502,8 @@ export function LogDrainDestinationSheetForm({
onValueChange={field.onChange}
value={field.value}
>
- <FormItem asChild>
- <FormControl>
- <RadioGroupCardItem value="http1" label="HTTP/1" />
- </FormControl>
- </FormItem>
- <FormItem asChild>
- <FormControl>
- <RadioGroupCardItem value="http2" label="HTTP/2" />
- </FormControl>
- </FormItem>
+ <RadioGroupCardItem value="http1" label="HTTP/1" />
+ <RadioGroupCardItem value="http2" label="HTTP/2" />
</RadioGroupCard>
</FormControl>
</FormItemLayout>
diff --git a/apps/studio/components/interfaces/ProjectCreation/AdvancedConfiguration.tsx b/apps/studio/components/interfaces/ProjectCreation/AdvancedConfiguration.tsx
index ef41eea090d..e8b3721d06e 100644
--- a/apps/studio/components/interfaces/ProjectCreation/AdvancedConfiguration.tsx
+++ b/apps/studio/components/interfaces/ProjectCreation/AdvancedConfiguration.tsx
@@ -63,7 +63,7 @@ export const AdvancedConfiguration = ({ form }: AdvancedConfigurationProps) => {
</>
}
description="Recommended for production workloads"
- className="[&>div>div>p]:text-left [&>div>div>p]:text-xs [&>div>div>label]:flex [&>div>div>label]:items-center [&>div>div>label]:gap-x-2"
+ className="[&>div>div>p]:text-left [&>div>div>p]:text-xs [&>div>div>div]:flex [&>div>div>div]:items-center [&>div>div>div]:gap-x-2"
/>
</FormControl>
</FormItem>
@@ -82,7 +82,7 @@ export const AdvancedConfiguration = ({ form }: AdvancedConfigurationProps) => {
}
description="Not recommended for production workloads"
className={cn(
- '[&>div>div>p]:text-left [&>div>div>p]:text-xs [&>div>div>label]:flex [&>div>div>label]:items-center [&>div>div>label]:gap-x-2',
+ '[&>div>div>p]:text-left [&>div>div>p]:text-xs [&>div>div>div]:flex [&>div>div>div]:items-center [&>div>div>div]:gap-x-2',
form.getValues('useOrioleDb') ? 'rounded-b-none!' : ''
)}
disabled={disableOrioleProjectCreation}
diff --git a/packages/ui/src/components/radio-group-card.tsx b/packages/ui/src/components/radio-group-card.tsx
index b51a2a5667b..dc62ce535d7 100644
--- a/packages/ui/src/components/radio-group-card.tsx
+++ b/packages/ui/src/components/radio-group-card.tsx
@@ -29,10 +29,14 @@ interface RadioGroupCardItemProps {
const RadioGroupCardItem = React.forwardRef<
React.ElementRef<typeof RadioGroupPrimitive.Item>,
RadioGroupCardItemProps & React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>
->(({ image, label, showIndicator = true, ...props }, ref) => {
+>(({ id: idProp, children, className, image, label, showIndicator = true, ...props }, ref) => {
+ const generatedId = React.useId()
+ const id = idProp || generatedId
return (
<RadioGroupPrimitive.Item
ref={ref}
+ id={id}
+ aria-labelledby={`${id}-label`}
{...props}
className={cn(
'flex flex-col gap-2',
@@ -48,11 +52,11 @@ const RadioGroupCardItem = React.forwardRef<
'transition-colors',
'group',
'data-[state=checked]:border-control-hover',
- props.className
+ className
)}
>
- {props.children}
- <label className="flex gap-2 w-full" id={props.id} htmlFor={props.value}>
+ {children}
+ <div className="flex gap-2 w-full" id={`${id}-label`}>
{showIndicator && (
<div
className="
@@ -85,7 +89,7 @@ const RadioGroupCardItem = React.forwardRef<
>
{label}
</div>
- </label>
+ </div>
</RadioGroupPrimitive.Item>
)
})
diff --git a/packages/ui/src/components/radio-group-stacked.tsx b/packages/ui/src/components/radio-group-stacked.tsx
index 12b0da4d11d..a2a22264f79 100644
--- a/packages/ui/src/components/radio-group-stacked.tsx
+++ b/packages/ui/src/components/radio-group-stacked.tsx
@@ -4,7 +4,6 @@ import { Circle } from 'lucide-react'
import { RadioGroup as RadioGroupPrimitive } from 'radix-ui'
import * as React from 'react'
-import { Label } from '../components/shadcn/ui/label'
import { cn } from '../lib/utils/cn'
const RadioGroupStacked = React.forwardRef<
@@ -32,10 +31,14 @@ interface RadioGroupStackedItemProps {
const RadioGroupStackedItem = React.forwardRef<
React.ElementRef<typeof RadioGroupPrimitive.Item>,
RadioGroupStackedItemProps & React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>
->(({ image, label, showIndicator = true, ...props }, ref) => {
+>(({ id: idProp, image, label, showIndicator = true, ...props }, ref) => {
+ const generatedId = React.useId()
+ const id = idProp || generatedId
return (
<RadioGroupPrimitive.Item
ref={ref}
+ id={id}
+ aria-labelledby={`${id}-label`}
{...props}
className={cn(
// Base layout and sizing
@@ -78,8 +81,8 @@ const RadioGroupStackedItem = React.forwardRef<
</div>
)}
<div className="flex flex-col gap-0.25 items-start">
- <Label
- htmlFor={props.value}
+ <div
+ id={`${id}-label`}
className={cn(
// Base styles
'block mt-[-0.15rem] text-sm text-left text-light',
@@ -90,7 +93,7 @@ const RadioGroupStackedItem = React.forwardRef<
)}
>
{label}
- </Label>
+ </div>
{props.description && (
<p className="text-left text-sm text-foreground-lighter text-balance">
{props.description}
diff --git a/packages/ui/src/components/shadcn/ui/radio-group.tsx b/packages/ui/src/components/shadcn/ui/radio-group.tsx
index 8924e0449f6..d57d8f028cb 100644
--- a/packages/ui/src/components/shadcn/ui/radio-group.tsx
+++ b/packages/ui/src/components/shadcn/ui/radio-group.tsx
@@ -50,10 +50,13 @@ interface RadioGroupLargeItemProps {
const RadioGroupLargeItem = React.forwardRef<
React.ElementRef<typeof RadioGroupPrimitive.Item>,
RadioGroupLargeItemProps & React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>
->(({ image, label, showIndicator = true, ...props }, ref) => {
+>(({ id: idProp, image, label, showIndicator = true, ...props }, ref) => {
+ const generatedId = React.useId()
+ const id = idProp || generatedId
return (
<RadioGroupPrimitive.Item
ref={ref}
+ id={id}
{...props}
className={cn(
'flex flex-col gap-2',
@@ -101,7 +104,7 @@ const RadioGroupLargeItem = React.forwardRef<
)}
<label
- htmlFor={props.value}
+ htmlFor={id}
className={cn(
'text-xs transition-colors text-left',
'text-light',