make inputs work with Enter

This commit is contained in:
andrzej 2024-07-02 23:01:26 +02:00
parent 83efc850d3
commit edfee2c35d
6 changed files with 14 additions and 14 deletions

Binary file not shown.

View File

@ -4,12 +4,10 @@ import { StoryWithGenres } from "./page"
import { ArrowUpDown } from "lucide-react" import { ArrowUpDown } from "lucide-react"
import { Button } from "@/components/ui/button" import { Button } from "@/components/ui/button"
import GenreBadges from "app/ui/genreBadges" import GenreBadges from "app/ui/genreBadges"
import { actions } from "app/ui/tables/actions"
import { TextInputCell } from "app/ui/tables/inputs/textInput"
import { selectCol } from "app/ui/tables/selectColumn" import { selectCol } from "app/ui/tables/selectColumn"
import NumberInputCell from "app/ui/tables/inputs/numberInput" import NumberInputCell from "app/ui/tables/inputs/numberInput"
import { formSchema } from "app/ui/forms/story" import { formSchema } from "app/ui/forms/story"
import { TextInputCell } from "app/ui/tables/inputs/textInput"
const columnHelper = createColumnHelper<StoryWithGenres>() const columnHelper = createColumnHelper<StoryWithGenres>()
export const columns: ColumnDef<StoryWithGenres>[] = [ export const columns: ColumnDef<StoryWithGenres>[] = [

View File

@ -959,6 +959,14 @@ body {
width: 100vw; width: 100vw;
} }
.w-8 {
width: 2rem;
}
.w-16 {
width: 4rem;
}
.min-w-\[8rem\] { .min-w-\[8rem\] {
min-width: 8rem; min-width: 8rem;
} }

View File

@ -3,7 +3,6 @@
import { z } from "zod" import { z } from "zod"
import { zodResolver } from "@hookform/resolvers/zod" import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form" import { useForm } from "react-hook-form"
import { Button } from "@/components/ui/button"
import { import {
Form, Form,
FormControl, FormControl,
@ -16,12 +15,6 @@ import {
import { Input } from "@/components/ui/input" import { Input } from "@/components/ui/input"
import { toast } from "@/components/ui/use-toast" import { toast } from "@/components/ui/use-toast"
import {
Popover,
PopoverContent,
} from "@/components/ui/popover"
import GenresTrigger from "./genresTrigger"
import GenreCheckbox from "./genreCheckbox"
import { randomPublicationTitle } from "app/lib/shortStoryTitleGenerator" import { randomPublicationTitle } from "app/lib/shortStoryTitleGenerator"
import { ComponentProps } from "react" import { ComponentProps } from "react"
import { Genre } from "@prisma/client" import { Genre } from "@prisma/client"

View File

@ -64,7 +64,7 @@ export default function NumberInputCell(props: CellContext<any, any>) {
className="w-full h-fit flex items-center justify-center" className="w-full h-fit flex items-center justify-center"
tabIndex={0} tabIndex={0}
onKeyDown={e => { onKeyDown={e => {
if (e.code === "Space" && !isActive) { if (e.code === "Enter" && !isActive) {
e.preventDefault() e.preventDefault()
setIsActive(true) setIsActive(true)
} }
@ -84,6 +84,7 @@ export default function NumberInputCell(props: CellContext<any, any>) {
<FormControl <FormControl
> >
<Input <Input
className="w-24"
type="number" type="number"
autoFocus={true} autoFocus={true}
step={props.column.columnDef.meta?.step} step={props.column.columnDef.meta?.step}

View File

@ -26,7 +26,7 @@ export function TextInputCell(props: CellContext<any, any>) {
}, },
}) })
function onSubmit(value: z.infer<typeof formSchema>) { async function onSubmit(value: z.infer<typeof formSchema>) {
toast({ toast({
title: "You submitted the following values:", title: "You submitted the following values:",
description: ( description: (
@ -35,7 +35,7 @@ export function TextInputCell(props: CellContext<any, any>) {
</pre> </pre>
), ),
}) })
updateField({ const res = await updateField({
id, id,
table, table,
string: value[column], string: value[column],
@ -62,7 +62,7 @@ export function TextInputCell(props: CellContext<any, any>) {
className="w-full h-fit flex items-center justify-center" className="w-full h-fit flex items-center justify-center"
tabIndex={0} tabIndex={0}
onKeyDown={e => { onKeyDown={e => {
if (e.code === "Space" && !isActive) { if (e.code === "Enter" && !isActive) {
e.preventDefault() e.preventDefault()
setIsActive(true) setIsActive(true)
} }