Skip to content

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

feat(studio): focus column name input after adding a column (#49183)

Danny Whitecb8a60960772
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx
index c0c8d8687b4..cba1129e2ad 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx
@@ -59,6 +59,7 @@ interface ColumnProps {
isNewRecord: boolean
hasForeignKeys: boolean
hasImportContent: boolean
+ shouldAutoFocusName?: boolean
onUpdateColumn: (changes: Partial<ColumnField>) => void
onRemoveColumn: () => void
onEditForeignKey: (relation?: ForeignKey) => void
@@ -71,6 +72,7 @@ export const Column = ({
isNewRecord = false,
hasForeignKeys = false,
hasImportContent = false,
+ shouldAutoFocusName = false,
onUpdateColumn,
onRemoveColumn,
onEditForeignKey,
@@ -137,6 +139,7 @@ export const Column = ({
<div className="flex w-[95%] items-center justify-between">
<div className="h-4 w-px bg-border" />
<Input
+ autoFocus={shouldAutoFocusName}
aria-label="Column name"
size="small"
value={column.name}
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsx
index 737e78921f3..0354611ea99 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsx
@@ -69,6 +69,7 @@ export const ColumnManagement = ({
const [open, setOpen] = useState(false)
const [selectedColumn, setSelectedColumn] = useState<ColumnField>()
const [selectedFk, setSelectedFk] = useState<ForeignKey>()
+ const [columnIdToFocus, setColumnIdToFocus] = useState<string | null>(null)
const hasImportContent = !isEmpty(importContent)
const [primaryKeyColumns, otherColumns] = partition(
@@ -109,6 +110,7 @@ export const ColumnManagement = ({
const onAddColumn = () => {
const defaultColumn = generateColumnField()
const updatedColumns = columns.concat(defaultColumn)
+ setColumnIdToFocus(defaultColumn.id)
onColumnsUpdated(updatedColumns)
}
@@ -285,6 +287,7 @@ export const ColumnManagement = ({
hasForeignKeys={checkIfHaveForeignKeys(column)}
isNewRecord={isNewRecord}
hasImportContent={hasImportContent}
+ shouldAutoFocusName={column.id === columnIdToFocus}
onUpdateColumn={(changes) => onUpdateColumn(column, changes)}
onRemoveColumn={() => onRemoveColumn(column)}
onEditForeignKey={(fk) => {
@@ -316,6 +319,7 @@ export const ColumnManagement = ({
isNewRecord={isNewRecord}
hasForeignKeys={checkIfHaveForeignKeys(column)}
hasImportContent={hasImportContent}
+ shouldAutoFocusName={column.id === columnIdToFocus}
onUpdateColumn={(changes) => onUpdateColumn(column, changes)}
onRemoveColumn={() => onRemoveColumn(column)}
onEditForeignKey={(fk) => {