Skip to content

Commit

Permalink
Focus the added field
Browse files Browse the repository at this point in the history
  • Loading branch information
insmac committed Oct 16, 2023
1 parent 9679d81 commit 8a9d6fb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
30 changes: 17 additions & 13 deletions packages/web-console/src/components/TableSchemaDialog/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ export const Actions = ({
action,
ctaText,
lastFocusedIndex,
onAdded,
}: {
action: Action
ctaText: string
lastFocusedIndex?: number
onAdded: (index: number) => void
}) => {
const newEntry = {
name: "",
Expand Down Expand Up @@ -63,17 +65,19 @@ export const Actions = ({
<PopperHover
trigger={
<Button
disabled={watchSchemaColumns.length === 0}
disabled={
watchSchemaColumns.length === 0 || lastFocusedIndex === undefined
}
skin="secondary"
type="button"
onClick={() =>
insert(
onClick={() => {
const index =
lastFocusedIndex !== undefined
? lastFocusedIndex
: watchSchemaColumns.length,
newEntry,
)
}
: watchSchemaColumns.length
insert(index, newEntry)
onAdded(index)
}}
>
<InsertRowTop size="20px" />
</Button>
Expand All @@ -92,14 +96,14 @@ export const Actions = ({
<Button
skin="secondary"
type="button"
onClick={() =>
insert(
onClick={() => {
const index =
lastFocusedIndex !== undefined
? lastFocusedIndex + 1
: watchSchemaColumns.length,
newEntry,
)
}
: watchSchemaColumns.length
insert(index, newEntry)
onAdded(index)
}}
>
<InsertRowBottom size="20px" />
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const Column = ({
onSetTimestamp,
onFocus,
timestamp,
lastFocusedIndex,
}: {
action: Action
disabled: boolean
Expand All @@ -70,6 +71,7 @@ export const Column = ({
onSetTimestamp: (name: string) => void
onFocus: (index: number) => void
timestamp: string
lastFocusedIndex?: number
}) => {
const [name, setName] = useState(column.name)

Expand Down Expand Up @@ -99,6 +101,7 @@ export const Column = ({
name={`schemaColumns.${index}.name`}
autoComplete="off"
required
{...(lastFocusedIndex === index && { autoFocus: true })}
/>
</Form.Item>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ export const Columns = ({
action,
isEditLocked,
onColumnFocus,
lastFocusedIndex,
}: {
action: Action
isEditLocked: boolean
onColumnFocus: (index: number) => void
lastFocusedIndex?: number
}) => {
const { formState, getValues, setValue, watch } = useFormContext()

Expand All @@ -60,6 +62,7 @@ export const Columns = ({
column={column}
disabled={isEditLocked}
index={index}
lastFocusedIndex={lastFocusedIndex}
onFocus={onColumnFocus}
onSetTimestamp={(name) => {
setValue("timestamp", watchTimestamp === name ? "" : name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export const Dialog = ({
ctaText={ctaText}
action={action}
lastFocusedIndex={lastFocusedIndex}
onAdded={setLastFocusedIndex}
/>
}
/>
Expand Down Expand Up @@ -326,6 +327,7 @@ export const Dialog = ({
action={action}
isEditLocked={isEditLocked}
onColumnFocus={setLastFocusedIndex}
lastFocusedIndex={lastFocusedIndex}
/>
</Inputs>
</Items>
Expand Down

0 comments on commit 8a9d6fb

Please sign in to comment.