Files
supabase/apps/studio/components/interfaces/Database/Functions/CreateFunction/FunctionEditor.tsx
T
Gildas Garcia 3669fef749 Fix tooltip a11y comment (#50640)
## Problem

The tooltip comment we have about removing the `aria-describedby`
attribute to avoid screen readers reading the same text twice is wrong.

## Solution

Make it clear why we do that so that future devs don't remove it.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Accessibility**
* Clarified accessibility guidance for tooltips and screen-reader labels
across code blocks, database controls, function editors, hooks, and
table actions.
* **Documentation**
* Updated internal comments to more clearly explain why duplicate
tooltip text is avoided for screen readers.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-21 15:28:33 +02:00

60 lines
1.8 KiB
TypeScript

import { Maximize2, Minimize2 } from 'lucide-react'
import { Button, cn, FormControl, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
import { CodeEditor } from '@/components/ui/CodeEditor/CodeEditor'
export const FunctionEditor = ({
field,
language,
focused,
setFocused,
}: {
field: any
language: string
focused: boolean
setFocused: (b: boolean) => void
}) => {
return (
<div className={cn('rounded-md relative group grow')}>
<FormControl>
{language !== undefined && (
<CodeEditor
id="database-functions-editor"
language="pgsql"
placeholder={language === 'plpgsql' ? `BEGIN\n\nEND;` : undefined}
value={field.value}
onInputChange={field.onChange}
/>
)}
</FormControl>
<div
className={cn(
'absolute top-0 right-2 bg-surface-300 border border-strong rounded-sm h-[28px]',
'opacity-0 group-hover:opacity-100 group-hover:top-2 transition-all'
)}
>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="text"
size="tiny"
className={cn(
'px-1.5 text-foreground-lighter hover:text-foreground',
'transition z-50'
)}
onClick={() => setFocused(!focused)}
icon={focused ? <Minimize2 /> : <Maximize2 />}
aria-label={focused ? 'Minimize editor' : 'Maximize editor'}
// Tooltip repeats the label; screen readers would read it twice
aria-describedby={undefined}
/>
</TooltipTrigger>
<TooltipContent side="bottom">
{focused ? 'Minimize editor' : 'Maximize editor'}
</TooltipContent>
</Tooltip>
</div>
</div>
)
}