Skip to content

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

fix(ui): bake explicit tabindex into interactive primitives (#47984)

Danny White6f19dfe18c18
diff --git a/apps/design-system/content/docs/accessibility.mdx b/apps/design-system/content/docs/accessibility.mdx
index 35bebb64804..a549d1eb7b6 100644
--- a/apps/design-system/content/docs/accessibility.mdx
+++ b/apps/design-system/content/docs/accessibility.mdx
@@ -27,7 +27,7 @@ Chromium-based browsers and Firefox handle this automatically via the Tab key. S
Interactive page elements should also provide visual feedback upon selection via a `focus-visible` state. We use consistent focus styles such as `inset-focus` so users recognize this state instantly.
-[Button](components/button) has all of the above built-in. Bespoke interactive elements however, such as the below interactive [Table Row](components/table#examples), require these props to be added manually:
+[Button](components/button) has all of the above built-in. The same explicit `tabIndex` default is also baked into Checkbox, Switch, Select Trigger, Toggle, Accordion Trigger, Collapsible Trigger, Dropdown Menu Trigger, Popover Trigger, Dialog Trigger, Sheet Trigger, Alert Dialog Trigger, and the Sidebar Menu and action buttons. Bespoke interactive elements however, such as the below interactive [Table Row](components/table#examples), require these props to be added manually:
```tsx showLineNumbers {4-14}
<TableRow
diff --git a/apps/studio/.github/eslint-rule-baselines.json b/apps/studio/.github/eslint-rule-baselines.json
index b75037cf884..f958116f061 100644
--- a/apps/studio/.github/eslint-rule-baselines.json
+++ b/apps/studio/.github/eslint-rule-baselines.json
@@ -19,7 +19,8 @@
"jsx-a11y/tabindex-no-positive": 0,
"jsx-a11y/anchor-is-valid": 7,
"jsx-a11y/heading-has-content": 2,
- "jsx-a11y/no-distracting-elements": 0
+ "jsx-a11y/no-distracting-elements": 0,
+ "supabase/require-explicit-tabindex": 82
},
"ruleFiles": {
"react-hooks/exhaustive-deps": {
@@ -1067,6 +1068,72 @@
"jsx-a11y/heading-has-content": {
"components/layouts/Scaffold.tsx": 2
},
- "jsx-a11y/no-distracting-elements": {}
+ "jsx-a11y/no-distracting-elements": {},
+ "supabase/require-explicit-tabindex": {
+ "components/grid/components/grid/ColumnHeader.tsx": 1,
+ "components/grid/components/header/sort/SortRow.tsx": 1,
+ "components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx": 1,
+ "components/interfaces/BranchManagement/EdgeFunctionsDiffPanel.tsx": 1,
+ "components/interfaces/BranchManagement/WorkflowLogs.tsx": 1,
+ "components/interfaces/Connect/OrganizationSelector.tsx": 1,
+ "components/interfaces/ConnectSheet/ConnectConfigSection.tsx": 1,
+ "components/interfaces/ConnectSheet/ConnectionParameters.tsx": 1,
+ "components/interfaces/Database/EnumeratedTypes/EnumeratedTypeValueRow.tsx": 1,
+ "components/interfaces/Database/Policies/PolicyEditorPanel/PolicyEditorPanelHeader.tsx": 1,
+ "components/interfaces/Database/Privileges/PrivilegesTable.tsx": 1,
+ "components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DuckLake/Fields.tsx": 1,
+ "components/interfaces/Database/Replication/DestinationPanel/ReadReplicaForm/ReadReplicaPricingDialog.tsx": 1,
+ "components/interfaces/Database/Replication/ReplicationPipelineStatus/SlotLagMetrics.tsx": 1,
+ "components/interfaces/Database/Replication/ReplicationPipelineStatus/SlotStatus.tsx": 1,
+ "components/interfaces/Database/Replication/ReplicationPipelineStatus/TableReplicationRow.tsx": 1,
+ "components/interfaces/Database/Roles/RoleRow.tsx": 1,
+ "components/interfaces/Database/Roles/RolesList.tsx": 2,
+ "components/interfaces/Database/Triggers/TriggerSheet.tsx": 1,
+ "components/interfaces/ExplainVisualizer/ExplainVisualizer.NodeRow.tsx": 1,
+ "components/interfaces/Functions/CommandRender.tsx": 1,
+ "components/interfaces/Functions/EdgeFunctionsListItem.tsx": 1,
+ "components/interfaces/Integrations/Integration/MarkdownContent.tsx": 1,
+ "components/interfaces/Integrations/Marketplace/MarketplaceFilterBar.tsx": 3,
+ "components/interfaces/LogDrains/LogDrainsCard.tsx": 1,
+ "components/interfaces/Observability/ServiceHealthTable.tsx": 1,
+ "components/interfaces/Organization/OrganizationCard.tsx": 1,
+ "components/interfaces/Organization/PrivateApps/Apps/ViewAppSheet/ViewAppSheetInfo.tsx": 1,
+ "components/interfaces/ProjectAPIDocs/FirstLevelNav.tsx": 6,
+ "components/interfaces/ProjectAPIDocs/SecondLevelNav.Layout.tsx": 1,
+ "components/interfaces/ProjectHome/ConnectSection.tsx": 1,
+ "components/interfaces/ProjectHome/SortableSection.tsx": 1,
+ "components/interfaces/QueryInsights/QueryInsightsChart/QueryInsightsChart.tsx": 2,
+ "components/interfaces/QueryPerformance/QueryPerformanceMetrics.tsx": 2,
+ "components/interfaces/Settings/Integrations/VercelIntegration/VercelIntegrationConnectionForm.tsx": 3,
+ "components/interfaces/Storage/BucketFilePickerDialog/BucketFilePickerHeader.tsx": 1,
+ "components/interfaces/Storage/StorageExplorer/FileExplorerRowEditing.tsx": 1,
+ "components/interfaces/Storage/StorageExplorer/MoveItemsModal.tsx": 1,
+ "components/interfaces/Storage/StoragePolicies/StoragePoliciesBucketsSection.tsx": 1,
+ "components/interfaces/Storage/StoragePolicies/StoragePolicyEditorModalTitle.tsx": 1,
+ "components/interfaces/Storage/StorageSettings/StorageSettings.ValidateSizeLimit.tsx": 1,
+ "components/interfaces/Support/AttachmentUpload.tsx": 3,
+ "components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadsheetImportPreview.tsx": 1,
+ "components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx": 3,
+ "components/layouts/EdgeFunctionsLayout/EdgeFunctionDetailsLayout.tsx": 1,
+ "components/layouts/Navigation/LayoutHeader/FeedbackDropdown/FeedbackWidget.tsx": 1,
+ "components/layouts/ProjectLayout/LayoutHeader/MobileMenuContent/OrgMenuItem.tsx": 1,
+ "components/layouts/ProjectLayout/LayoutHeader/MobileMenuContent/TopLevelRouteItem.tsx": 1,
+ "components/layouts/TableEditorLayout/EntityListItem.tsx": 1,
+ "components/layouts/Tabs/CollapseButton.tsx": 1,
+ "components/layouts/Tabs/SortableTab.tsx": 1,
+ "components/layouts/Tabs/Tabs.tsx": 1,
+ "components/ui/AIAssistantPanel/ModelSelector.tsx": 1,
+ "components/ui/Charts/ChartHighlightActions.tsx": 1,
+ "components/ui/Charts/ComposedChart.utils.tsx": 1,
+ "components/ui/ComputeBadgeWrapper.tsx": 1,
+ "components/ui/DataTable/DataTableFilters/DataTableFilterCheckbox.tsx": 2,
+ "components/ui/DataTable/DataTableFilters/DataTableFilterCheckboxAsync.tsx": 1,
+ "components/ui/DevToolbar/ProjectStatusTab.tsx": 1,
+ "components/ui/DevToolbar/ResourceWarningsTab.tsx": 2,
+ "components/ui/FeaturePreviewBadge.tsx": 1,
+ "components/ui/FilterPopover.tsx": 1,
+ "components/ui/PasswordStrengthBar.tsx": 1,
+ "components/ui/SingleStat.tsx": 1
+ }
}
}
diff --git a/apps/studio/scripts/ratchet-rules.json b/apps/studio/scripts/ratchet-rules.json
index 4f0135b422e..c681e8b26c9 100644
--- a/apps/studio/scripts/ratchet-rules.json
+++ b/apps/studio/scripts/ratchet-rules.json
@@ -18,5 +18,6 @@
"jsx-a11y/tabindex-no-positive",
"jsx-a11y/anchor-is-valid",
"jsx-a11y/heading-has-content",
- "jsx-a11y/no-distracting-elements"
+ "jsx-a11y/no-distracting-elements",
+ "supabase/require-explicit-tabindex"
]
diff --git a/packages/eslint-config-supabase/next.js b/packages/eslint-config-supabase/next.js
index 8de68d8cb2c..049e34bacdd 100644
--- a/packages/eslint-config-supabase/next.js
+++ b/packages/eslint-config-supabase/next.js
@@ -9,6 +9,7 @@ const tsparser = require('@typescript-eslint/parser')
// Custom Supabase rules
const noAwaitBeforeCopyToClipboard = require('./rules/no-await-before-copy-to-clipboard')
+const requireExplicitTabIndex = require('./rules/require-explicit-tabindex')
const compat = new FlatCompat({
baseDirectory: __dirname,
@@ -20,6 +21,7 @@ const compat = new FlatCompat({
const supabasePlugin = {
rules: {
'no-await-before-copy-to-clipboard': noAwaitBeforeCopyToClipboard,
+ 'require-explicit-tabindex': requireExplicitTabIndex,
},
}
@@ -41,6 +43,7 @@ const typescriptConfig = {
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
'supabase/no-await-before-copy-to-clipboard': 'error',
+ 'supabase/require-explicit-tabindex': 'warn',
},
}
diff --git a/packages/eslint-config-supabase/rules/require-explicit-tabindex.js b/packages/eslint-config-supabase/rules/require-explicit-tabindex.js
new file mode 100644
index 00000000000..43b8d273b9b
--- /dev/null
+++ b/packages/eslint-config-supabase/rules/require-explicit-tabindex.js
@@ -0,0 +1,93 @@
+/**
+ * ESLint rule requiring an explicit tabIndex on raw interactive elements.
+ *
+ * An explicit tabIndex={0} puts the control in sequential focus order even when
+ * the user agent only tabs to text fields by default (Safari / macOS Keyboard
+ * navigation). Prefer Button from `ui`, which sets this by default; when using
+ * raw <button> / role="button", set tabIndex.
+ *
+ * BAD:
+ * <button onClick={...}>Save</button>
+ * <div role="button" onClick={...}>Save</div>
+ *
+ * GOOD:
+ * <button tabIndex={0} onClick={...}>Save</button>
+ * <Button onClick={...}>Save</Button>
+ * <button tabIndex={disabled ? -1 : 0} onClick={...}>Save</button>
+ */
+
+/** @type {import('eslint').Rule.RuleModule} */
+module.exports = {
+ meta: {
+ type: 'suggestion',
+ docs: {
+ description:
+ 'Require explicit tabIndex on raw <button> and role="button" elements for keyboard focus',
+ recommended: true,
+ },
+ messages: {
+ missingTabIndex:
+ 'Add an explicit tabIndex={0} (or -1 when disabled) for keyboard focus, or use Button from `ui` which sets it by default.',
+ },
+ schema: [],
+ },
+
+ create(context) {
+ /**
+ * @param {import('estree').Node | null | undefined} node
+ * @returns {boolean}
+ */
+ function isButtonRole(node) {
+ if (!node || node.type !== 'JSXAttribute') return false
+ if (node.name.type !== 'JSXIdentifier' || node.name.name !== 'role') return false
+ const value = node.value
+ if (!value) return false
+ if (value.type === 'Literal' && value.value === 'button') return true
+ if (
+ value.type === 'JSXExpressionContainer' &&
+ value.expression.type === 'Literal' &&
+ value.expression.value === 'button'
+ ) {
+ return true
+ }
+ return false
+ }
+
+ /**
+ * @param {import('estree').Node} openingElement
+ * @returns {boolean}
+ */
+ function hasTabIndex(openingElement) {
+ return openingElement.attributes.some(
+ (attr) =>
+ attr.type === 'JSXAttribute' &&
+ attr.name.type === 'JSXIdentifier' &&
+ attr.name.name === 'tabIndex'
+ )
+ }
+
+ /**
+ * @param {import('estree').Node} openingElement
+ * @returns {boolean}
+ */
+ function shouldRequireTabIndex(openingElement) {
+ const name = openingElement.name
+ if (name.type === 'JSXIdentifier' && name.name === 'button') {
+ return true
+ }
+ return openingElement.attributes.some(isButtonRole)
+ }
+
+ return {
+ JSXOpeningElement(node) {
+ if (!shouldRequireTabIndex(node)) return
+ if (hasTabIndex(node)) return
+
+ context.report({
+ node,
+ messageId: 'missingTabIndex',
+ })
+ },
+ }
+ },
+}
diff --git a/packages/ui/src/components/Button/Button.tsx b/packages/ui/src/components/Button/Button.tsx
index f110cb94061..28e4d5a9471 100644
--- a/packages/ui/src/components/Button/Button.tsx
+++ b/packages/ui/src/components/Button/Button.tsx
@@ -7,6 +7,7 @@ import { cloneElement, forwardRef, isValidElement, ReactNode } from 'react'
import { SIZE_VARIANTS, SIZE_VARIANTS_DEFAULT } from '../../lib/constants'
import { cn } from '../../lib/utils/cn'
+import { getExplicitTabIndex } from '../../lib/utils/getExplicitTabIndex'
export type ButtonVariantProps = VariantProps<typeof buttonVariants>
const buttonVariants = cva(
@@ -233,11 +234,7 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(
// if loading, button is disabled
const disabled = loading === true || props.disabled
- // Set default tabIndex for proper Safari focus handling
- // - Explicit tabIndex prop takes precedence
- // - If disabled, default to -1 (unless explicitly set)
- // - Otherwise, default to 0 for keyboard accessibility
- const computedTabIndex = tabIndex !== undefined ? tabIndex : disabled ? -1 : 0
+ const computedTabIndex = getExplicitTabIndex(tabIndex, disabled)
const renderIconContainer = (content: ReactNode) => (
<div aria-hidden className={cn(IconContainerVariants({ size, variant }))}>
diff --git a/packages/ui/src/components/shadcn/ui/accordion.tsx b/packages/ui/src/components/shadcn/ui/accordion.tsx
index 34ed3cc306e..ee0f3c73b7a 100644
--- a/packages/ui/src/components/shadcn/ui/accordion.tsx
+++ b/packages/ui/src/components/shadcn/ui/accordion.tsx
@@ -1,10 +1,11 @@
'use client'
-import { Accordion as AccordionPrimitive } from 'radix-ui'
import { ChevronDown } from 'lucide-react'
+import { Accordion as AccordionPrimitive } from 'radix-ui'
import * as React from 'react'
import { cn } from '../../../lib/utils/cn'
+import { getExplicitTabIndex } from '../../../lib/utils/getExplicitTabIndex'
const Accordion = AccordionPrimitive.Root
@@ -19,32 +20,38 @@ AccordionItem.displayName = 'AccordionItem'
const AccordionTrigger = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger> & { hideIcon?: boolean }
->(({ className, children, hideIcon, ...props }, ref) => (
- <AccordionPrimitive.Header className="flex">
- <AccordionPrimitive.Trigger
- ref={ref}
- className={cn(
- 'cursor-pointer flex flex-1 gap-2 items-center justify-between py-4 text-left',
- 'font-medium transition-all hover:underline',
- '[&[data-state=open]>svg]:rotate-180',
- className
- )}
- {...props}
- >
- {children}
- {!hideIcon && (
- <ChevronDown
- aria-hidden="true"
- className={cn(
- 'h-4 w-4 shrink-0',
- 'transition-transform duration-200',
- 'motion-reduce:transition-none motion-reduce:duration-0'
- )}
- />
- )}
- </AccordionPrimitive.Trigger>
- </AccordionPrimitive.Header>
-))
+>(({ className, children, hideIcon, disabled, tabIndex, ...props }, ref) => {
+ const computedTabIndex = getExplicitTabIndex(tabIndex, disabled)
+
+ return (
+ <AccordionPrimitive.Header className="flex">
+ <AccordionPrimitive.Trigger
+ ref={ref}
+ className={cn(
+ 'cursor-pointer flex flex-1 gap-2 items-center justify-between py-4 text-left',
+ 'font-medium transition-all hover:underline',
+ '[&[data-state=open]>svg]:rotate-180',
+ className
+ )}
+ {...props}
+ disabled={disabled}
+ tabIndex={computedTabIndex}
+ >
+ {children}
+ {!hideIcon && (
+ <ChevronDown
+ aria-hidden="true"
+ className={cn(
+ 'h-4 w-4 shrink-0',
+ 'transition-transform duration-200',
+ 'motion-reduce:transition-none motion-reduce:duration-0'
+ )}
+ />
+ )}
+ </AccordionPrimitive.Trigger>
+ </AccordionPrimitive.Header>
+ )
+})
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName
const AccordionContent = React.forwardRef<
diff --git a/packages/ui/src/components/shadcn/ui/alert-dialog.tsx b/packages/ui/src/components/shadcn/ui/alert-dialog.tsx
index eca64e832a6..e02c894c259 100644
--- a/packages/ui/src/components/shadcn/ui/alert-dialog.tsx
+++ b/packages/ui/src/components/shadcn/ui/alert-dialog.tsx
@@ -5,6 +5,7 @@ import { AlertDialog as AlertDialogPrimitive } from 'radix-ui'
import * as React from 'react'
import { cn } from '../../../lib/utils/cn'
+import { getExplicitTabIndex } from '../../../lib/utils/getExplicitTabIndex'
import { Button, ButtonVariantProps, buttonVariants } from './../../Button'
type AlertDialogContextValue = {
@@ -75,7 +76,22 @@ const AlertDialog = ({
}
AlertDialog.displayName = AlertDialogPrimitive.Root.displayName
-const AlertDialogTrigger = AlertDialogPrimitive.Trigger
+const AlertDialogTrigger = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Trigger>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Trigger>
+>(({ disabled, tabIndex, ...props }, ref) => {
+ const computedTabIndex = getExplicitTabIndex(tabIndex, disabled)
+
+ return (
+ <AlertDialogPrimitive.Trigger
+ ref={ref}
+ {...props}
+ disabled={disabled}
+ tabIndex={computedTabIndex}
+ />
+ )
+})
+AlertDialogTrigger.displayName = AlertDialogPrimitive.Trigger.displayName
const AlertDialogPortal = ({ children, ...props }: AlertDialogPrimitive.AlertDialogPortalProps) => (
<AlertDialogPrimitive.Portal {...props}>
diff --git a/packages/ui/src/components/shadcn/ui/button.tsx b/packages/ui/src/components/shadcn/ui/button.tsx
index 759fdf605a8..222cc08dcb6 100644
--- a/packages/ui/src/components/shadcn/ui/button.tsx
+++ b/packages/ui/src/components/shadcn/ui/button.tsx
@@ -5,6 +5,7 @@ import { Slot as SlotPrimitive } from 'radix-ui'
import * as React from 'react'
import { cn } from '../../../lib/utils/cn'
+import { getExplicitTabIndex } from '../../../lib/utils/getExplicitTabIndex'
const buttonVariants = cva(
'inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-foreground-muted focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
@@ -38,10 +39,18 @@ export interface ButtonProps
}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
- ({ className, variant, size, asChild = false, ...props }, ref) => {
+ ({ className, variant, size, asChild = false, disabled, tabIndex, ...props }, ref) => {
const Comp = asChild ? SlotPrimitive.Slot : 'button'
+ const computedTabIndex = getExplicitTabIndex(tabIndex, disabled)
+
return (
- <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />
+ <Comp
+ className={cn(buttonVariants({ variant, size, className }))}
+ ref={ref}
+ {...props}
+ disabled={disabled}
+ tabIndex={computedTabIndex}
+ />
)
}
)
diff --git a/packages/ui/src/components/shadcn/ui/checkbox.tsx b/packages/ui/src/components/shadcn/ui/checkbox.tsx
index e3b3e96c244..33bfcc93242 100644
--- a/packages/ui/src/components/shadcn/ui/checkbox.tsx
+++ b/packages/ui/src/components/shadcn/ui/checkbox.tsx
@@ -5,28 +5,35 @@ import { Checkbox as CheckboxPrimitive } from 'radix-ui'
import * as React from 'react'
import { cn } from '../../../lib/utils/cn'
+import { getExplicitTabIndex } from '../../../lib/utils/getExplicitTabIndex'
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
->(({ className, ...props }, ref) => (
- <CheckboxPrimitive.Root
- ref={ref}
- className={cn(
- 'peer flex items-center justify-center h-4 w-4 shrink-0 rounded-sm border border-control bg-control/25 ring-offset-background',
- 'transition-colors duration-150 ease-in-out',
- 'hover:border-strong',
- 'focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-background-control focus-visible:ring-offset-2 focus-visible:ring-offset-foreground-muted',
- 'disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-foreground data-[state=checked]:text-background',
- className
- )}
- {...props}
- >
- <CheckboxPrimitive.Indicator className={cn('flex items-center justify-center text-current')}>
- <Check className="h-3 w-3 text-background" strokeWidth={4} />
- </CheckboxPrimitive.Indicator>
- </CheckboxPrimitive.Root>
-))
+>(({ className, disabled, tabIndex, ...props }, ref) => {
+ const computedTabIndex = getExplicitTabIndex(tabIndex, disabled)
+
+ return (
+ <CheckboxPrimitive.Root
+ ref={ref}
+ className={cn(
+ 'peer flex items-center justify-center h-4 w-4 shrink-0 rounded-sm border border-control bg-control/25 ring-offset-background',
+ 'transition-colors duration-150 ease-in-out',
+ 'hover:border-strong',
+ 'focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-background-control focus-visible:ring-offset-2 focus-visible:ring-offset-foreground-muted',
+ 'disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-foreground data-[state=checked]:text-background',
+ className
+ )}
+ {...props}
+ disabled={disabled}
+ tabIndex={computedTabIndex}
+ >
+ <CheckboxPrimitive.Indicator className={cn('flex items-center justify-center text-current')}>
+ <Check className="h-3 w-3 text-background" strokeWidth={4} />
+ </CheckboxPrimitive.Indicator>
+ </CheckboxPrimitive.Root>
+ )
+})
Checkbox.displayName = CheckboxPrimitive.Root.displayName
export { Checkbox }
diff --git a/packages/ui/src/components/shadcn/ui/collapsible.tsx b/packages/ui/src/components/shadcn/ui/collapsible.tsx
index 21169db91b7..c129f72c8ac 100644
--- a/packages/ui/src/components/shadcn/ui/collapsible.tsx
+++ b/packages/ui/src/components/shadcn/ui/collapsible.tsx
@@ -1,10 +1,28 @@
'use client'
import { Collapsible as CollapsiblePrimitive } from 'radix-ui'
+import * as React from 'react'
+
+import { getExplicitTabIndex } from '../../../lib/utils/getExplicitTabIndex'
const Collapsible = CollapsiblePrimitive.Root
-const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger
+const CollapsibleTrigger = React.forwardRef<
+ React.ElementRef<typeof CollapsiblePrimitive.CollapsibleTrigger>,
+ React.ComponentPropsWithoutRef<typeof CollapsiblePrimitive.CollapsibleTrigger>
+>(({ disabled, tabIndex, ...props }, ref) => {
+ const computedTabIndex = getExplicitTabIndex(tabIndex, disabled)
+
+ return (
+ <CollapsiblePrimitive.CollapsibleTrigger
+ ref={ref}
+ {...props}
+ disabled={disabled}
+ tabIndex={computedTabIndex}
+ />
+ )
+})
+CollapsibleTrigger.displayName = CollapsiblePrimitive.CollapsibleTrigger.displayName
const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent
diff --git a/packages/ui/src/components/shadcn/ui/command.tsx b/packages/ui/src/components/shadcn/ui/command.tsx
index b75f0d9b62c..f414dc31c05 100644
--- a/packages/ui/src/components/shadcn/ui/command.tsx
+++ b/packages/ui/src/components/shadcn/ui/command.tsx
@@ -69,6 +69,9 @@ const CommandInput = React.forwardRef<
/>
{showResetIcon && (
<button
+ type="button"
+ tabIndex={props.disabled || !props.value?.length ? -1 : 0}
+ disabled={props.disabled || !props.value?.length}
onClick={handleReset}
className={cn(
'text-foreground-lighter hover:text-foreground-light hover:cursor-pointer transition-all opacity-0 duration-100',
diff --git a/packages/ui/src/components/shadcn/ui/dialog.tsx b/packages/ui/src/components/shadcn/ui/dialog.tsx
index 6f72dc190b0..5edd2b3318e 100644
--- a/packages/ui/src/components/shadcn/ui/dialog.tsx
+++ b/packages/ui/src/components/shadcn/ui/dialog.tsx
@@ -6,6 +6,7 @@ import { Dialog as DialogPrimitive } from 'radix-ui'
import * as React from 'react'
import { cn } from '../../../lib/utils/cn'
+import { getExplicitTabIndex } from '../../../lib/utils/getExplicitTabIndex'
export const DIALOG_PADDING_Y_SMALL = 'py-4'
export const DIALOG_PADDING_X_SMALL = 'px-4 md:px-5'
@@ -27,7 +28,17 @@ const DialogPaddingVariants = cva('', {
const Dialog = DialogPrimitive.Root
-const DialogTrigger = DialogPrimitive.Trigger
+const DialogTrigger = React.forwardRef<
+ React.ElementRef<typeof DialogPrimitive.Trigger>,
+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Trigger>
+>(({ disabled, tabIndex, ...props }, ref) => {
+ const computedTabIndex = getExplicitTabIndex(tabIndex, disabled)
+
+ return (
+ <DialogPrimitive.Trigger ref={ref} {...props} disabled={disabled} tabIndex={computedTabIndex} />
+ )
+})
+DialogTrigger.displayName = DialogPrimitive.Trigger.displayName
const DialogPortal = (props: DialogPrimitive.DialogPortalProps) => (
<DialogPrimitive.Portal {...props} />
diff --git a/packages/ui/src/components/shadcn/ui/dropdown-menu.tsx b/packages/ui/src/components/shadcn/ui/dropdown-menu.tsx
index 73f58d6a821..1eb84f8031d 100644
--- a/packages/ui/src/components/shadcn/ui/dropdown-menu.tsx
+++ b/packages/ui/src/components/shadcn/ui/dropdown-menu.tsx
@@ -5,6 +5,7 @@ import { DropdownMenu as DropdownMenuPrimitive } from 'radix-ui'
import * as React from 'react'
import { cn } from '../../../lib/utils/cn'
+import { getExplicitTabIndex } from '../../../lib/utils/getExplicitTabIndex'
const DropdownMenu = ({
modal = false,
@@ -13,7 +14,22 @@ const DropdownMenu = ({
<DropdownMenuPrimitive.Root modal={modal} {...props} />
)
-const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger
+const DropdownMenuTrigger = React.forwardRef<
+ React.ElementRef<typeof DropdownMenuPrimitive.Trigger>,
+ React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Trigger>
+>(({ disabled, tabIndex, ...props }, ref) => {
+ const computedTabIndex = getExplicitTabIndex(tabIndex, disabled)
+
+ return (
+ <DropdownMenuPrimitive.Trigger
+ ref={ref}
+ {...props}
+ disabled={disabled}
+ tabIndex={computedTabIndex}
+ />
+ )
+})
+DropdownMenuTrigger.displayName = DropdownMenuPrimitive.Trigger.displayName
const DropdownMenuGroup = DropdownMenuPrimitive.Group
diff --git a/packages/ui/src/components/shadcn/ui/popover.tsx b/packages/ui/src/components/shadcn/ui/popover.tsx
index 6e151bdb8ca..55679902127 100644
--- a/packages/ui/src/components/shadcn/ui/popover.tsx
+++ b/packages/ui/src/components/shadcn/ui/popover.tsx
@@ -4,10 +4,28 @@ import { Popover as PopoverPrimitive } from 'radix-ui'
import * as React from 'react'
import { cn } from '../../../lib/utils/cn'
+import { getExplicitTabIndex } from '../../../lib/utils/getExplicitTabIndex'
import styles from './popover.module.css'
const Popover = PopoverPrimitive.Root
-const PopoverTrigger = PopoverPrimitive.Trigger
+
+const PopoverTrigger = React.forwardRef<
+ React.ElementRef<typeof PopoverPrimitive.Trigger>,
+ React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Trigger>
+>(({ disabled, tabIndex, ...props }, ref) => {
+ const computedTabIndex = getExplicitTabIndex(tabIndex, disabled)
+
+ return (
+ <PopoverPrimitive.Trigger
+ ref={ref}
+ {...props}
+ disabled={disabled}
+ tabIndex={computedTabIndex}
+ />
+ )
+})
+PopoverTrigger.displayName = PopoverPrimitive.Trigger.displayName
+
const PopoverAnchor = PopoverPrimitive.Anchor
export type PopoverContentProps = {
diff --git a/packages/ui/src/components/shadcn/ui/sheet.tsx b/packages/ui/src/components/shadcn/ui/sheet.tsx
index d85ee8a219a..975deb02132 100644
--- a/packages/ui/src/components/shadcn/ui/sheet.tsx
+++ b/packages/ui/src/components/shadcn/ui/sheet.tsx
@@ -1,15 +1,26 @@
'use client'
-import { Dialog as SheetPrimitive } from 'radix-ui'
import { cva, type VariantProps } from 'class-variance-authority'
import { X } from 'lucide-react'
+import { Dialog as SheetPrimitive } from 'radix-ui'
import * as React from 'react'
import { cn } from '../../../lib/utils/cn'
+import { getExplicitTabIndex } from '../../../lib/utils/getExplicitTabIndex'
const Sheet = SheetPrimitive.Root
-const SheetTrigger = SheetPrimitive.Trigger
+const SheetTrigger = React.forwardRef<
+ React.ElementRef<typeof SheetPrimitive.Trigger>,
+ React.ComponentPropsWithoutRef<typeof SheetPrimitive.Trigger>
+>(({ disabled, tabIndex, ...props }, ref) => {
+ const computedTabIndex = getExplicitTabIndex(tabIndex, disabled)
+
+ return (
+ <SheetPrimitive.Trigger ref={ref} {...props} disabled={disabled} tabIndex={computedTabIndex} />
+ )
+})
+SheetTrigger.displayName = SheetPrimitive.Trigger.displayName
const SheetClose = SheetPrimitive.Close
diff --git a/packages/ui/src/components/shadcn/ui/sidebar.tsx b/packages/ui/src/components/shadcn/ui/sidebar.tsx
index 5c2c0c82cac..24fdc0b08cc 100644
--- a/packages/ui/src/components/shadcn/ui/sidebar.tsx
+++ b/packages/ui/src/components/shadcn/ui/sidebar.tsx
@@ -6,7 +6,7 @@ import { PanelLeft } from 'lucide-react'
import { Separator as _SeparatorPrimitive, Slot as SlotPrimitive } from 'radix-ui'
import * as React from 'react'
-import { cn } from './../../../lib/utils'
+import { cn, getExplicitTabIndex } from './../../../lib/utils'
import { useIsMobile } from './../../hooks/use-mobile'
import { Button } from './button'
import { Input } from './input'
@@ -445,8 +445,9 @@ SidebarGroupLabel.displayName = 'SidebarGroupLabel'
const SidebarGroupAction = React.forwardRef<
HTMLButtonElement,
React.ComponentProps<'button'> & { asChild?: boolean }
->(({ className, asChild = false, ...props }, ref) => {
+>(({ className, asChild = false, disabled, tabIndex, ...props }, ref) => {
const Comp = asChild ? SlotPrimitive.Slot : 'button'
+ const computedTabIndex = getExplicitTabIndex(tabIndex, disabled)
return (
<Comp
@@ -460,6 +461,8 @@ const SidebarGroupAction = React.forwardRef<
className
)}
{...props}
+ disabled={disabled}
+ tabIndex={computedTabIndex}
/>
)
})
@@ -563,13 +566,9 @@ const SidebarMenuButton = React.forwardRef<
) => {
const Comp = asChild ? SlotPrimitive.Slot : 'button'
const { isMobile, state } = useSidebar()
- const { disabled, tabIndex } = props
+ const { disabled, tabIndex, ...rest } = props
- // Set default tabIndex for proper Safari focus handling
- // - Explicit tabIndex prop takes precedence
- // - If disabled, default to -1 (unless explicitly set)
- // - Otherwise, default to 0 for keyboard accessibility
- const computedTabIndex = tabIndex !== undefined ? tabIndex : disabled ? -1 : 0
+ const computedTabIndex = getExplicitTabIndex(tabIndex, disabled)
const button = (
<Comp
@@ -578,9 +577,10 @@ const SidebarMenuButton = React.forwardRef<
data-size={size}
data-active={isActive}
data-has-icon={hasIcon}
- tabIndex={computedTabIndex}
className={cn(sidebarMenuButtonVariants({ variant, size, hasIcon, isLoading }), className)}
- {...props}
+ {...rest}
+ disabled={disabled}
+ tabIndex={computedTabIndex}
/>
)
@@ -615,8 +615,9 @@ const SidebarMenuAction = React.forwardRef<
asChild?: boolean
showOnHover?: boolean
}
->(({ className, asChild = false, showOnHover = false, ...props }, ref) => {
+>(({ className, asChild = false, showOnHover = false, disabled, tabIndex, ...props }, ref) => {
const Comp = asChild ? SlotPrimitive.Slot : 'button'
+ const computedTabIndex = getExplicitTabIndex(tabIndex, disabled)
return (
<Comp
@@ -635,6 +636,8 @@ const SidebarMenuAction = React.forwardRef<
className
)}
{...props}
+ disabled={disabled}
+ tabIndex={computedTabIndex}
/>
)
})
diff --git a/packages/ui/src/components/shadcn/ui/table.tsx b/packages/ui/src/components/shadcn/ui/table.tsx
index 3c3a28d9118..f0948c89ff7 100644
--- a/packages/ui/src/components/shadcn/ui/table.tsx
+++ b/packages/ui/src/components/shadcn/ui/table.tsx
@@ -132,6 +132,7 @@ function TableHeadSort<TColumn extends string = string>({
return (
<button
type="button"
+ tabIndex={0}
className={cn(
'group/table-head-sort heading-meta whitespace-nowrap flex items-center gap-1 cursor-pointer select-none bg-transparent! border-none p-0 w-full text-left',
className
diff --git a/packages/ui/src/lib/utils/getExplicitTabIndex.ts b/packages/ui/src/lib/utils/getExplicitTabIndex.ts
new file mode 100644
index 00000000000..d8bdf020f3a
--- /dev/null
+++ b/packages/ui/src/lib/utils/getExplicitTabIndex.ts
@@ -0,0 +1,12 @@
+/**
+ * Explicit tabIndex for keyboard focus (Safari skips buttons otherwise).
+ * - Explicit `tabIndex` prop takes precedence
+ * - If disabled, default to -1
+ * - Otherwise, default to 0
+ */
+export function getExplicitTabIndex(
+ tabIndex: number | undefined,
+ disabled?: boolean | null
+): number {
+ return tabIndex !== undefined ? tabIndex : disabled ? -1 : 0
+}
diff --git a/packages/ui/src/lib/utils/index.ts b/packages/ui/src/lib/utils/index.ts
index b69b50d5098..3c5883a38cb 100644
--- a/packages/ui/src/lib/utils/index.ts
+++ b/packages/ui/src/lib/utils/index.ts
@@ -2,3 +2,4 @@ export * from './cn'
export * from './mergeDeep'
export * from './randomIdGenerator'
export * from './clipboard'
+export * from './getExplicitTabIndex'