@react-fabric/form 1.0.0-beta.15 → 1.0.0-beta.18

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.
@@ -138,7 +138,7 @@ var ArrayInput = function ArrayInput(_ref) {
138
138
  children: [typeof children === "function" ? children({
139
139
  index: index,
140
140
  name: "".concat(name, ".").concat(index)
141
- }) : react.Children.map(children, function (child) {
141
+ }) : utilities$1.cloneChildren(children, function (child) {
142
142
  return /*#__PURE__*/react.cloneElement(child, Object.assign({
143
143
  disabled: disabled,
144
144
  readOnly: readOnly,
@@ -2,6 +2,7 @@
2
2
 
3
3
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
4
  var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
5
+ var utilities = require('@react-fabric/utilities');
5
6
  var classNames = require('classnames');
6
7
  var react = require('react');
7
8
  var Field_module = require('../internal/Field.module.css');
@@ -20,8 +21,8 @@ var Field = function Field(_ref) {
20
21
  return /*#__PURE__*/jsxRuntime.jsx(FieldWrapper.FieldWrapper, _objectSpread(_objectSpread({}, rest), {}, {
21
22
  children: /*#__PURE__*/jsxRuntime.jsx("div", {
22
23
  className: classNames(Field_module.fieldGroup, !plain && !noOutline && "outline", !plain && "bg-base", "flex-1 rounded", !vertical && "flex flex-nowrap"),
23
- children: react.Children.map(children, function (child) {
24
- return child && /*#__PURE__*/react.cloneElement(child, {
24
+ children: utilities.cloneChildren(children, function (child) {
25
+ return /*#__PURE__*/react.cloneElement(child, {
25
26
  "data-inner": true
26
27
  });
27
28
  })
@@ -2,6 +2,7 @@
2
2
 
3
3
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
4
  var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
5
+ var utilities = require('@react-fabric/utilities');
5
6
  var react = require('react');
6
7
  var FieldWrapper = require('../internal/FieldWrapper.js');
7
8
  var jsxRuntime = require('react/jsx-runtime');
@@ -19,7 +20,7 @@ var RadioGroup = function RadioGroup(_ref) {
19
20
  return /*#__PURE__*/jsxRuntime.jsx(FieldWrapper.FieldWrapper, _objectSpread(_objectSpread({}, rest), {}, {
20
21
  children: /*#__PURE__*/jsxRuntime.jsx("div", {
21
22
  className: className,
22
- children: react.Children.map(children, function (child) {
23
+ children: utilities.cloneChildren(children, function (child) {
23
24
  return /*#__PURE__*/react.cloneElement(child, {
24
25
  name: name,
25
26
  onChange: onChange,
@@ -13,26 +13,27 @@ var Options = require('./Options.js');
13
13
  var useSelect = require('./useSelect.js');
14
14
  var jsxRuntime = require('react/jsx-runtime');
15
15
 
16
- var _excluded = ["ref", "name", "value", "readOnly", "disabled", "required", "placeholder", "autoFocus", "options", "height", "groupProperty", "labelProperty", "valueProperty", "multiple", "allowCreate", "createOption", "matcher", "renderer", "onQuery", "onChange", "onSelect", "onEnterPressed", "invalid", "error", "allowClear", "decorateStart", "decorateEnd", "data-inner", "data-hide-selected"];
16
+ var _excluded = ["ref", "name", "value", "readOnly", "disabled", "required", "placeholder", "autoFocus", "options", "height", "groupProperty", "labelProperty", "valueProperty", "multiple", "allowCreate", "searchable", "createOption", "matcher", "renderer", "onQuery", "onChange", "onSelect", "onEnterPressed", "invalid", "error", "allowClear", "decorateStart", "decorateEnd", "data-inner", "data-hide-selected"];
17
17
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
18
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
19
  var List = function List(_ref) {
20
20
  var _state$query;
21
- _ref.ref;
22
- var name = _ref.name,
21
+ var ref = _ref.ref,
22
+ name = _ref.name,
23
23
  value = _ref.value,
24
24
  readOnly = _ref.readOnly,
25
25
  disabled = _ref.disabled,
26
26
  required = _ref.required,
27
- placeholder = _ref.placeholder;
28
- _ref.autoFocus;
29
- var options = _ref.options,
27
+ placeholder = _ref.placeholder,
28
+ autoFocus = _ref.autoFocus,
29
+ options = _ref.options,
30
30
  height = _ref.height,
31
31
  groupProperty = _ref.groupProperty,
32
32
  labelProperty = _ref.labelProperty,
33
33
  valueProperty = _ref.valueProperty,
34
34
  multiple = _ref.multiple,
35
35
  allowCreate = _ref.allowCreate,
36
+ searchable = _ref.searchable,
36
37
  createOption = _ref.createOption,
37
38
  matcher = _ref.matcher,
38
39
  renderer = _ref.renderer,
@@ -138,9 +139,10 @@ var List = function List(_ref) {
138
139
  }
139
140
  } else if (evt.key === "Backspace") {
140
141
  !state.query && handleRemove();
141
- } else if (["ArrowUp", "ArrowDown"].includes(evt.key)) {
142
- if (state.activeIndex === null) {
143
- setActiveIndex(state.selectedIndex);
142
+ } else if (!searchable || ["ArrowUp", "ArrowDown"].includes(evt.key)) {
143
+ if (["ArrowUp", "ArrowDown"].includes(evt.key) && state.activeIndex === null) {
144
+ var _state$selectedIndex;
145
+ setActiveIndex((_state$selectedIndex = state.selectedIndex) !== null && _state$selectedIndex !== void 0 ? _state$selectedIndex : 0);
144
146
  }
145
147
  setTimeout(function () {
146
148
  var _props$onKeyDown;
@@ -185,6 +187,14 @@ var List = function List(_ref) {
185
187
  });
186
188
  }
187
189
  }, [state.value, state.query, placeholder, renderer]);
190
+ react.useLayoutEffect(function () {
191
+ setTimeout(function () {
192
+ var _listRef$current$stat;
193
+ state.selectedIndex && ((_listRef$current$stat = listRef.current[state.selectedIndex]) === null || _listRef$current$stat === void 0 ? void 0 : _listRef$current$stat.scrollIntoView({
194
+ block: "center"
195
+ }));
196
+ }, 100);
197
+ }, [state.selectedIndex]);
188
198
  return /*#__PURE__*/jsxRuntime.jsxs(Wrapper, _objectSpread(_objectSpread({}, wrapperProps), {}, {
189
199
  children: [/*#__PURE__*/jsxRuntime.jsx(InputWrapper.InputWrapper, {
190
200
  showClear: !utilities.isEmpty(state.value),
@@ -197,23 +207,32 @@ var List = function List(_ref) {
197
207
  className: "z-1 rounded-b-none",
198
208
  "data-inner": true,
199
209
  wrapperRef: refs.setReference,
200
- children: /*#__PURE__*/jsxRuntime.jsxs("div", {
210
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread(_objectSpread({
211
+ role: "none",
201
212
  "data-select-display": "true",
202
- className: "group flex-1 py-1 px-2 truncate text-start flex gap-1 flex-wrap",
203
- children: [!hideSelected && displayValue, /*#__PURE__*/jsxRuntime.jsx("input", _objectSpread(_objectSpread({
213
+ className: classNames("group flex-1 py-1 px-2 truncate text-start flex gap-1 relative min-h-5 justify-start", multiple ? "flex-wrap" : "flex-nowrap overflow-hidden")
214
+ }, referenceProps), {}, {
215
+ onMouseUp: function onMouseUp(e) {
216
+ var _e$currentTarget$quer;
217
+ return (_e$currentTarget$quer = e.currentTarget.querySelector("input")) === null || _e$currentTarget$quer === void 0 ? void 0 : _e$currentTarget$quer.focus();
218
+ },
219
+ children: [!hideSelected && displayValue, /*#__PURE__*/jsxRuntime.jsx("input", {
220
+ readOnly: !searchable || readOnly,
204
221
  disabled: disabled,
205
222
  value: (_state$query = state.query) !== null && _state$query !== void 0 ? _state$query : "",
206
223
  "aria-invalid": invalid,
207
224
  "data-testid": name,
208
225
  name: name,
209
- className: classNames("appearance-none bg-transparent outline-none border-none ring-0 flex-1 min-w-24", disabled && "cursor-not-allowed pointer-events-none"),
210
- placeholder: utilities.isEmpty(state.value) ? placeholder : ""
211
- }, referenceProps), {}, {
226
+ size: 1,
227
+ ref: ref,
228
+ autoFocus: autoFocus,
229
+ className: classNames("appearance-none bg-transparent outline-none border-none ring-0 flex-1 min-w-24", disabled && "cursor-not-allowed pointer-events-none", multiple && "min-w-24"),
230
+ placeholder: utilities.isEmpty(state.value) ? placeholder : "",
212
231
  onChange: function onChange(evt) {
213
232
  return handleQuery(evt.target.value);
214
233
  }
215
- }))]
216
- })
234
+ })]
235
+ }))
217
236
  }), /*#__PURE__*/jsxRuntime.jsx(react$1.FloatingFocusManager, {
218
237
  context: context,
219
238
  initialFocus: -1,
@@ -227,11 +246,13 @@ var List = function List(_ref) {
227
246
  }, floatingProps), {}, {
228
247
  items: state.items,
229
248
  active: state.activeIndex,
249
+ valueProperty: valueProperty,
250
+ labelProperty: labelProperty,
230
251
  itemRef: setItemRef,
231
252
  itemProps: makeItemProps,
232
- children: function children(item) {
233
- var _ref4, _renderer3;
234
- return (_ref4 = (_renderer3 = renderer === null || renderer === void 0 ? void 0 : renderer(item)) !== null && _renderer3 !== void 0 ? _renderer3 : item[labelProperty]) !== null && _ref4 !== void 0 ? _ref4 : item;
253
+ children: function children(item, label) {
254
+ var _renderer3;
255
+ return (_renderer3 = renderer === null || renderer === void 0 ? void 0 : renderer(item)) !== null && _renderer3 !== void 0 ? _renderer3 : label;
235
256
  }
236
257
  }))
237
258
  })]
@@ -5,9 +5,9 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
5
5
  import { DndContext } from '@dnd-kit/core';
6
6
  import { SortableContext, useSortable } from '@dnd-kit/sortable';
7
7
  import { Icon, CoreIcons, Button, Tooltip } from '@react-fabric/core';
8
- import { isString } from '@react-fabric/utilities';
8
+ import { cloneChildren, isString } from '@react-fabric/utilities';
9
9
  import classNames from 'classnames';
10
- import { useMemo, useCallback, useImperativeHandle, Children, cloneElement } from 'react';
10
+ import { useMemo, useCallback, useImperativeHandle, cloneElement } from 'react';
11
11
  import { useFormContext, useFieldArray } from 'react-hook-form';
12
12
  import { useTranslation } from 'react-i18next';
13
13
  import { FieldWrapper } from '../internal/FieldWrapper.js';
@@ -138,7 +138,7 @@ var ArrayInput = function ArrayInput(_ref) {
138
138
  children: [typeof children === "function" ? children({
139
139
  index: index,
140
140
  name: "".concat(name, ".").concat(index)
141
- }) : Children.map(children, function (child) {
141
+ }) : cloneChildren(children, function (child) {
142
142
  return /*#__PURE__*/cloneElement(child, Object.assign({
143
143
  disabled: disabled,
144
144
  readOnly: readOnly,
@@ -2,8 +2,9 @@
2
2
 
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
+ import { cloneChildren } from '@react-fabric/utilities';
5
6
  import classNames from 'classnames';
6
- import { Children, cloneElement } from 'react';
7
+ import { cloneElement } from 'react';
7
8
  import classes from '../internal/Field.module.css';
8
9
  import { FieldWrapper } from '../internal/FieldWrapper.js';
9
10
  import { jsx } from 'react/jsx-runtime';
@@ -20,8 +21,8 @@ var Field = function Field(_ref) {
20
21
  return /*#__PURE__*/jsx(FieldWrapper, _objectSpread(_objectSpread({}, rest), {}, {
21
22
  children: /*#__PURE__*/jsx("div", {
22
23
  className: classNames(classes.fieldGroup, !plain && !noOutline && "outline", !plain && "bg-base", "flex-1 rounded", !vertical && "flex flex-nowrap"),
23
- children: Children.map(children, function (child) {
24
- return child && /*#__PURE__*/cloneElement(child, {
24
+ children: cloneChildren(children, function (child) {
25
+ return /*#__PURE__*/cloneElement(child, {
25
26
  "data-inner": true
26
27
  });
27
28
  })
@@ -2,7 +2,8 @@
2
2
 
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
- import { Children, cloneElement } from 'react';
5
+ import { cloneChildren } from '@react-fabric/utilities';
6
+ import { cloneElement } from 'react';
6
7
  import { FieldWrapper } from '../internal/FieldWrapper.js';
7
8
  import { jsx } from 'react/jsx-runtime';
8
9
 
@@ -19,7 +20,7 @@ var RadioGroup = function RadioGroup(_ref) {
19
20
  return /*#__PURE__*/jsx(FieldWrapper, _objectSpread(_objectSpread({}, rest), {}, {
20
21
  children: /*#__PURE__*/jsx("div", {
21
22
  className: className,
22
- children: Children.map(children, function (child) {
23
+ children: cloneChildren(children, function (child) {
23
24
  return /*#__PURE__*/cloneElement(child, {
24
25
  name: name,
25
26
  onChange: onChange,
@@ -6,33 +6,34 @@ import { useFloating, autoUpdate, useListNavigation, useTypeahead, useInteractio
6
6
  import { Chip } from '@react-fabric/core';
7
7
  import { isArray, isEmpty } from '@react-fabric/utilities';
8
8
  import classNames from 'classnames';
9
- import { useMemo, Fragment, useId, useCallback } from 'react';
9
+ import { useMemo, Fragment, useId, useCallback, useLayoutEffect } from 'react';
10
10
  import { FieldWrapper } from '../internal/FieldWrapper.js';
11
11
  import { InputWrapper } from '../internal/InputWrapper.js';
12
12
  import { Options } from './Options.js';
13
13
  import { useSelect } from './useSelect.js';
14
14
  import { jsx, jsxs } from 'react/jsx-runtime';
15
15
 
16
- var _excluded = ["ref", "name", "value", "readOnly", "disabled", "required", "placeholder", "autoFocus", "options", "height", "groupProperty", "labelProperty", "valueProperty", "multiple", "allowCreate", "createOption", "matcher", "renderer", "onQuery", "onChange", "onSelect", "onEnterPressed", "invalid", "error", "allowClear", "decorateStart", "decorateEnd", "data-inner", "data-hide-selected"];
16
+ var _excluded = ["ref", "name", "value", "readOnly", "disabled", "required", "placeholder", "autoFocus", "options", "height", "groupProperty", "labelProperty", "valueProperty", "multiple", "allowCreate", "searchable", "createOption", "matcher", "renderer", "onQuery", "onChange", "onSelect", "onEnterPressed", "invalid", "error", "allowClear", "decorateStart", "decorateEnd", "data-inner", "data-hide-selected"];
17
17
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
18
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
19
  var List = function List(_ref) {
20
20
  var _state$query;
21
- _ref.ref;
22
- var name = _ref.name,
21
+ var ref = _ref.ref,
22
+ name = _ref.name,
23
23
  value = _ref.value,
24
24
  readOnly = _ref.readOnly,
25
25
  disabled = _ref.disabled,
26
26
  required = _ref.required,
27
- placeholder = _ref.placeholder;
28
- _ref.autoFocus;
29
- var options = _ref.options,
27
+ placeholder = _ref.placeholder,
28
+ autoFocus = _ref.autoFocus,
29
+ options = _ref.options,
30
30
  height = _ref.height,
31
31
  groupProperty = _ref.groupProperty,
32
32
  labelProperty = _ref.labelProperty,
33
33
  valueProperty = _ref.valueProperty,
34
34
  multiple = _ref.multiple,
35
35
  allowCreate = _ref.allowCreate,
36
+ searchable = _ref.searchable,
36
37
  createOption = _ref.createOption,
37
38
  matcher = _ref.matcher,
38
39
  renderer = _ref.renderer,
@@ -138,9 +139,10 @@ var List = function List(_ref) {
138
139
  }
139
140
  } else if (evt.key === "Backspace") {
140
141
  !state.query && handleRemove();
141
- } else if (["ArrowUp", "ArrowDown"].includes(evt.key)) {
142
- if (state.activeIndex === null) {
143
- setActiveIndex(state.selectedIndex);
142
+ } else if (!searchable || ["ArrowUp", "ArrowDown"].includes(evt.key)) {
143
+ if (["ArrowUp", "ArrowDown"].includes(evt.key) && state.activeIndex === null) {
144
+ var _state$selectedIndex;
145
+ setActiveIndex((_state$selectedIndex = state.selectedIndex) !== null && _state$selectedIndex !== void 0 ? _state$selectedIndex : 0);
144
146
  }
145
147
  setTimeout(function () {
146
148
  var _props$onKeyDown;
@@ -185,6 +187,14 @@ var List = function List(_ref) {
185
187
  });
186
188
  }
187
189
  }, [state.value, state.query, placeholder, renderer]);
190
+ useLayoutEffect(function () {
191
+ setTimeout(function () {
192
+ var _listRef$current$stat;
193
+ state.selectedIndex && ((_listRef$current$stat = listRef.current[state.selectedIndex]) === null || _listRef$current$stat === void 0 ? void 0 : _listRef$current$stat.scrollIntoView({
194
+ block: "center"
195
+ }));
196
+ }, 100);
197
+ }, [state.selectedIndex]);
188
198
  return /*#__PURE__*/jsxs(Wrapper, _objectSpread(_objectSpread({}, wrapperProps), {}, {
189
199
  children: [/*#__PURE__*/jsx(InputWrapper, {
190
200
  showClear: !isEmpty(state.value),
@@ -197,23 +207,32 @@ var List = function List(_ref) {
197
207
  className: "z-1 rounded-b-none",
198
208
  "data-inner": true,
199
209
  wrapperRef: refs.setReference,
200
- children: /*#__PURE__*/jsxs("div", {
210
+ children: /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
211
+ role: "none",
201
212
  "data-select-display": "true",
202
- className: "group flex-1 py-1 px-2 truncate text-start flex gap-1 flex-wrap",
203
- children: [!hideSelected && displayValue, /*#__PURE__*/jsx("input", _objectSpread(_objectSpread({
213
+ className: classNames("group flex-1 py-1 px-2 truncate text-start flex gap-1 relative min-h-5 justify-start", multiple ? "flex-wrap" : "flex-nowrap overflow-hidden")
214
+ }, referenceProps), {}, {
215
+ onMouseUp: function onMouseUp(e) {
216
+ var _e$currentTarget$quer;
217
+ return (_e$currentTarget$quer = e.currentTarget.querySelector("input")) === null || _e$currentTarget$quer === void 0 ? void 0 : _e$currentTarget$quer.focus();
218
+ },
219
+ children: [!hideSelected && displayValue, /*#__PURE__*/jsx("input", {
220
+ readOnly: !searchable || readOnly,
204
221
  disabled: disabled,
205
222
  value: (_state$query = state.query) !== null && _state$query !== void 0 ? _state$query : "",
206
223
  "aria-invalid": invalid,
207
224
  "data-testid": name,
208
225
  name: name,
209
- className: classNames("appearance-none bg-transparent outline-none border-none ring-0 flex-1 min-w-24", disabled && "cursor-not-allowed pointer-events-none"),
210
- placeholder: isEmpty(state.value) ? placeholder : ""
211
- }, referenceProps), {}, {
226
+ size: 1,
227
+ ref: ref,
228
+ autoFocus: autoFocus,
229
+ className: classNames("appearance-none bg-transparent outline-none border-none ring-0 flex-1 min-w-24", disabled && "cursor-not-allowed pointer-events-none", multiple && "min-w-24"),
230
+ placeholder: isEmpty(state.value) ? placeholder : "",
212
231
  onChange: function onChange(evt) {
213
232
  return handleQuery(evt.target.value);
214
233
  }
215
- }))]
216
- })
234
+ })]
235
+ }))
217
236
  }), /*#__PURE__*/jsx(FloatingFocusManager, {
218
237
  context: context,
219
238
  initialFocus: -1,
@@ -227,11 +246,13 @@ var List = function List(_ref) {
227
246
  }, floatingProps), {}, {
228
247
  items: state.items,
229
248
  active: state.activeIndex,
249
+ valueProperty: valueProperty,
250
+ labelProperty: labelProperty,
230
251
  itemRef: setItemRef,
231
252
  itemProps: makeItemProps,
232
- children: function children(item) {
233
- var _ref4, _renderer3;
234
- return (_ref4 = (_renderer3 = renderer === null || renderer === void 0 ? void 0 : renderer(item)) !== null && _renderer3 !== void 0 ? _renderer3 : item[labelProperty]) !== null && _ref4 !== void 0 ? _ref4 : item;
253
+ children: function children(item, label) {
254
+ var _renderer3;
255
+ return (_renderer3 = renderer === null || renderer === void 0 ? void 0 : renderer(item)) !== null && _renderer3 !== void 0 ? _renderer3 : label;
235
256
  }
236
257
  }))
237
258
  })]
@@ -1,4 +1,4 @@
1
1
  import { type SelectProps } from "../types";
2
- export declare const List: <T extends unknown = string>({ ref, name, value, readOnly, disabled, required, placeholder, autoFocus, options, height, groupProperty, labelProperty, valueProperty, multiple, allowCreate, createOption, matcher, renderer, onQuery, onChange, onSelect, onEnterPressed, invalid, error, allowClear, decorateStart, decorateEnd, "data-inner": isInner, "data-hide-selected": hideSelected, ...rest }: SelectProps<T> & {
2
+ export declare const List: <T extends unknown = string>({ ref, name, value, readOnly, disabled, required, placeholder, autoFocus, options, height, groupProperty, labelProperty, valueProperty, multiple, allowCreate, searchable, createOption, matcher, renderer, onQuery, onChange, onSelect, onEnterPressed, invalid, error, allowClear, decorateStart, decorateEnd, "data-inner": isInner, "data-hide-selected": hideSelected, ...rest }: SelectProps<T> & {
3
3
  height?: string | number;
4
4
  }) => import("react/jsx-runtime").JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/form",
3
- "version": "1.0.0-beta.15",
3
+ "version": "1.0.0-beta.18",
4
4
  "description": "RUF: Form package",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -37,10 +37,10 @@
37
37
  "@dnd-kit/modifiers": "^7.0.0",
38
38
  "@dnd-kit/sortable": "^8.0.0",
39
39
  "@dnd-kit/utilities": "^3.2.2",
40
- "@floating-ui/react": "0.26.24",
40
+ "@floating-ui/react": "^0.26.24",
41
41
  "@hookform/resolvers": "^3.9.0",
42
- "@react-fabric/core": "^1.0.0-beta.15",
43
- "@react-fabric/utilities": "^1.0.0-beta.15",
42
+ "@react-fabric/core": "^1.0.0-beta.18",
43
+ "@react-fabric/utilities": "^1.0.0-beta.18",
44
44
  "classnames": "^2.5.1",
45
45
  "color": "^4.2.3",
46
46
  "react-color": "^2.19.3",
@@ -60,5 +60,5 @@
60
60
  "node": ">=18.12.0",
61
61
  "npm": ">=8.19.0"
62
62
  },
63
- "gitHead": "d6c7e122b74bf8b0511ef4fb8a99931458a37b3a"
63
+ "gitHead": "4795fee60aa3e7411934a688f7c53e42ca3297ed"
64
64
  }
@@ -24,10 +24,9 @@
24
24
  import { DndContext, type DragEndEvent } from "@dnd-kit/core";
25
25
  import { SortableContext, useSortable } from "@dnd-kit/sortable";
26
26
  import { Button, CoreIcons, Icon, Tooltip } from "@react-fabric/core";
27
- import { isString } from "@react-fabric/utilities";
27
+ import { cloneChildren, isString } from "@react-fabric/utilities";
28
28
  import classNames from "classnames";
29
29
  import {
30
- Children,
31
30
  cloneElement,
32
31
  useCallback,
33
32
  useImperativeHandle,
@@ -255,7 +254,7 @@ export const ArrayInput = ({
255
254
  index,
256
255
  name: `${name}.${index}`,
257
256
  })
258
- : Children.map(children, (child: AnyObject) =>
257
+ : cloneChildren(children, (child: AnyObject) =>
259
258
  cloneElement(
260
259
  child,
261
260
  Object.assign(
@@ -25,8 +25,9 @@ import {
25
25
  type ChildrenProp,
26
26
  type CssProp,
27
27
  } from "@react-fabric/core/dist/types/types";
28
+ import { cloneChildren } from "@react-fabric/utilities";
28
29
  import classNames from "classnames";
29
- import { Children, cloneElement } from "react";
30
+ import { cloneElement } from "react";
30
31
  import classes from "../internal/Field.module.css";
31
32
  import { FieldWrapper } from "../internal/FieldWrapper";
32
33
 
@@ -90,13 +91,10 @@ export const Field = ({
90
91
  !vertical && "flex flex-nowrap",
91
92
  )}
92
93
  >
93
- {Children.map(
94
- children,
95
- (child) =>
96
- child &&
97
- cloneElement(child as AnyObject, {
98
- "data-inner": true,
99
- }),
94
+ {cloneChildren(children, (child: AnyObject) =>
95
+ cloneElement(child, {
96
+ "data-inner": true,
97
+ }),
100
98
  )}
101
99
  </div>
102
100
  </FieldWrapper>
@@ -25,7 +25,8 @@ import {
25
25
  type ChildrenProp,
26
26
  type CssProp,
27
27
  } from "@react-fabric/core/dist/types/types";
28
- import { Children, cloneElement } from "react";
28
+ import { cloneChildren } from "@react-fabric/utilities";
29
+ import { cloneElement } from "react";
29
30
  import { FieldWrapper } from "../internal/FieldWrapper";
30
31
  import { type Radio } from "./Radio";
31
32
 
@@ -84,8 +85,8 @@ export const RadioGroup = ({
84
85
  return (
85
86
  <FieldWrapper {...rest}>
86
87
  <div className={className}>
87
- {Children.map(children, (child) =>
88
- cloneElement(child as AnyObject, {
88
+ {cloneChildren(children, (child: AnyObject) =>
89
+ cloneElement(child, {
89
90
  name,
90
91
  onChange,
91
92
  width: optionWidth,
@@ -32,7 +32,7 @@ import {
32
32
  import { Chip } from "@react-fabric/core";
33
33
  import { isArray, isEmpty } from "@react-fabric/utilities";
34
34
  import classNames from "classnames";
35
- import { Fragment, useCallback, useId, useMemo } from "react";
35
+ import { Fragment, useCallback, useId, useLayoutEffect, useMemo } from "react";
36
36
  import { FieldWrapper } from "../internal/FieldWrapper";
37
37
  import { InputWrapper } from "../internal/InputWrapper";
38
38
  import { type SelectProps } from "../types";
@@ -55,6 +55,7 @@ export const List = <T extends AnyObject = string>({
55
55
  valueProperty,
56
56
  multiple,
57
57
  allowCreate,
58
+ searchable,
58
59
  createOption,
59
60
  matcher,
60
61
  renderer,
@@ -166,9 +167,12 @@ export const List = <T extends AnyObject = string>({
166
167
  }
167
168
  } else if (evt.key === "Backspace") {
168
169
  !state.query && handleRemove();
169
- } else if (["ArrowUp", "ArrowDown"].includes(evt.key)) {
170
- if (state.activeIndex === null) {
171
- setActiveIndex(state.selectedIndex);
170
+ } else if (!searchable || ["ArrowUp", "ArrowDown"].includes(evt.key)) {
171
+ if (
172
+ ["ArrowUp", "ArrowDown"].includes(evt.key) &&
173
+ state.activeIndex === null
174
+ ) {
175
+ setActiveIndex(state.selectedIndex ?? 0);
172
176
  }
173
177
  setTimeout(() => {
174
178
  props.onKeyDown?.(evt);
@@ -225,6 +229,15 @@ export const List = <T extends AnyObject = string>({
225
229
  }
226
230
  }, [state.value, state.query, placeholder, renderer]);
227
231
 
232
+ useLayoutEffect(() => {
233
+ setTimeout(() => {
234
+ state.selectedIndex &&
235
+ listRef.current[state.selectedIndex]?.scrollIntoView({
236
+ block: "center",
237
+ });
238
+ }, 100);
239
+ }, [state.selectedIndex]);
240
+
228
241
  return (
229
242
  <Wrapper {...wrapperProps}>
230
243
  <InputWrapper
@@ -240,22 +253,34 @@ export const List = <T extends AnyObject = string>({
240
253
  wrapperRef={refs.setReference}
241
254
  >
242
255
  <div
256
+ role="none"
243
257
  data-select-display="true"
244
- className="group flex-1 py-1 px-2 truncate text-start flex gap-1 flex-wrap"
258
+ className={classNames(
259
+ "group flex-1 py-1 px-2 truncate text-start flex gap-1 relative min-h-5 justify-start",
260
+ multiple ? "flex-wrap" : "flex-nowrap overflow-hidden",
261
+ )}
262
+ {...referenceProps}
263
+ onMouseUp={(e) =>
264
+ e.currentTarget.querySelector<HTMLElement>("input")?.focus()
265
+ }
245
266
  >
246
267
  {!hideSelected && displayValue}
247
268
  <input
269
+ readOnly={!searchable || readOnly}
248
270
  disabled={disabled}
249
271
  value={state.query ?? ""}
250
272
  aria-invalid={invalid}
251
273
  data-testid={name}
252
274
  name={name}
275
+ size={1}
276
+ ref={ref}
277
+ autoFocus={autoFocus}
253
278
  className={classNames(
254
279
  "appearance-none bg-transparent outline-none border-none ring-0 flex-1 min-w-24",
255
280
  disabled && "cursor-not-allowed pointer-events-none",
281
+ multiple && "min-w-24",
256
282
  )}
257
283
  placeholder={isEmpty(state.value) ? placeholder : ""}
258
- {...referenceProps}
259
284
  onChange={(evt) => handleQuery(evt.target.value)}
260
285
  />
261
286
  </div>
@@ -277,10 +302,12 @@ export const List = <T extends AnyObject = string>({
277
302
  {...floatingProps}
278
303
  items={state.items}
279
304
  active={state.activeIndex}
305
+ valueProperty={valueProperty}
306
+ labelProperty={labelProperty}
280
307
  itemRef={setItemRef}
281
308
  itemProps={makeItemProps}
282
309
  >
283
- {(item) => renderer?.(item) ?? item[labelProperty] ?? item}
310
+ {(item, label) => renderer?.(item) ?? label}
284
311
  </Options>
285
312
  </FloatingFocusManager>
286
313
  </Wrapper>