@pathscale/ui 0.0.83 → 0.0.84

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.
@@ -2,7 +2,10 @@ import { type JSX, type ParentComponent } from "solid-js";
2
2
  import { IComponentBaseProps } from "../types";
3
3
  import ValidatedForm, { useFormValidation } from "./ValidatedForm";
4
4
  export { type ValidatedFormProps } from "./ValidatedForm";
5
- export type FormProps = Omit<JSX.HTMLAttributes<HTMLFormElement>, "ref"> & IComponentBaseProps;
5
+ export type FormProps = Omit<JSX.HTMLAttributes<HTMLFormElement>, "ref"> & IComponentBaseProps & {
6
+ autoFocus?: boolean;
7
+ cycleOnEnter?: boolean;
8
+ };
6
9
  export { useFormValidation };
7
10
  declare const _default: ParentComponent<FormProps> & {
8
11
  Label: ParentComponent<import("./Label").LabelProps>;
package/dist/index.js CHANGED
@@ -7440,16 +7440,61 @@ function ValidatedForm(props) {
7440
7440
  const form_ValidatedForm = ValidatedForm;
7441
7441
  var Form_tmpl$ = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.template)("<form role=form>");
7442
7442
  const Form = (props)=>{
7443
- const [local, others] = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.splitProps)(props, [
7443
+ const merged = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.mergeProps)({
7444
+ autoFocus: true,
7445
+ cycleOnEnter: true
7446
+ }, props);
7447
+ const [local, others] = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.splitProps)(merged, [
7444
7448
  "children",
7445
7449
  "dataTheme",
7446
7450
  "class",
7447
- "className"
7451
+ "className",
7452
+ "autoFocus",
7453
+ "cycleOnEnter"
7448
7454
  ]);
7449
7455
  const resolvedChildren = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.children)(()=>local.children);
7450
7456
  const classes = ()=>twMerge("form-control", local.class, local.className);
7457
+ let formRef;
7458
+ const getFocusableElements = ()=>{
7459
+ if (!formRef) return [];
7460
+ return Array.from(formRef.querySelectorAll('input:not([disabled]):not([type="hidden"]), textarea:not([disabled]), select:not([disabled])'));
7461
+ };
7462
+ const handleKeyDown = (e)=>{
7463
+ if (!local.cycleOnEnter || "Enter" !== e.key) return;
7464
+ const focusableElements = getFocusableElements();
7465
+ const activeElement = document.activeElement;
7466
+ if (!formRef?.contains(activeElement)) return;
7467
+ const currentIndex = focusableElements.indexOf(activeElement);
7468
+ if (-1 === currentIndex) return;
7469
+ e.preventDefault();
7470
+ if (currentIndex === focusableElements.length - 1) formRef?.dispatchEvent(new Event("submit", {
7471
+ bubbles: true,
7472
+ cancelable: true
7473
+ }));
7474
+ else {
7475
+ const nextElement = focusableElements[currentIndex + 1];
7476
+ nextElement?.focus();
7477
+ }
7478
+ };
7479
+ (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.onMount)(()=>{
7480
+ if (local.autoFocus && formRef) {
7481
+ const focusableElements = getFocusableElements();
7482
+ if (focusableElements.length > 0) {
7483
+ const firstElement = focusableElements[0];
7484
+ firstElement.focus();
7485
+ }
7486
+ }
7487
+ if (local.cycleOnEnter && formRef) {
7488
+ formRef.addEventListener("keydown", handleKeyDown);
7489
+ (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.onCleanup)(()=>{
7490
+ formRef?.removeEventListener("keydown", handleKeyDown);
7491
+ });
7492
+ }
7493
+ });
7451
7494
  return (()=>{
7452
7495
  var _el$ = Form_tmpl$();
7496
+ var _ref$ = formRef;
7497
+ "function" == typeof _ref$ ? (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.use)(_ref$, _el$) : formRef = _el$;
7453
7498
  (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.spread)(_el$, (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.mergeProps)(others, {
7454
7499
  get ["data-theme"] () {
7455
7500
  return local.dataTheme;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pathscale/ui",
3
- "version": "0.0.83",
3
+ "version": "0.0.84",
4
4
  "author": "pathscale",
5
5
  "repository": {
6
6
  "type": "git",