Skip to content

Commit

Permalink
feat: prevent enter
Browse files Browse the repository at this point in the history
  • Loading branch information
GalvinGao committed Oct 12, 2023
1 parent 43207d1 commit 0060374
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/components/rjsf/themes/BaseInputTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ export default function BaseInputTemplate<
onBlur={_onBlur}
onFocus={_onFocus}
onWheel={e => {
e.preventDefault()
const target = e.target as HTMLElement
// Prevent the input value change
target.blur()

// Prevent the page/container scrolling
e.stopPropagation()
}}
InputProps={{
startAdornment: (
Expand Down
16 changes: 15 additions & 1 deletion src/pages/research/ResearchDetailPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Card, CardContent, CircularProgress, Toolbar } from "@mui/material"
import RJSFForm, { IChangeEvent } from "@rjsf/core"
import { FC, useRef } from "react"
import { FC, useEffect, useRef } from "react"
import { toast } from "react-hot-toast"
import { graphql, useLazyLoadQuery, useMutation } from "react-relay"
import { useParams } from "react-router-dom"
Expand All @@ -23,6 +23,20 @@ export const ResearchDetailPage: FC = () => {
const { id } = useParams<{ id: string }>()
if (!id) throw new Error("id is required")

useEffect(() => {
const el = formRef.current?.formElement?.current as HTMLDivElement
const handler = (e: KeyboardEvent) => {
if (e.key === "Enter") {
e.preventDefault()
}
}

el.addEventListener("keydown", handler, { passive: false, capture: true })
return () => {
el.removeEventListener("keydown", handler)
}
}, [formRef.current?.formElement])

const data = useLazyLoadQuery<ResearchDetailPageQuery>(
graphql`
query ResearchDetailPageQuery($id: ID!) {
Expand Down

0 comments on commit 0060374

Please sign in to comment.