All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.react-utils.useFieldSubmit.useFieldSubmit.js.map Maven / Gradle / Ivy

Go to download

A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.

There is a newer version: 4.12.3
Show newest version
{"version":3,"file":"useFieldSubmit.js","names":["useCallback","useEffect","useRef","useFieldSubmit","onSubmit","ref","keyDownHandler","event","key","shiftKey","stopPropagation","preventDefault","element","current","undefined","addEventListener","removeEventListener"],"sources":["../../../src/react-utils/useFieldSubmit/useFieldSubmit.js"],"sourcesContent":["import { useCallback, useEffect, useRef } from \"react\";\n\nconst useFieldSubmit = onSubmit => {\n  /** @type {{ current: HTMLInputElement & HTMLTextAreaElement }} */\n  // @ts-ignore\n  const ref = useRef(null);\n\n  const keyDownHandler = useCallback(event => {\n    if (event.key !== \"Enter\") return;\n\n    if (event.shiftKey) {\n      event.stopPropagation();\n    } else {\n      onSubmit();\n      event.preventDefault();\n    }\n  }, []);\n\n  useEffect(() => {\n    const element = ref.current;\n    if (!element) return undefined;\n\n    element.addEventListener(\"keydown\", keyDownHandler);\n\n    return () => element.removeEventListener(\"keydown\", keyDownHandler);\n  }, []);\n\n  return ref;\n};\n\nexport default useFieldSubmit;\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAEtD,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CAAGC,QAAQ,EAAI;EACjC;EACA;EACA,IAAMC,GAAG,GAAGH,MAAM,CAAC,IAAI,CAAC;EAExB,IAAMI,cAAc,GAAGN,WAAW,CAAC,UAAAO,KAAK,EAAI;IAC1C,IAAIA,KAAK,CAACC,GAAG,KAAK,OAAO,EAAE;IAE3B,IAAID,KAAK,CAACE,QAAQ,EAAE;MAClBF,KAAK,CAACG,eAAe,CAAC,CAAC;IACzB,CAAC,MAAM;MACLN,QAAQ,CAAC,CAAC;MACVG,KAAK,CAACI,cAAc,CAAC,CAAC;IACxB;EACF,CAAC,EAAE,EAAE,CAAC;EAENV,SAAS,CAAC,YAAM;IACd,IAAMW,OAAO,GAAGP,GAAG,CAACQ,OAAO;IAC3B,IAAI,CAACD,OAAO,EAAE,OAAOE,SAAS;IAE9BF,OAAO,CAACG,gBAAgB,CAAC,SAAS,EAAET,cAAc,CAAC;IAEnD,OAAO;MAAA,OAAMM,OAAO,CAACI,mBAAmB,CAAC,SAAS,EAAEV,cAAc,CAAC;IAAA;EACrE,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOD,GAAG;AACZ,CAAC;AAED,eAAeF,cAAc","ignoreList":[]}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy