@ultraviolet/form 3.8.2 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,7 @@ export declare const CheckboxGroupField: {
17
17
  required?: boolean;
18
18
  'data-testid'?: string;
19
19
  tooltip?: string;
20
- } & Pick<import("react").InputHTMLAttributes<HTMLInputElement>, "value" | "onChange" | "onBlur" | "name" | "onFocus" | "autoFocus" | "id" | "tabIndex"> & (({
20
+ } & (Pick<import("react").InputHTMLAttributes<HTMLInputElement>, "value" | "onChange" | "onBlur" | "name" | "onFocus" | "autoFocus" | "id" | "tabIndex"> & (({
21
21
  "aria-label"?: undefined;
22
22
  } & {
23
23
  children: import("react").ReactNode;
@@ -25,7 +25,7 @@ export declare const CheckboxGroupField: {
25
25
  children?: undefined;
26
26
  } & {
27
27
  'aria-label': string;
28
- }))) & import("react").RefAttributes<HTMLInputElement>, "onChange" | "checked"> & {
28
+ })))) & import("react").RefAttributes<HTMLInputElement>, "onChange" | "checked"> & {
29
29
  value: string;
30
30
  }) => import("@emotion/react/jsx-runtime").JSX.Element;
31
31
  };
@@ -22,6 +22,7 @@ const TextAreaField = ({
22
22
  name,
23
23
  onFocus,
24
24
  onBlur,
25
+ onKeyDown,
25
26
  placeholder,
26
27
  readOnly,
27
28
  required,
@@ -29,6 +30,7 @@ const TextAreaField = ({
29
30
  success,
30
31
  tooltip,
31
32
  regex: regexes,
33
+ submitOnEnter,
32
34
  validate
33
35
  }) => {
34
36
  const {
@@ -54,6 +56,24 @@ const TextAreaField = ({
54
56
  maxLength
55
57
  }
56
58
  });
59
+ const onKeyDownHandler = (event) => {
60
+ if (submitOnEnter && event.key === "Enter" && !event.shiftKey) {
61
+ event.preventDefault();
62
+ event.stopPropagation();
63
+ const {
64
+ form
65
+ } = event.currentTarget;
66
+ if (form) {
67
+ const submitEvent = new Event("submit", {
68
+ bubbles: true,
69
+ cancelable: true
70
+ });
71
+ form.dispatchEvent(submitEvent);
72
+ }
73
+ } else {
74
+ onKeyDown?.(event);
75
+ }
76
+ };
57
77
  return /* @__PURE__ */ jsxRuntime.jsx(ui.TextArea, { autoFocus, className, clearable, "data-testid": dataTestId, disabled, error: getError({
58
78
  regex: regexes,
59
79
  minLength,
@@ -66,8 +86,6 @@ const TextAreaField = ({
66
86
  }, onChange: (event) => {
67
87
  field.onChange(event);
68
88
  onChange?.(event);
69
- }, onFocus: (event) => {
70
- onFocus?.(event);
71
- }, placeholder, readOnly, required, rows, success, tabIndex, tooltip, value: field.value });
89
+ }, onFocus, onKeyDown: onKeyDownHandler, placeholder, readOnly, required, rows, success, tabIndex, tooltip, value: field.value });
72
90
  };
73
91
  exports.TextAreaField = TextAreaField;
@@ -4,8 +4,9 @@ import type { FieldPath, FieldValues } from 'react-hook-form';
4
4
  import type { BaseFieldProps } from '../../types';
5
5
  export type TextAreaFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof TextArea>, 'value' | 'error' | 'name' | 'onChange'> & {
6
6
  regex?: (RegExp | RegExp[])[];
7
+ submitOnEnter?: boolean;
7
8
  };
8
9
  /**
9
10
  * This component offers a form field based on Ultraviolet UI TextArea component
10
11
  */
11
- export declare const TextAreaField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ autoFocus, clearable, className, tabIndex, control, "data-testid": dataTestId, disabled, helper, label, labelDescription, onChange, minLength, maxLength, name, onFocus, onBlur, placeholder, readOnly, required, rows, success, tooltip, regex: regexes, validate, }: TextAreaFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
12
+ export declare const TextAreaField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ autoFocus, clearable, className, tabIndex, control, "data-testid": dataTestId, disabled, helper, label, labelDescription, onChange, minLength, maxLength, name, onFocus, onBlur, onKeyDown, placeholder, readOnly, required, rows, success, tooltip, regex: regexes, submitOnEnter, validate, }: TextAreaFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
@@ -20,6 +20,7 @@ const TextAreaField = ({
20
20
  name,
21
21
  onFocus,
22
22
  onBlur,
23
+ onKeyDown,
23
24
  placeholder,
24
25
  readOnly,
25
26
  required,
@@ -27,6 +28,7 @@ const TextAreaField = ({
27
28
  success,
28
29
  tooltip,
29
30
  regex: regexes,
31
+ submitOnEnter,
30
32
  validate
31
33
  }) => {
32
34
  const {
@@ -52,6 +54,24 @@ const TextAreaField = ({
52
54
  maxLength
53
55
  }
54
56
  });
57
+ const onKeyDownHandler = (event) => {
58
+ if (submitOnEnter && event.key === "Enter" && !event.shiftKey) {
59
+ event.preventDefault();
60
+ event.stopPropagation();
61
+ const {
62
+ form
63
+ } = event.currentTarget;
64
+ if (form) {
65
+ const submitEvent = new Event("submit", {
66
+ bubbles: true,
67
+ cancelable: true
68
+ });
69
+ form.dispatchEvent(submitEvent);
70
+ }
71
+ } else {
72
+ onKeyDown?.(event);
73
+ }
74
+ };
55
75
  return /* @__PURE__ */ jsx(TextArea, { autoFocus, className, clearable, "data-testid": dataTestId, disabled, error: getError({
56
76
  regex: regexes,
57
77
  minLength,
@@ -64,9 +84,7 @@ const TextAreaField = ({
64
84
  }, onChange: (event) => {
65
85
  field.onChange(event);
66
86
  onChange?.(event);
67
- }, onFocus: (event) => {
68
- onFocus?.(event);
69
- }, placeholder, readOnly, required, rows, success, tabIndex, tooltip, value: field.value });
87
+ }, onFocus, onKeyDown: onKeyDownHandler, placeholder, readOnly, required, rows, success, tabIndex, tooltip, value: field.value });
70
88
  };
71
89
  export {
72
90
  TextAreaField
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultraviolet/form",
3
- "version": "3.8.2",
3
+ "version": "3.9.0",
4
4
  "description": "Ultraviolet Form",
5
5
  "homepage": "https://github.com/scaleway/ultraviolet#readme",
6
6
  "repository": {
@@ -61,7 +61,7 @@
61
61
  "@emotion/react": "11.13.3",
62
62
  "@emotion/styled": "11.13.0",
63
63
  "@types/final-form-focus": "1.1.7",
64
- "@types/react": "18.3.5",
64
+ "@types/react": "18.3.9",
65
65
  "@types/react-dom": "18.3.0",
66
66
  "react": "18.3.1",
67
67
  "react-dom": "18.3.1",
@@ -70,9 +70,9 @@
70
70
  "dependencies": {
71
71
  "@babel/runtime": "7.25.6",
72
72
  "react-hook-form": "7.53.0",
73
- "react-select": "5.8.0",
74
- "@ultraviolet/themes": "1.14.0",
75
- "@ultraviolet/ui": "1.70.1"
73
+ "react-select": "5.8.1",
74
+ "@ultraviolet/themes": "1.14.1",
75
+ "@ultraviolet/ui": "1.71.0"
76
76
  },
77
77
  "scripts": {
78
78
  "build:profile": "npx vite-bundle-visualizer -c vite.config.ts",