@react-md/core 6.2.0 → 6.3.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.
Files changed (158) hide show
  1. package/dist/_base.scss +1 -0
  2. package/dist/datetime/NativeDateField.d.ts +24 -0
  3. package/dist/datetime/NativeDateField.js +63 -0
  4. package/dist/datetime/NativeDateField.js.map +1 -0
  5. package/dist/datetime/NativeTimeField.d.ts +26 -0
  6. package/dist/datetime/NativeTimeField.js +63 -0
  7. package/dist/datetime/NativeTimeField.js.map +1 -0
  8. package/dist/datetime/useDateField.d.ts +120 -0
  9. package/dist/datetime/useDateField.js +35 -0
  10. package/dist/datetime/useDateField.js.map +1 -0
  11. package/dist/datetime/useTimeField.d.ts +124 -0
  12. package/dist/datetime/useTimeField.js +65 -0
  13. package/dist/datetime/useTimeField.js.map +1 -0
  14. package/dist/datetime/utils.d.ts +34 -0
  15. package/dist/datetime/utils.js +27 -0
  16. package/dist/datetime/utils.js.map +1 -0
  17. package/dist/draggable/utils.d.ts +3 -6
  18. package/dist/draggable/utils.js.map +1 -1
  19. package/dist/expansion-panel/ExpansionList.js +1 -1
  20. package/dist/expansion-panel/ExpansionList.js.map +1 -1
  21. package/dist/expansion-panel/useExpansionList.d.ts +2 -7
  22. package/dist/expansion-panel/useExpansionList.js.map +1 -1
  23. package/dist/form/FormMessage.js +3 -1
  24. package/dist/form/FormMessage.js.map +1 -1
  25. package/dist/form/FormMessageContainer.d.ts +2 -1
  26. package/dist/form/FormMessageContainer.js +3 -2
  27. package/dist/form/FormMessageContainer.js.map +1 -1
  28. package/dist/form/FormMessageCounter.d.ts +3 -2
  29. package/dist/form/FormMessageCounter.js +5 -2
  30. package/dist/form/FormMessageCounter.js.map +1 -1
  31. package/dist/form/Listbox.d.ts +3 -10
  32. package/dist/form/Listbox.js +8 -27
  33. package/dist/form/Listbox.js.map +1 -1
  34. package/dist/form/ListboxProvider.d.ts +17 -0
  35. package/dist/form/ListboxProvider.js +33 -1
  36. package/dist/form/ListboxProvider.js.map +1 -1
  37. package/dist/form/NativeSelect.js +1 -0
  38. package/dist/form/NativeSelect.js.map +1 -1
  39. package/dist/form/TextArea.js +1 -0
  40. package/dist/form/TextArea.js.map +1 -1
  41. package/dist/form/TextField.js +1 -0
  42. package/dist/form/TextField.js.map +1 -1
  43. package/dist/form/_form-message.scss +13 -0
  44. package/dist/form/_select.scss +1 -1
  45. package/dist/form/_slider.scss +1 -1
  46. package/dist/form/_text-field.scss +12 -3
  47. package/dist/form/formMessageContainerStyles.d.ts +7 -0
  48. package/dist/form/formMessageContainerStyles.js +4 -2
  49. package/dist/form/formMessageContainerStyles.js.map +1 -1
  50. package/dist/form/sliderUtils.d.ts +3 -7
  51. package/dist/form/sliderUtils.js.map +1 -1
  52. package/dist/form/types.d.ts +13 -0
  53. package/dist/form/types.js.map +1 -1
  54. package/dist/form/useCombobox.d.ts +6 -2
  55. package/dist/form/useCombobox.js +8 -9
  56. package/dist/form/useCombobox.js.map +1 -1
  57. package/dist/form/useFormReset.d.ts +4 -1
  58. package/dist/form/useFormReset.js +9 -4
  59. package/dist/form/useFormReset.js.map +1 -1
  60. package/dist/form/useNumberField.d.ts +5 -5
  61. package/dist/form/useNumberField.js +10 -2
  62. package/dist/form/useNumberField.js.map +1 -1
  63. package/dist/form/useSelectCombobox.js +2 -2
  64. package/dist/form/useSelectCombobox.js.map +1 -1
  65. package/dist/form/useTextField.d.ts +76 -59
  66. package/dist/form/useTextField.js +7 -1
  67. package/dist/form/useTextField.js.map +1 -1
  68. package/dist/interaction/utils.d.ts +14 -0
  69. package/dist/interaction/utils.js +23 -12
  70. package/dist/interaction/utils.js.map +1 -1
  71. package/dist/menu/MenuBar.js +1 -1
  72. package/dist/menu/MenuBar.js.map +1 -1
  73. package/dist/menu/MenuItemTextField.d.ts +1 -2
  74. package/dist/menu/MenuItemTextField.js.map +1 -1
  75. package/dist/menu/MenuWidget.js +3 -2
  76. package/dist/menu/MenuWidget.js.map +1 -1
  77. package/dist/movement/constants.d.ts +10 -0
  78. package/dist/movement/constants.js +20 -4
  79. package/dist/movement/constants.js.map +1 -1
  80. package/dist/movement/types.d.ts +59 -10
  81. package/dist/movement/types.js.map +1 -1
  82. package/dist/movement/useKeyboardMovementProvider.d.ts +5 -1
  83. package/dist/movement/useKeyboardMovementProvider.js +171 -73
  84. package/dist/movement/useKeyboardMovementProvider.js.map +1 -1
  85. package/dist/tabs/useTabList.js +1 -1
  86. package/dist/tabs/useTabList.js.map +1 -1
  87. package/dist/test-utils/drag.d.ts +6 -9
  88. package/dist/transition/useCarousel.d.ts +2 -2
  89. package/dist/transition/useCarousel.js.map +1 -1
  90. package/dist/tree/Tree.js +1 -1
  91. package/dist/tree/Tree.js.map +1 -1
  92. package/dist/tree/_tree.scss +1 -1
  93. package/dist/tree/useTreeMovement.d.ts +2 -1
  94. package/dist/tree/useTreeMovement.js +2 -1
  95. package/dist/tree/useTreeMovement.js.map +1 -1
  96. package/dist/types.d.ts +14 -0
  97. package/dist/types.js.map +1 -1
  98. package/dist/utils/getMiddleOfRange.d.ts +2 -3
  99. package/dist/utils/getMiddleOfRange.js.map +1 -1
  100. package/dist/utils/getPercentage.d.ts +2 -9
  101. package/dist/utils/getPercentage.js +1 -1
  102. package/dist/utils/getPercentage.js.map +1 -1
  103. package/dist/utils/getRangeSteps.d.ts +2 -3
  104. package/dist/utils/getRangeSteps.js +0 -3
  105. package/dist/utils/getRangeSteps.js.map +1 -1
  106. package/dist/utils/nearest.d.ts +2 -3
  107. package/dist/utils/nearest.js +0 -3
  108. package/dist/utils/nearest.js.map +1 -1
  109. package/dist/utils/trigonometry.d.ts +31 -0
  110. package/dist/utils/trigonometry.js +25 -0
  111. package/dist/utils/trigonometry.js.map +1 -0
  112. package/dist/window-splitter/_window-splitter.scss +1 -1
  113. package/dist/window-splitter/useWindowSplitter.d.ts +1 -1
  114. package/dist/window-splitter/useWindowSplitter.js.map +1 -1
  115. package/package.json +1 -1
  116. package/src/datetime/NativeDateField.tsx +92 -0
  117. package/src/datetime/NativeTimeField.tsx +94 -0
  118. package/src/datetime/useDateField.ts +193 -0
  119. package/src/datetime/useTimeField.ts +233 -0
  120. package/src/datetime/utils.ts +48 -0
  121. package/src/draggable/utils.ts +3 -6
  122. package/src/expansion-panel/ExpansionList.tsx +2 -1
  123. package/src/expansion-panel/useExpansionList.ts +6 -12
  124. package/src/form/FormMessage.tsx +4 -0
  125. package/src/form/FormMessageContainer.tsx +8 -4
  126. package/src/form/FormMessageCounter.tsx +17 -6
  127. package/src/form/Listbox.tsx +18 -46
  128. package/src/form/ListboxProvider.ts +61 -1
  129. package/src/form/NativeSelect.tsx +1 -0
  130. package/src/form/TextArea.tsx +1 -0
  131. package/src/form/TextField.tsx +1 -0
  132. package/src/form/formMessageContainerStyles.ts +10 -2
  133. package/src/form/sliderUtils.ts +3 -7
  134. package/src/form/types.ts +15 -0
  135. package/src/form/useCombobox.ts +15 -10
  136. package/src/form/useFormReset.ts +12 -5
  137. package/src/form/useNumberField.ts +17 -14
  138. package/src/form/useSelectCombobox.ts +2 -2
  139. package/src/form/useTextField.ts +102 -69
  140. package/src/interaction/utils.ts +18 -20
  141. package/src/menu/MenuBar.tsx +1 -1
  142. package/src/menu/MenuItemTextField.tsx +1 -3
  143. package/src/menu/MenuWidget.tsx +4 -2
  144. package/src/movement/constants.ts +26 -4
  145. package/src/movement/types.ts +84 -19
  146. package/src/movement/useKeyboardMovementProvider.ts +209 -95
  147. package/src/tabs/useTabList.ts +1 -1
  148. package/src/test-utils/drag.ts +8 -12
  149. package/src/transition/useCarousel.ts +2 -2
  150. package/src/tree/Tree.tsx +1 -1
  151. package/src/tree/useTreeMovement.ts +4 -0
  152. package/src/types.ts +16 -0
  153. package/src/utils/getMiddleOfRange.ts +2 -3
  154. package/src/utils/getPercentage.ts +3 -11
  155. package/src/utils/getRangeSteps.ts +3 -3
  156. package/src/utils/nearest.ts +3 -3
  157. package/src/utils/trigonometry.ts +46 -0
  158. package/src/window-splitter/useWindowSplitter.ts +3 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/form/useTextField.ts"],"sourcesContent":["\"use client\";\n\nimport {\n type HTMLAttributes,\n type ReactNode,\n type Ref,\n type RefCallback,\n type RefObject,\n useCallback,\n useRef,\n useState,\n} from \"react\";\n\nimport { getIcon } from \"../icon/config.js\";\nimport { type UseStateInitializer, type UseStateSetter } from \"../types.js\";\nimport { useEnsuredId } from \"../useEnsuredId.js\";\nimport { useEnsuredRef } from \"../useEnsuredRef.js\";\nimport { type TextFieldProps } from \"./TextField.js\";\nimport {\n type FormMessageInputLengthCounterProps,\n type FormMessageProps,\n} from \"./types.js\";\nimport {\n type ErrorMessageOptions,\n type GetErrorIcon,\n type GetErrorMessage,\n type IsErrored,\n type TextFieldValidationOptions,\n type TextFieldValidationType,\n defaultGetErrorIcon,\n defaultGetErrorMessage,\n defaultIsErrored,\n} from \"./validation.js\";\n\nconst noop = (): void => {\n // do nothing\n};\n\n/**\n * @since 2.5.0\n * @since 6.0.0 Added the `onInvalid` handler\n */\nexport type TextFieldChangeHandlers<\n E extends HTMLInputElement | HTMLTextAreaElement,\n> = Pick<HTMLAttributes<E>, \"onBlur\" | \"onChange\" | \"onInvalid\">;\n\n/** @since 6.0.0 */\nexport interface ErrorChangeHandlerOptions<\n E extends HTMLInputElement | HTMLTextAreaElement,\n> {\n /**\n * A ref containing the `TextField` or `TextArea` if you need access to that\n * DOM node for error reporting.\n */\n ref: RefObject<E>;\n\n /**\n * The current name for the `TextField` or `TextArea`.\n */\n name: string;\n\n /**\n * This will be `true` when the `TextField`/`TextArea` has an error.\n */\n error: boolean;\n\n /**\n * The error message returned by {@link GetErrorMessage}/the browser's\n * validation message. This is normally an empty string when the {@link error}\n * state is `false`.\n */\n errorMessage: string;\n}\n\n/**\n * A function that reports the error state changing. A good use-case for this is\n * to keep track of all the errors within your form and keep a submit button\n * disabled until they have been resolved.\n *\n * Example:\n *\n * ```ts\n * const [errors, setErrors] = useState<Record<string, boolean | undefined>>({});\n * const onErrorChange: ErrorChangeHandler = ({ name, error }) =>\n * setErrors((prevErrors) => ({ ...prevErrors, [name]: error }));\n *\n * const invalid = Object.values(errors).some(Boolean);\n *\n * // form implementation is left as an exercise for the reader\n * <Button type=\"submit\" disabled={invalid} onClick={submitForm}>Submit</Button>\n * ```\n *\n * @since 2.5.0\n * @since 6.0.0 Changed to object argument.\n */\nexport type ErrorChangeHandler<\n E extends HTMLInputElement | HTMLTextAreaElement,\n> = (options: ErrorChangeHandlerOptions<E>) => void;\n\n/** @since 2.5.6 */\nexport interface TextFieldHookState {\n /**\n * The current value for the `TextField` or `TextArea`.\n */\n value: string;\n\n /**\n * This will be `true` when the `TextField`/`TextArea` has an error.\n */\n error: boolean;\n\n /**\n * The error message returned by {@link GetErrorMessage}/the browser's\n * validation message. This is normally an empty string when the {@link error}\n * state is `false`.\n */\n errorMessage: string;\n}\n\n/**\n * All the props that will be generated and return from the `useTextField` hook\n * that should be passed to a `FormMessage` component.\n *\n * @since 2.5.0\n */\nexport interface ProvidedFormMessageProps\n extends Pick<FormMessageProps, \"id\" | \"theme\" | \"children\">,\n Required<Pick<TextFieldProps, \"error\">>,\n Partial<Pick<FormMessageInputLengthCounterProps, \"length\" | \"maxLength\">> {}\n\n/**\n * All the props that will be generated and returned by the `useTextField` hook\n * that should be passed to a `TextField` component.\n *\n * @since 2.5.0\n */\nexport interface ProvidedTextFieldProps<\n E extends HTMLInputElement | HTMLTextAreaElement,\n> extends TextFieldValidationOptions,\n TextFieldChangeHandlers<E>,\n Required<Pick<TextFieldProps, \"id\" | \"name\" | \"value\" | \"error\">>,\n Pick<TextFieldProps, \"aria-describedby\" | \"rightAddon\"> {\n /**\n * A ref that must be passed to the `TextField`/`TextArea` so that the custom\n * validity behavior can work.\n *\n * @since 6.0.0\n */\n ref: RefCallback<E>;\n}\n\n/**\n * @since 2.5.0\n */\nexport interface ProvidedTextFieldMessageProps<\n E extends HTMLInputElement | HTMLTextAreaElement,\n> extends ProvidedTextFieldProps<E> {\n /**\n * These props will be defined as long as the `disableMessage` prop is not\n * `true` from the `useTextField` hook.\n */\n messageProps: ProvidedFormMessageProps;\n}\n\n/** @since 2.5.6 */\nexport interface TextFieldHookOptions<\n E extends HTMLInputElement | HTMLTextAreaElement,\n> extends TextFieldValidationOptions,\n TextFieldChangeHandlers<E> {\n /**\n * An optional id to use for the `TextField` or `TextArea` that is also used\n * to create an id for the inline help/error messages.\n *\n * @defaultValue `\"text-field-\" + useId()`\n */\n id?: string;\n\n /**\n * An optional ref that should be merged with the ref returned by this hook.\n * This should really only be used if you are making a custom component using\n * this hook and forwarding refs. If you need a ref to access the `<input>` or\n * `<textarea>` DOM node, you can use the `fieldRef` returned by this hook\n * instead.\n *\n * @example Accessing TextField DOM Node\n * ```tsx\n * import { TextField } from \"@react-md/core/form/TextField\";\n * import { useTextField } from \"@react-md/core/form/useTextField\";\n * import { useEffect } from \"react\";\n * import type { ReactElement } from \"react\";\n *\n * function Example(): ReactElement {\n * const { fieldRef, fieldProps } = useTextField({ name: \"example\" });\n *\n * useEffect(() => {\n * fieldRef.current;\n * // ^ HTMLInputElement | null\n * }, [fieldRef]);\n *\n * return <TextField {...fieldProps} label=\"Example\" />;\n * }\n * ```\n */\n ref?: Ref<E>;\n\n /**\n * A unique name to attach to the `TextField`, `TextArea` or `Password`\n * component.\n */\n name: string;\n\n /**\n * Boolean if the `FormMessage` should also display a counter for the\n * remaining letters allowed based on the `maxLength`.\n *\n * This will still be considered false if the `maxLength` value is not\n * provided.\n *\n * @defaultValue `false`\n */\n counter?: boolean;\n\n /**\n * This is used internally for the `useNumberField` hook and probably\n * shouldn't be used otherwise. This is just passed into the\n * {@link getErrorMessage} options and is used for additional validation.\n *\n * @defaultValue `false`\n */\n isNumber?: boolean;\n\n /**\n * The default value to use for the `TextField` or `TextArea` one initial\n * render. If you want to manually change the value to something else after\n * the initial render, either change the `key` for the component containing\n * this hook, or use the `setState` function returned from this hook.\n *\n * @defaultValue `\"\"`\n */\n defaultValue?: UseStateInitializer<string>;\n\n /**\n * An optional help text to display in the `FormMessage` component when there\n * is not an error.\n */\n helpText?: ReactNode;\n\n /**\n * A function used to determine if the `TextField` or `TextArea` is an in\n * errored state.\n *\n * @see {@link defaultIsErrored}\n * @defaultValue `defaultIsErrored`\n */\n isErrored?: IsErrored;\n\n /**\n * An optional error icon used in the {@link getErrorIcon} option.\n *\n * @defaultValue `getIcon(\"error\")`\n */\n errorIcon?: ReactNode;\n\n /**\n * A function used to get the error icon to display at the right of the\n * `TextField` or `TextArea`. The default behavior will only show an icon when\n * the `error` state is `true` and an `errorIcon` option has been provided.\n *\n * @see {@link defaultGetErrorIcon}\n * @defaultValue `defaultGetErrorIcon`\n */\n getErrorIcon?: GetErrorIcon;\n\n /**\n * A function to get and display an error message based on the `TextField` or\n * `TextArea` validity.\n *\n * @see {@link defaultGetErrorMessage}\n * @defaultValue `defaultGetErrorMessage`\n */\n getErrorMessage?: GetErrorMessage;\n\n /**\n * An optional function that will be called whenever the `error` state is\n * changed. This can be used for more complex forms to `disable` the Submit\n * button or anything else if any field has an error.\n *\n * @defaultValue `() => {}`\n */\n onErrorChange?: ErrorChangeHandler<E>;\n\n /**\n * Set this to `true` to prevent the `errorMessage` from being\n * rendered inline below the `TextField`.\n *\n * @defaultValue `false`\n * @since 6.0.0 Only disables the `errorMessage` behavior so\n * that counters and help text can still be rendered easily.\n */\n disableMessage?: boolean;\n\n /**\n * Boolean if the `maxLength` prop should not be passed to the `TextField`\n * component since it will prevent any additional characters from being\n * entered in the text field which might feel like weird behavior to some\n * users. This should really only be used when the `counter` option is also\n * enabled and rendering along with a `FormMessage` component.\n *\n * @defaultValue `false`\n */\n disableMaxLength?: boolean;\n\n /**\n * @defaultValue `\"recommended\"`\n */\n validationType?: TextFieldValidationType;\n}\n\n/** @since 6.0.0 */\nexport interface TextFieldImplementation<\n E extends HTMLInputElement | HTMLTextAreaElement,\n> extends TextFieldHookState {\n fieldRef: RefObject<E>;\n reset: () => void;\n setState: UseStateSetter<Readonly<TextFieldHookState>>;\n fieldProps: ProvidedTextFieldProps<E>;\n}\n\n/** @since 6.0.0 */\nexport interface TextFieldWithMessageImplementation<\n E extends HTMLInputElement | HTMLTextAreaElement,\n> extends TextFieldImplementation<E> {\n fieldProps: ProvidedTextFieldMessageProps<E>;\n}\n\n/** @since 6.0.0 */\nexport interface ValidatedTextFieldImplementation<\n E extends HTMLInputElement | HTMLTextAreaElement,\n> extends TextFieldImplementation<E> {\n fieldProps: ProvidedTextFieldProps<E> | ProvidedTextFieldMessageProps<E>;\n}\n\n/**\n * If you do not want to display the error messages below the `TextField` and\n * handle error messages separately, set the `disableMessage` option to `true`.\n *\n * @example No Inline Error Messages\n * ```tsx\n * import { type ReactElement } from \"react\";\n * import { TextField } from \"@react-md/core/form/TextField\";\n * import { useTextField } from \"@react-md/core/form/useTextField\";\n *\n * function Example(): ReactElement {\n * const { fieldProps } = useTextField({\n * name: \"example\",\n * disableMessage: true,\n * });\n *\n * return <TextField {...fieldProps} label=\"Example\" />;\n * }\n * ```\n *\n * Look at the other {@link useTextField} override for additional examples.\n *\n * @see {@link https://react-md.dev/components/text-field | TextField Demos}\n * @see {@link https://react-md.dev/hooks/use-text-field | useTextField Demos}\n */\nexport function useTextField<E extends HTMLInputElement | HTMLTextAreaElement>(\n options: TextFieldHookOptions<E> & { disableMessage: true }\n): TextFieldImplementation<E>;\n\n/**\n * @example Simple Example\n * ```tsx\n * import { type ReactElement } from \"react\";\n * import { TextField } from \"@react-md/core/form/TextField\";\n * import { useTextField } from \"@react-md/core/form/useTextField\";\n *\n * function Example(): ReactElement {\n * const { fieldProps } = useTextField({\n * name: \"example\",\n * });\n *\n * return <TextField {...fieldProps} label=\"Example\" />;\n * }\n * ```\n *\n * @example Inline Counter\n * ```tsx\n * import { type ReactElement } from \"react\";\n * import { TextField } from \"@react-md/core/form/TextField\";\n * import { useTextField } from \"@react-md/core/form/useTextField\";\n *\n * function Example(): ReactElement {\n * const { fieldProps } = useTextField({\n * name: \"example\",\n * counter: true,\n * required: true,\n * maxLength: 20,\n * // this allows the user to type beyond the max length limit and display\n * // an error message. omit or set to `false` to enforce the max length instead\n * disableMaxLength: true,\n * });\n *\n * return <TextField {...fieldProps} label=\"Example\" />;\n * }\n * ```\n *\n * @example Adding Constraints\n * ```tsx\n * import { type ReactElement } from \"react\";\n * import { TextField } from \"@react-md/core/form/TextField\";\n * import { useTextField } from \"@react-md/core/form/useTextField\";\n *\n * function Example(): ReactElement {\n * const { fieldProps } = useTextField({\n * name: \"example\",\n * required: true,\n * pattern: \"^[A-Za-z]+$\",\n * minLength: 4,\n * maxLength: 20,\n * });\n *\n * return <TextField {...fieldProps} label=\"Example\" />;\n * }\n * ```\n *\n * @example Custom Validation\n * ```tsx\n * import { type ReactElement } from \"react\";\n * import { TextField } from \"@react-md/core/form/TextField\";\n * import { useTextField } from \"@react-md/core/form/useTextField\";\n *\n * function Example(): ReactElement {\n * const { fieldProps } = useTextField({\n * name: \"example\",\n * required: true,\n * getErrorMessage(options) {\n * const {\n * value,\n * pattern,\n * required,\n * minLength,\n * maxLength,\n * validity,\n * validationMessage,\n * isNumber,\n * isBlurEvent,\n * validationType,\n * } = options;\n *\n * if (validity.tooLong) {\n * return `No more than ${maxLength} characters.`;\n * }\n *\n * if (validity.tooShort) {\n * return `No more than ${minLength} characters.`;\n * }\n *\n * if (validity.valueMissing) {\n * return \"This value is required!\";\n * }\n *\n * if (value === \"bad value\") {\n * return \"Value cannot be bad value\";\n * }\n *\n * return defaultGetErrorMessage(options);\n * }\n * });\n *\n * return <TextField {...fieldProps} label=\"Example\" />;\n * }\n * ```\n *\n * @see {@link https://react-md.dev/components/text-field | TextField Demos}\n * @see {@link https://react-md.dev/hooks/use-text-field | useTextField Demos}\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation\n * @since 2.5.6\n * @since 6.0.0 This hook returns an object instead of an ordered list. Also\n * added the ability to display an inline counter and help text while disabling\n * the error messaging.\n */\nexport function useTextField<E extends HTMLInputElement | HTMLTextAreaElement>(\n options: TextFieldHookOptions<E>\n): TextFieldWithMessageImplementation<E>;\n/**\n * @see {@link https://react-md.dev/components/text-field | TextField Demos}\n * @see {@link https://react-md.dev/hooks/use-text-field | useTextField Demos}\n * @since 6.0.0\n */\nexport function useTextField<E extends HTMLInputElement | HTMLTextAreaElement>(\n options: TextFieldHookOptions<E>\n): ValidatedTextFieldImplementation<E> {\n const {\n id: propId,\n ref: propRef,\n name,\n defaultValue = \"\",\n isNumber = false,\n required,\n pattern,\n minLength,\n maxLength,\n onBlur = noop,\n onChange = noop,\n onInvalid = noop,\n counter = false,\n helpText,\n validationType = \"recommended\",\n disableMessage = false,\n disableMaxLength = false,\n errorIcon: propErrorIcon,\n isErrored = defaultIsErrored,\n onErrorChange = noop,\n getErrorIcon = defaultGetErrorIcon,\n getErrorMessage = defaultGetErrorMessage,\n } = options;\n\n const id = useEnsuredId(propId, \"text-field\");\n const messageId = `${id}-message`;\n const [fieldRef, ref] = useEnsuredRef(propRef);\n const [state, setState] = useState<TextFieldHookState>(() => {\n const value =\n typeof defaultValue === \"function\" ? defaultValue() : defaultValue;\n\n return {\n value,\n error: false,\n errorMessage: \"\",\n };\n });\n const { value, error, errorMessage } = state;\n\n // using a `ref` instead of a `useCallback` makes it so the `defaultValue`\n // will always be used once reset.\n const reset = useRef(() => {\n fieldRef.current?.setCustomValidity(\"\");\n setState({ value, error: false, errorMessage: \"\" });\n }).current;\n\n const errored = useRef(error);\n const checkValidity = useCallback(\n (isBlurEvent: boolean) => {\n const field = fieldRef.current;\n if (!field) {\n throw new Error(\"Unable to check validity due to missing ref\");\n }\n\n // need to temporarily set the `maxLength` back so it can be \"verified\"\n // through the validity api\n /* istanbul ignore next */\n if (isBlurEvent && disableMaxLength && typeof maxLength === \"number\") {\n field.maxLength = maxLength;\n }\n\n const { value } = field;\n field.setCustomValidity(\"\");\n field.checkValidity();\n\n // remove the temporarily set `maxLength` attribute after checking the\n // validity\n /* istanbul ignore next */\n if (disableMaxLength && typeof maxLength === \"number\") {\n field.removeAttribute(\"maxLength\");\n }\n\n const options: ErrorMessageOptions = {\n value,\n pattern,\n required,\n minLength,\n maxLength,\n isBlurEvent,\n isNumber,\n validationType,\n validity: field.validity,\n validationMessage: field.validationMessage,\n };\n const errorMessage = getErrorMessage(options);\n const error = isErrored({ ...options, errorMessage });\n\n if (errored.current !== error) {\n errored.current = error;\n onErrorChange({\n ref: fieldRef,\n name,\n error,\n errorMessage,\n });\n }\n\n /* istanbul ignore next */\n if (errorMessage !== field.validationMessage) {\n field.setCustomValidity(errorMessage);\n }\n\n setState((prevState) => {\n if (\n prevState.value === value &&\n prevState.error === error &&\n prevState.errorMessage === errorMessage\n ) {\n return prevState;\n }\n\n return {\n value,\n error,\n errorMessage,\n };\n });\n },\n [\n disableMaxLength,\n fieldRef,\n getErrorMessage,\n isErrored,\n isNumber,\n maxLength,\n minLength,\n name,\n onErrorChange,\n pattern,\n required,\n validationType,\n ]\n );\n\n const errorIcon = getIcon(\"error\", propErrorIcon);\n const fieldProps: ProvidedTextFieldProps<E> & {\n messageProps?: ProvidedFormMessageProps;\n } = {\n id,\n ref,\n name,\n value,\n error,\n required,\n pattern,\n minLength,\n maxLength: disableMaxLength ? undefined : maxLength,\n rightAddon: getErrorIcon({\n error,\n errorIcon,\n errorMessage,\n }),\n onBlur(event) {\n onBlur(event);\n if (event.isPropagationStopped()) {\n return;\n }\n\n checkValidity(true);\n },\n onChange(event) {\n onChange(event);\n if (event.isPropagationStopped()) {\n return;\n }\n\n if (validationType === \"blur\") {\n const { value } = event.currentTarget;\n setState((prevState) => ({\n ...prevState,\n value,\n }));\n return;\n }\n\n checkValidity(false);\n },\n onInvalid(event) {\n onInvalid(event);\n if (\n event.isPropagationStopped() ||\n event.currentTarget === document.activeElement\n ) {\n return;\n }\n\n // this makes it so that if a submit button is clicked in a form, all\n // textfields will gain the error state immediately\n // also need to extract the validationMessage immediately because of the\n // SyntheticEvent behavior in React. By the time the `setState` is called,\n // the event might've been deleted\n const { validationMessage } = event.currentTarget;\n\n setState((prevState) => {\n if (prevState.error) {\n return prevState;\n }\n\n return {\n ...prevState,\n error: true,\n errorMessage: validationMessage,\n };\n });\n },\n };\n\n const isCounter = counter && typeof maxLength === \"number\";\n if (isCounter || helpText || !disableMessage) {\n fieldProps[\"aria-describedby\"] = messageId;\n fieldProps.messageProps = {\n id: messageId,\n error,\n length: counter ? value.length : undefined,\n maxLength: (counter && maxLength) || undefined,\n children: (!disableMessage && errorMessage) || helpText,\n };\n }\n\n return {\n ...state,\n reset,\n setState,\n fieldRef,\n fieldProps,\n };\n}\n"],"names":["useCallback","useRef","useState","getIcon","useEnsuredId","useEnsuredRef","defaultGetErrorIcon","defaultGetErrorMessage","defaultIsErrored","noop","useTextField","options","id","propId","ref","propRef","name","defaultValue","isNumber","required","pattern","minLength","maxLength","onBlur","onChange","onInvalid","counter","helpText","validationType","disableMessage","disableMaxLength","errorIcon","propErrorIcon","isErrored","onErrorChange","getErrorIcon","getErrorMessage","messageId","fieldRef","state","setState","value","error","errorMessage","reset","current","setCustomValidity","errored","checkValidity","isBlurEvent","field","Error","removeAttribute","validity","validationMessage","prevState","fieldProps","undefined","rightAddon","event","isPropagationStopped","currentTarget","document","activeElement","isCounter","messageProps","length","children"],"mappings":"AAAA;AAEA,SAMEA,WAAW,EACXC,MAAM,EACNC,QAAQ,QACH,QAAQ;AAEf,SAASC,OAAO,QAAQ,oBAAoB;AAE5C,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,aAAa,QAAQ,sBAAsB;AAMpD,SAOEC,mBAAmB,EACnBC,sBAAsB,EACtBC,gBAAgB,QACX,kBAAkB;AAEzB,MAAMC,OAAO;AACX,aAAa;AACf;AAkcA;;;;CAIC,GACD,OAAO,SAASC,aACdC,OAAgC;IAEhC,MAAM,EACJC,IAAIC,MAAM,EACVC,KAAKC,OAAO,EACZC,IAAI,EACJC,eAAe,EAAE,EACjBC,WAAW,KAAK,EAChBC,Q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AIhC,mBAAmB,QAAQ;gBAC7B,MAAM,EAAEa,KAAK,EAAE,GAAGkB,MAAME,aAAa;gBACrCrB,SAAS,CAACe,YAAe,CAAA;wBACvB,GAAGA,SAAS;wBACZd;oBACF,CAAA;gBACA;YACF;YAEAO,cAAc;QAChB;QACAvB,WAAUkC,KAAK;YACblC,UAAUkC;YACV,IACEA,MAAMC,oBAAoB,MAC1BD,MAAME,aAAa,KAAKC,SAASC,aAAa,EAC9C;gBACA;YACF;YAEA,qEAAqE;YACrE,mDAAmD;YACnD,wEAAwE;YACxE,0EAA0E;YAC1E,kCAAkC;YAClC,MAAM,EAAET,iBAAiB,EAAE,GAAGK,MAAME,aAAa;YAEjDrB,SAAS,CAACe;gBACR,IAAIA,UAAUb,KAAK,EAAE;oBACnB,OAAOa;gBACT;gBAEA,OAAO;oBACL,GAAGA,SAAS;oBACZb,OAAO;oBACPC,cAAcW;gBAChB;YACF;QACF;IACF;IAEA,MAAMU,YAAYtC,WAAW,OAAOJ,cAAc;IAClD,IAAI0C,aAAarC,YAAY,CAACE,gBAAgB;QAC5C2B,UAAU,CAAC,mBAAmB,GAAGnB;QACjCmB,WAAWS,YAAY,GAAG;YACxBrD,IAAIyB;YACJK;YACAwB,QAAQxC,UAAUe,MAAMyB,MAAM,GAAGT;YACjCnC,WAAW,AAACI,WAAWJ,aAAcmC;YACrCU,UAAU,AAAC,CAACtC,kBAAkBc,gBAAiBhB;QACjD;IACF;IAEA,OAAO;QACL,GAAGY,KAAK;QACRK;QACAJ;QACAF;QACAkB;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/form/useTextField.ts"],"sourcesContent":["\"use client\";\n\nimport {\n type HTMLAttributes,\n type ReactNode,\n type Ref,\n type RefCallback,\n type RefObject,\n useCallback,\n useRef,\n useState,\n} from \"react\";\n\nimport { getIcon } from \"../icon/config.js\";\nimport { type UseStateInitializer, type UseStateSetter } from \"../types.js\";\nimport { useEnsuredId } from \"../useEnsuredId.js\";\nimport { useEnsuredRef } from \"../useEnsuredRef.js\";\nimport { type TextFieldProps } from \"./TextField.js\";\nimport {\n type FormMessageInputLengthCounterProps,\n type FormMessageProps,\n} from \"./types.js\";\nimport { useFormReset } from \"./useFormReset.js\";\nimport {\n type ErrorMessageOptions,\n type GetErrorIcon,\n type GetErrorMessage,\n type IsErrored,\n type TextFieldValidationOptions,\n type TextFieldValidationType,\n defaultGetErrorIcon,\n defaultGetErrorMessage,\n defaultIsErrored,\n} from \"./validation.js\";\n\nconst noop = (): void => {\n // do nothing\n};\n\n/**\n * @since 2.5.0\n * @since 6.0.0 Added the `onInvalid` handler\n */\nexport type TextFieldChangeHandlers<\n E extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement,\n> = Pick<HTMLAttributes<E>, \"onBlur\" | \"onChange\" | \"onInvalid\">;\n\n/** @since 6.0.0 */\nexport interface ErrorChangeHandlerOptions<\n E extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement,\n> {\n /**\n * A ref containing the `TextField` or `TextArea` if you need access to that\n * DOM node for error reporting.\n */\n ref: RefObject<E>;\n\n /**\n * The current name for the `TextField` or `TextArea`.\n */\n name: string;\n\n /**\n * This will be `true` when the `TextField`/`TextArea` has an error.\n */\n error: boolean;\n\n /**\n * The error message returned by {@link GetErrorMessage}/the browser's\n * validation message. This is normally an empty string when the {@link error}\n * state is `false`.\n */\n errorMessage: string;\n}\n\n/**\n * A function that reports the error state changing. A good use-case for this is\n * to keep track of all the errors within your form and keep a submit button\n * disabled until they have been resolved.\n *\n * Example:\n *\n * ```ts\n * const [errors, setErrors] = useState<Record<string, boolean | undefined>>({});\n * const onErrorChange: ErrorChangeHandler = ({ name, error }) =>\n * setErrors((prevErrors) => ({ ...prevErrors, [name]: error }));\n *\n * const invalid = Object.values(errors).some(Boolean);\n *\n * // form implementation is left as an exercise for the reader\n * <Button type=\"submit\" disabled={invalid} onClick={submitForm}>Submit</Button>\n * ```\n *\n * @since 2.5.0\n * @since 6.0.0 Changed to object argument.\n */\nexport type ErrorChangeHandler<\n E extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement,\n> = (options: ErrorChangeHandlerOptions<E>) => void;\n\n/** @since 2.5.6 */\nexport interface TextFieldHookState {\n /**\n * The current value for the `TextField` or `TextArea`.\n */\n value: string;\n\n /**\n * This will be `true` when the `TextField`/`TextArea` has an error.\n */\n error: boolean;\n\n /**\n * The error message returned by {@link GetErrorMessage}/the browser's\n * validation message. This is normally an empty string when the {@link error}\n * state is `false`.\n */\n errorMessage: string;\n}\n\n/**\n * All the props that will be generated and return from the `useTextField` hook\n * that should be passed to a `FormMessage` component.\n *\n * @since 2.5.0\n */\nexport interface ProvidedFormMessageProps\n extends Pick<FormMessageProps, \"id\" | \"theme\" | \"children\">,\n Required<Pick<TextFieldProps, \"error\">>,\n Partial<Pick<FormMessageInputLengthCounterProps, \"length\" | \"maxLength\">> {}\n\n/**\n * All the props that will be generated and returned by the `useTextField` hook\n * that should be passed to a `TextField` component.\n *\n * @since 2.5.0\n */\nexport interface ProvidedTextFieldProps<\n E extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement,\n> extends TextFieldValidationOptions,\n TextFieldChangeHandlers<E>,\n Required<Pick<TextFieldProps, \"id\" | \"name\" | \"value\" | \"error\">>,\n Pick<TextFieldProps, \"aria-describedby\" | \"rightAddon\"> {\n /**\n * A ref that must be passed to the `TextField`/`TextArea` so that the custom\n * validity behavior can work.\n *\n * @since 6.0.0\n */\n ref: RefCallback<E>;\n}\n\n/**\n * @since 2.5.0\n */\nexport interface ProvidedTextFieldMessageProps<\n E extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement,\n> extends ProvidedTextFieldProps<E> {\n /**\n * These props will be defined as long as the `disableMessage` prop is not\n * `true` from the `useTextField` hook.\n */\n messageProps: ProvidedFormMessageProps;\n}\n\n/**\n * @since 6.3.0\n */\nexport interface TextFieldHookComponentOptions<\n E extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement,\n> {\n /**\n * An optional id to use for the `TextField`, `Password`, or `TextArea` that\n * is also used to create an id for the inline help/error messages.\n *\n * @defaultValue `\"text-field-\" + useId()`\n */\n id?: string;\n\n /**\n * A unique name to attach to the `TextField`, `TextArea`, or `Password`\n * component.\n */\n name: string;\n\n /**\n * @since 6.3.0\n */\n form?: string;\n\n /**\n * Boolean if the `FormMessage` should also display a counter for the\n * remaining letters allowed based on the `maxLength`.\n *\n * This will still be considered false if the `maxLength` value is not\n * provided.\n *\n * @defaultValue `false`\n */\n counter?: boolean;\n\n /**\n * An optional help text to display in the `FormMessage` component when there\n * is not an error.\n */\n helpText?: ReactNode;\n\n /**\n * A function used to determine if the `TextField` or `TextArea` is an in\n * errored state.\n *\n * @see {@link defaultIsErrored}\n * @defaultValue `defaultIsErrored`\n */\n isErrored?: IsErrored;\n\n /**\n * An optional error icon used in the {@link getErrorIcon} option.\n *\n * @defaultValue `getIcon(\"error\")`\n */\n errorIcon?: ReactNode;\n\n /**\n * A function used to get the error icon to display at the right of the\n * `TextField` or `TextArea`. The default behavior will only show an icon when\n * the `error` state is `true` and an `errorIcon` option has been provided.\n *\n * @see {@link defaultGetErrorIcon}\n * @defaultValue `defaultGetErrorIcon`\n */\n getErrorIcon?: GetErrorIcon;\n\n /**\n * A function to get and display an error message based on the `TextField` or\n * `TextArea` validity.\n *\n * @see {@link defaultGetErrorMessage}\n * @defaultValue `defaultGetErrorMessage`\n */\n getErrorMessage?: GetErrorMessage;\n\n /**\n * An optional function that will be called whenever the `error` state is\n * changed. This can be used for more complex forms to `disable` the Submit\n * button or anything else if any field has an error.\n *\n * @defaultValue `() => {}`\n */\n onErrorChange?: ErrorChangeHandler<E>;\n\n /**\n * Set to `true` to prevent the state from automatically resetting with a\n * form's `reset` event.\n *\n * @defaultValue `false`\n * @since 6.3.0\n */\n disableReset?: boolean;\n\n /**\n * Set this to `true` to prevent the `errorMessage` from being\n * rendered inline below the `TextField`.\n *\n * @defaultValue `false`\n * @since 6.0.0 Only disables the `errorMessage` behavior so\n * that counters and help text can still be rendered easily.\n */\n disableMessage?: boolean;\n\n /**\n * Boolean if the `maxLength` prop should not be passed to the `TextField`\n * component since it will prevent any additional characters from being\n * entered in the text field which might feel like weird behavior to some\n * users. This should really only be used when the `counter` option is also\n * enabled and rendering along with a `FormMessage` component.\n *\n * @defaultValue `false`\n */\n disableMaxLength?: boolean;\n\n /**\n * @defaultValue `\"recommended\"`\n */\n validationType?: TextFieldValidationType;\n}\n\n/** @since 2.5.6 */\nexport interface TextFieldHookOptions<\n E extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement,\n> extends TextFieldValidationOptions,\n TextFieldHookComponentOptions<E>,\n TextFieldChangeHandlers<E> {\n /**\n * An optional ref that should be merged with the ref returned by this hook.\n * This should really only be used if you are making a custom component using\n * this hook and forwarding refs. If you need a ref to access the `<input>` or\n * `<textarea>` DOM node, you can use the `fieldRef` returned by this hook\n * instead.\n *\n * @example Accessing TextField DOM Node\n * ```tsx\n * import { TextField } from \"@react-md/core/form/TextField\";\n * import { useTextField } from \"@react-md/core/form/useTextField\";\n * import { useEffect } from \"react\";\n * import type { ReactElement } from \"react\";\n *\n * function Example(): ReactElement {\n * const { fieldRef, fieldProps } = useTextField({ name: \"example\" });\n *\n * useEffect(() => {\n * fieldRef.current;\n * // ^ HTMLInputElement | null\n * }, [fieldRef]);\n *\n * return <TextField {...fieldProps} label=\"Example\" />;\n * }\n * ```\n */\n ref?: Ref<E>;\n\n /**\n * This is used internally for the `useNumberField` hook and probably\n * shouldn't be used otherwise. This is just passed into the\n * {@link getErrorMessage} options and is used for additional validation.\n *\n * @defaultValue `false`\n */\n isNumber?: boolean;\n\n /**\n * The default value to use for the `TextField` or `TextArea` one initial\n * render. If you want to manually change the value to something else after\n * the initial render, either change the `key` for the component containing\n * this hook, or use the `setState` function returned from this hook.\n *\n * @defaultValue `\"\"`\n */\n defaultValue?: UseStateInitializer<string>;\n}\n\n/** @since 6.0.0 */\nexport interface TextFieldImplementation<\n E extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement,\n> extends TextFieldHookState {\n fieldRef: RefObject<E>;\n reset: () => void;\n setState: UseStateSetter<Readonly<TextFieldHookState>>;\n fieldProps: ProvidedTextFieldProps<E>;\n}\n\n/** @since 6.0.0 */\nexport interface TextFieldWithMessageImplementation<\n E extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement,\n> extends TextFieldImplementation<E> {\n fieldProps: ProvidedTextFieldMessageProps<E>;\n}\n\n/** @since 6.0.0 */\nexport interface ValidatedTextFieldImplementation<\n E extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement,\n> extends TextFieldImplementation<E> {\n fieldProps: ProvidedTextFieldProps<E> | ProvidedTextFieldMessageProps<E>;\n}\n\n/**\n * If you do not want to display the error messages below the `TextField` and\n * handle error messages separately, set the `disableMessage` option to `true`.\n *\n * @example No Inline Error Messages\n * ```tsx\n * import { type ReactElement } from \"react\";\n * import { TextField } from \"@react-md/core/form/TextField\";\n * import { useTextField } from \"@react-md/core/form/useTextField\";\n *\n * function Example(): ReactElement {\n * const { fieldProps } = useTextField({\n * name: \"example\",\n * disableMessage: true,\n * });\n *\n * return <TextField {...fieldProps} label=\"Example\" />;\n * }\n * ```\n *\n * Look at the other {@link useTextField} override for additional examples.\n *\n * @see {@link https://react-md.dev/components/text-field | TextField Demos}\n * @see {@link https://react-md.dev/hooks/use-text-field | useTextField Demos}\n */\nexport function useTextField<\n E extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement,\n>(\n options: TextFieldHookOptions<E> & { disableMessage: true }\n): TextFieldImplementation<E>;\n\n/**\n * @example Simple Example\n * ```tsx\n * import { type ReactElement } from \"react\";\n * import { TextField } from \"@react-md/core/form/TextField\";\n * import { useTextField } from \"@react-md/core/form/useTextField\";\n *\n * function Example(): ReactElement {\n * const { fieldProps } = useTextField({\n * name: \"example\",\n * });\n *\n * return <TextField {...fieldProps} label=\"Example\" />;\n * }\n * ```\n *\n * @example Inline Counter\n * ```tsx\n * import { type ReactElement } from \"react\";\n * import { TextField } from \"@react-md/core/form/TextField\";\n * import { useTextField } from \"@react-md/core/form/useTextField\";\n *\n * function Example(): ReactElement {\n * const { fieldProps } = useTextField({\n * name: \"example\",\n * counter: true,\n * required: true,\n * maxLength: 20,\n * // this allows the user to type beyond the max length limit and display\n * // an error message. omit or set to `false` to enforce the max length instead\n * disableMaxLength: true,\n * });\n *\n * return <TextField {...fieldProps} label=\"Example\" />;\n * }\n * ```\n *\n * @example Adding Constraints\n * ```tsx\n * import { type ReactElement } from \"react\";\n * import { TextField } from \"@react-md/core/form/TextField\";\n * import { useTextField } from \"@react-md/core/form/useTextField\";\n *\n * function Example(): ReactElement {\n * const { fieldProps } = useTextField({\n * name: \"example\",\n * required: true,\n * pattern: \"^[A-Za-z]+$\",\n * minLength: 4,\n * maxLength: 20,\n * });\n *\n * return <TextField {...fieldProps} label=\"Example\" />;\n * }\n * ```\n *\n * @example Custom Validation\n * ```tsx\n * import { type ReactElement } from \"react\";\n * import { TextField } from \"@react-md/core/form/TextField\";\n * import { useTextField } from \"@react-md/core/form/useTextField\";\n *\n * function Example(): ReactElement {\n * const { fieldProps } = useTextField({\n * name: \"example\",\n * required: true,\n * getErrorMessage(options) {\n * const {\n * value,\n * pattern,\n * required,\n * minLength,\n * maxLength,\n * validity,\n * validationMessage,\n * isNumber,\n * isBlurEvent,\n * validationType,\n * } = options;\n *\n * if (validity.tooLong) {\n * return `No more than ${maxLength} characters.`;\n * }\n *\n * if (validity.tooShort) {\n * return `No more than ${minLength} characters.`;\n * }\n *\n * if (validity.valueMissing) {\n * return \"This value is required!\";\n * }\n *\n * if (value === \"bad value\") {\n * return \"Value cannot be bad value\";\n * }\n *\n * return defaultGetErrorMessage(options);\n * }\n * });\n *\n * return <TextField {...fieldProps} label=\"Example\" />;\n * }\n * ```\n *\n * @see {@link https://react-md.dev/components/text-field | TextField Demos}\n * @see {@link https://react-md.dev/hooks/use-text-field | useTextField Demos}\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation\n * @since 2.5.6\n * @since 6.0.0 This hook returns an object instead of an ordered list. Also\n * added the ability to display an inline counter and help text while disabling\n * the error messaging.\n */\nexport function useTextField<\n E extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement,\n>(options: TextFieldHookOptions<E>): TextFieldWithMessageImplementation<E>;\n/**\n * @see {@link https://react-md.dev/components/text-field | TextField Demos}\n * @see {@link https://react-md.dev/hooks/use-text-field | useTextField Demos}\n * @since 6.0.0\n */\nexport function useTextField<\n E extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement,\n>(options: TextFieldHookOptions<E>): ValidatedTextFieldImplementation<E> {\n const {\n id: propId,\n ref: propRef,\n name,\n form,\n defaultValue = \"\",\n isNumber = false,\n required,\n pattern,\n minLength,\n maxLength,\n onBlur = noop,\n onChange = noop,\n onInvalid = noop,\n counter = false,\n helpText,\n disableReset,\n validationType = \"recommended\",\n disableMessage = false,\n disableMaxLength = false,\n errorIcon: propErrorIcon,\n isErrored = defaultIsErrored,\n onErrorChange = noop,\n getErrorIcon = defaultGetErrorIcon,\n getErrorMessage = defaultGetErrorMessage,\n } = options;\n\n const id = useEnsuredId(propId, \"text-field\");\n const messageId = `${id}-message`;\n const [fieldRef, ref] = useEnsuredRef(propRef);\n const [state, setState] = useState<TextFieldHookState>(() => {\n const value =\n typeof defaultValue === \"function\" ? defaultValue() : defaultValue;\n\n return {\n value,\n error: false,\n errorMessage: \"\",\n };\n });\n const { value, error, errorMessage } = state;\n\n // using a `ref` instead of a `useCallback` makes it so the `defaultValue`\n // will always be used once reset.\n const reset = useRef(() => {\n fieldRef.current?.setCustomValidity(\"\");\n setState({ value, error: false, errorMessage: \"\" });\n }).current;\n\n const errored = useRef(error);\n const checkValidity = useCallback(\n (isBlurEvent: boolean) => {\n const field = fieldRef.current;\n if (!field) {\n throw new Error(\"Unable to check validity due to missing ref\");\n }\n\n // need to temporarily set the `maxLength` back so it can be \"verified\"\n // through the validity api\n /* istanbul ignore next */\n if (isBlurEvent && disableMaxLength && typeof maxLength === \"number\") {\n field.maxLength = maxLength;\n }\n\n const { value } = field;\n field.setCustomValidity(\"\");\n field.checkValidity();\n\n // remove the temporarily set `maxLength` attribute after checking the\n // validity\n /* istanbul ignore next */\n if (disableMaxLength && typeof maxLength === \"number\") {\n field.removeAttribute(\"maxLength\");\n }\n\n const options: ErrorMessageOptions = {\n value,\n pattern,\n required,\n minLength,\n maxLength,\n isBlurEvent,\n isNumber,\n validationType,\n validity: field.validity,\n validationMessage: field.validationMessage,\n };\n const errorMessage = getErrorMessage(options);\n const error = isErrored({ ...options, errorMessage });\n\n if (errored.current !== error) {\n errored.current = error;\n onErrorChange({\n ref: fieldRef,\n name,\n error,\n errorMessage,\n });\n }\n\n /* istanbul ignore next */\n if (errorMessage !== field.validationMessage) {\n field.setCustomValidity(errorMessage);\n }\n\n setState((prevState) => {\n if (\n prevState.value === value &&\n prevState.error === error &&\n prevState.errorMessage === errorMessage\n ) {\n return prevState;\n }\n\n return {\n value,\n error,\n errorMessage,\n };\n });\n },\n [\n disableMaxLength,\n fieldRef,\n getErrorMessage,\n isErrored,\n isNumber,\n maxLength,\n minLength,\n name,\n onErrorChange,\n pattern,\n required,\n validationType,\n ]\n );\n\n const errorIcon = getIcon(\"error\", propErrorIcon);\n const fieldProps: ProvidedTextFieldProps<E> & {\n messageProps?: ProvidedFormMessageProps;\n } = {\n id,\n ref,\n name,\n value,\n error,\n required,\n pattern,\n minLength,\n maxLength: disableMaxLength ? undefined : maxLength,\n rightAddon: getErrorIcon({\n error,\n errorIcon,\n errorMessage,\n }),\n onBlur(event) {\n onBlur(event);\n if (event.isPropagationStopped()) {\n return;\n }\n\n checkValidity(true);\n },\n onChange(event) {\n onChange(event);\n if (event.isPropagationStopped()) {\n return;\n }\n\n if (validationType === \"blur\") {\n const { value } = event.currentTarget;\n setState((prevState) => ({\n ...prevState,\n value,\n }));\n return;\n }\n\n checkValidity(false);\n },\n onInvalid(event) {\n onInvalid(event);\n if (\n event.isPropagationStopped() ||\n event.currentTarget === document.activeElement\n ) {\n return;\n }\n\n // this makes it so that if a submit button is clicked in a form, all\n // textfields will gain the error state immediately\n // also need to extract the validationMessage immediately because of the\n // SyntheticEvent behavior in React. By the time the `setState` is called,\n // the event might've been deleted\n const { validationMessage } = event.currentTarget;\n\n setState((prevState) => {\n if (prevState.error) {\n return prevState;\n }\n\n return {\n ...prevState,\n error: true,\n errorMessage: validationMessage,\n };\n });\n },\n };\n\n const isCounter = counter && typeof maxLength === \"number\";\n if (isCounter || helpText || !disableMessage) {\n fieldProps[\"aria-describedby\"] = messageId;\n fieldProps.messageProps = {\n id: messageId,\n error,\n length: counter ? value.length : undefined,\n maxLength: (counter && maxLength) || undefined,\n children: (!disableMessage && errorMessage) || helpText,\n };\n }\n\n useFormReset({\n form,\n onReset: disableReset ? undefined : reset,\n elementRef: fieldRef,\n });\n\n return {\n ...state,\n reset,\n setState,\n fieldRef,\n fieldProps,\n };\n}\n"],"names":["useCallback","useRef","useState","getIcon","useEnsuredId","useEnsuredRef","useFormReset","defaultGetErrorIcon","defaultGetErrorMessage","defaultIsErrored","noop","useTextField","options","id","propId","ref","propRef","name","form","defaultValue","isNumber","required","pattern","minLength","maxLength","onBlur","onChange","onInvalid","counter","helpText","disableReset","validationType","disableMessage","disableMaxLength","errorIcon","propErrorIcon","isErrored","onErrorChange","getErrorIcon","getErrorMessage","messageId","fieldRef","state","setState","value","error","errorMessage","reset","current","setCustomValidity","errored","checkValidity","isBlurEvent","field","Error","removeAttribute","validity","validationMessage","prevState","fieldProps","undefined","rightAddon","event","isPropagationStopped","currentTarget","document","activeElement","isCounter","messageProps","length","children","onReset","elementRef"],"mappings":"AAAA;AAEA,SAMEA,WAAW,EACXC,MAAM,EACNC,QAAQ,QACH,QAAQ;AAEf,SAASC,OAAO,QAAQ,oBAAoB;AAE5C,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,aAAa,QAAQ,sBAAsB;AAMpD,SAASC,YAAY,QAAQ,oBAAoB;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;QACpCyB,YAAY/B;IACd;IAEA,OAAO;QACL,GAAGC,KAAK;QACRK;QACAJ;QACAF;QACAkB;IACF;AACF"}
@@ -1,5 +1,19 @@
1
1
  import { type KeyboardEvent, type MouseEvent, type TouchEvent } from "react";
2
+ import { type Point } from "../types.js";
2
3
  import { type ElementInteractionState, type RippleState, type RippleStyle } from "./types.js";
4
+ /**
5
+ * @internal
6
+ * @since 6.3.0
7
+ */
8
+ interface GetRadiusOptions extends Point {
9
+ height: number;
10
+ width: number;
11
+ }
12
+ /**
13
+ * @internal
14
+ * @since 6.3.0
15
+ */
16
+ export declare function getRadius(options: GetRadiusOptions): number;
3
17
  /** @internal */
4
18
  export declare function getRippleStyle(event: MouseEvent<HTMLElement> | TouchEvent<HTMLElement> | KeyboardEvent<HTMLElement>, programmatic: boolean): RippleStyle;
5
19
  /** @internal */
@@ -1,17 +1,23 @@
1
1
  import { findSizingContainer } from "../positioning/utils.js";
2
- /** @internal */ function calcHypotenuse(a, b) {
3
- return Math.sqrt(a * a + b * b);
4
- }
2
+ import { calcHypotenuse } from "../utils/trigonometry.js";
5
3
  /**
6
- * Gets the current radius for a ripple based on the x and y page dimensions
7
- * as well as the size of the element.
8
- *
9
- * This is really just in a separate file so I can easily mock this and write
10
- * tests.
11
- *
12
4
  * @internal
13
- */ function getRadius(x, y, offsetWidth, offsetHeight) {
14
- return Math.max(calcHypotenuse(x, y), calcHypotenuse(offsetWidth - x, y), calcHypotenuse(offsetWidth - x, offsetHeight - y), calcHypotenuse(x, offsetHeight - y));
5
+ * @since 6.3.0
6
+ */ export function getRadius(options) {
7
+ const { x, y, height, width } = options;
8
+ return Math.max(calcHypotenuse({
9
+ x,
10
+ y
11
+ }), calcHypotenuse({
12
+ x: width - x,
13
+ y
14
+ }), calcHypotenuse({
15
+ x: width - x,
16
+ y: height - y
17
+ }), calcHypotenuse({
18
+ x,
19
+ y: height - y
20
+ }));
15
21
  }
16
22
  /** @internal */ export function getRippleStyle(event, programmatic) {
17
23
  const element = findSizingContainer(event.currentTarget) || event.currentTarget;
@@ -33,7 +39,12 @@ import { findSizingContainer } from "../positioning/utils.js";
33
39
  x = pageX - (left + window.scrollX);
34
40
  y = pageY - (top + window.scrollY);
35
41
  }
36
- const radius = getRadius(x, y, width, height);
42
+ const radius = getRadius({
43
+ x,
44
+ y,
45
+ width,
46
+ height
47
+ });
37
48
  const size = radius * 2;
38
49
  return {
39
50
  left: x - radius,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/interaction/utils.ts"],"sourcesContent":["import { type KeyboardEvent, type MouseEvent, type TouchEvent } from \"react\";\n\nimport { findSizingContainer } from \"../positioning/utils.js\";\nimport {\n type ElementInteractionState,\n type RippleState,\n type RippleStyle,\n} from \"./types.js\";\n\n/** @internal */\nfunction calcHypotenuse(a: number, b: number): number {\n return Math.sqrt(a * a + b * b);\n}\n\n/**\n * Gets the current radius for a ripple based on the x and y page dimensions\n * as well as the size of the element.\n *\n * This is really just in a separate file so I can easily mock this and write\n * tests.\n *\n * @internal\n */\nfunction getRadius(\n x: number,\n y: number,\n offsetWidth: number,\n offsetHeight: number\n): number {\n return Math.max(\n calcHypotenuse(x, y),\n calcHypotenuse(offsetWidth - x, y),\n calcHypotenuse(offsetWidth - x, offsetHeight - y),\n calcHypotenuse(x, offsetHeight - y)\n );\n}\n\n/** @internal */\nexport function getRippleStyle(\n event:\n | MouseEvent<HTMLElement>\n | TouchEvent<HTMLElement>\n | KeyboardEvent<HTMLElement>,\n programmatic: boolean\n): RippleStyle {\n const element =\n findSizingContainer(event.currentTarget) || event.currentTarget;\n const rect = element.getBoundingClientRect();\n const { left, top, height, width } = rect;\n\n let x: number;\n let y: number;\n if (\"key\" in event || programmatic) {\n x = width / 2;\n y = height / 2;\n } else {\n let pageX: number;\n let pageY: number;\n if (\"touches\" in event) {\n ({ pageX, pageY } = event.touches[0]);\n } else {\n ({ pageX, pageY } = event);\n }\n\n x = pageX - (left + window.scrollX);\n y = pageY - (top + window.scrollY);\n }\n\n const radius = getRadius(x, y, width, height);\n const size = radius * 2;\n\n return {\n left: x - radius,\n top: y - radius,\n height: size,\n width: size,\n };\n}\n\n/**\n * This is used to set the `exiting` state after a normal \"touch\" duration.\n * 300ms seemed like a good threshold since it is the majority of the scaling\n * duration (450ms)\n */\nconst ENTER_DELAY = 300;\n\n/** @internal */\nexport function releaseRipple(\n state: ElementInteractionState\n): ElementInteractionState {\n // find the first non-exiting ripple which should now be released\n const i = state.ripples.findIndex((ripple) => !ripple.exiting);\n if (i === -1) {\n return state;\n }\n\n const ripples = state.ripples.slice();\n const ripple = ripples[i];\n ripples[i] = {\n ...ripple,\n exiting: ripple.entered || Date.now() - ripple.startTime > ENTER_DELAY,\n };\n return { pressed: false, ripples };\n}\n\n/** @internal */\ninterface UpdateRipplesStateOptions {\n type: \"entered\" | \"exited\";\n state: ElementInteractionState;\n ripple: RippleState;\n holding: boolean;\n}\n\n/** @internal */\nexport function updateRipplesState(\n options: UpdateRipplesStateOptions\n): ElementInteractionState {\n const { type, ripple, state, holding } = options;\n\n const rippleIndex = state.ripples.findIndex((r) => r === ripple);\n if (rippleIndex === -1) {\n return state;\n }\n\n const ripples = state.ripples.slice();\n if (type === \"exited\") {\n ripples.splice(rippleIndex, 1);\n } else {\n const exiting = !holding || Date.now() - ripple.startTime > ENTER_DELAY;\n ripples[rippleIndex] = {\n ...ripple,\n exiting,\n entered: true,\n };\n }\n\n return { ...state, ripples };\n}\n"],"names":["findSizingContainer","calcHypotenuse","a","b","Math","sqrt","getRadius","x","y","offsetWidth","offsetHeight","max","getRippleStyle","event","programmatic","element","currentTarget","rect","getBoundingClientRect","left","top","height","width","pageX","pageY","touches","window","scrollX","scrollY","radius","size","ENTER_DELAY","releaseRipple","state","i","ripples","findIndex","ripple","exiting","slice","entered","Date","now","startTime","pressed","updateRipplesState","options","type","holding","rippleIndex","r","splice"],"mappings":"AAEA,SAASA,mBAAmB,QAAQ,0BAA0B;AAO9D,cAAc,GACd,SAASC,eAAeC,CAAS,EAAE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9B,iEAAiE;IACjE,MAAMC,IAAID,MAAME,OAAO,CAACC,SAAS,CAAC,CAACC,SAAW,CAACA,OAAOC,OAAO;IAC7D,IAAIJ,MAAM,CAAC,GAAG;QACZ,OAAOD;IACT;IAEA,MAAME,UAAUF,MAAME,OAAO,CAACI,KAAK;IACnC,MAAMF,SAASF,OAAO,CAACD,EAAE;IACzBC,OAAO,CAACD,EAAE,GAAG;QACX,GAAGG,MAAM;QACTC,SAASD,OAAOG,OAAO,IAAIC,KAAKC,GAAG,KAAKL,OAAOM,SAAS,GAAGZ;IAC7D;IACA,OAAO;QAAEa,SAAS;QAAOT;IAAQ;AACnC;AAUA,cAAc,GACd,OAAO,SAASU,mBACdC,OAAkC;IAElC,MAAM,EAAEC,IAAI,EAAEV,MAAM,EAAEJ,KAAK,EAAEe,OAAO,EAAE,GAAGF;IAEzC,MAAMG,cAAchB,MAAME,OAAO,CAACC,SAAS,CAAC,CAACc,IAAMA,MAAMb;IACzD,IAAIY,gBAAgB,CAAC,GAAG;QACtB,OAAOhB;IACT;IAEA,MAAME,UAAUF,MAAME,OAAO,CAACI,KAAK;IACnC,IAAIQ,SAAS,UAAU;QACrBZ,QAAQgB,MAAM,CAACF,aAAa;IAC9B,OAAO;QACL,MAAMX,UAAU,CAACU,WAAWP,KAAKC,GAAG,KAAKL,OAAOM,SAAS,GAAGZ;QAC5DI,OAAO,CAACc,YAAY,GAAG;YACrB,GAAGZ,MAAM;YACTC;YACAE,SAAS;QACX;IACF;IAEA,OAAO;QAAE,GAAGP,KAAK;QAAEE;IAAQ;AAC7B"}
1
+ {"version":3,"sources":["../../src/interaction/utils.ts"],"sourcesContent":["import { type KeyboardEvent, type MouseEvent, type TouchEvent } from \"react\";\n\nimport { findSizingContainer } from \"../positioning/utils.js\";\nimport { type Point } from \"../types.js\";\nimport { calcHypotenuse } from \"../utils/trigonometry.js\";\nimport {\n type ElementInteractionState,\n type RippleState,\n type RippleStyle,\n} from \"./types.js\";\n\n/**\n * @internal\n * @since 6.3.0\n */\ninterface GetRadiusOptions extends Point {\n height: number;\n width: number;\n}\n\n/**\n * @internal\n * @since 6.3.0\n */\nexport function getRadius(options: GetRadiusOptions): number {\n const { x, y, height, width } = options;\n\n return Math.max(\n calcHypotenuse({ x, y }),\n calcHypotenuse({ x: width - x, y }),\n calcHypotenuse({ x: width - x, y: height - y }),\n calcHypotenuse({ x, y: height - y })\n );\n}\n\n/** @internal */\nexport function getRippleStyle(\n event:\n | MouseEvent<HTMLElement>\n | TouchEvent<HTMLElement>\n | KeyboardEvent<HTMLElement>,\n programmatic: boolean\n): RippleStyle {\n const element =\n findSizingContainer(event.currentTarget) || event.currentTarget;\n const rect = element.getBoundingClientRect();\n const { left, top, height, width } = rect;\n\n let x: number;\n let y: number;\n if (\"key\" in event || programmatic) {\n x = width / 2;\n y = height / 2;\n } else {\n let pageX: number;\n let pageY: number;\n if (\"touches\" in event) {\n ({ pageX, pageY } = event.touches[0]);\n } else {\n ({ pageX, pageY } = event);\n }\n\n x = pageX - (left + window.scrollX);\n y = pageY - (top + window.scrollY);\n }\n\n const radius = getRadius({ x, y, width, height });\n const size = radius * 2;\n\n return {\n left: x - radius,\n top: y - radius,\n height: size,\n width: size,\n };\n}\n\n/**\n * This is used to set the `exiting` state after a normal \"touch\" duration.\n * 300ms seemed like a good threshold since it is the majority of the scaling\n * duration (450ms)\n */\nconst ENTER_DELAY = 300;\n\n/** @internal */\nexport function releaseRipple(\n state: ElementInteractionState\n): ElementInteractionState {\n // find the first non-exiting ripple which should now be released\n const i = state.ripples.findIndex((ripple) => !ripple.exiting);\n if (i === -1) {\n return state;\n }\n\n const ripples = state.ripples.slice();\n const ripple = ripples[i];\n ripples[i] = {\n ...ripple,\n exiting: ripple.entered || Date.now() - ripple.startTime > ENTER_DELAY,\n };\n return { pressed: false, ripples };\n}\n\n/** @internal */\ninterface UpdateRipplesStateOptions {\n type: \"entered\" | \"exited\";\n state: ElementInteractionState;\n ripple: RippleState;\n holding: boolean;\n}\n\n/** @internal */\nexport function updateRipplesState(\n options: UpdateRipplesStateOptions\n): ElementInteractionState {\n const { type, ripple, state, holding } = options;\n\n const rippleIndex = state.ripples.findIndex((r) => r === ripple);\n if (rippleIndex === -1) {\n return state;\n }\n\n const ripples = state.ripples.slice();\n if (type === \"exited\") {\n ripples.splice(rippleIndex, 1);\n } else {\n const exiting = !holding || Date.now() - ripple.startTime > ENTER_DELAY;\n ripples[rippleIndex] = {\n ...ripple,\n exiting,\n entered: true,\n };\n }\n\n return { ...state, ripples };\n}\n"],"names":["findSizingContainer","calcHypotenuse","getRadius","options","x","y","height","width","Math","max","getRippleStyle","event","programmatic","element","currentTarget","rect","getBoundingClientRect","left","top","pageX","pageY","touches","window","scrollX","scrollY","radius","size","ENTER_DELAY","releaseRipple","state","i","ripples","findIndex","ripple","exiting","slice","entered","Date","now","startTime","pressed","updateRipplesState","type","holding","rippleIndex","r","splice"],"mappings":"AAEA,SAASA,mBAAmB,QAAQ,0BAA0B;AAE9D,SAASC,cAAc,QAAQ,2BAA2B;AAgB1D;;;CAGC,GACD,OAAO,SAASC,UAAUC,OAAyB;IACjD,MAAM,EAAEC,CAAC,EAAEC,CAAC,EAAEC,MAAM,EAAEC,KAAK,EAAE,GAAGJ;IAEhC,OAAOK,KAAKC,GAAG,CACbR,eAAe;QAAEG;QAAGC;IAAE,IACtBJ,eAAe;QAAEG,GAAGG,QAAQH;QAAGC;IAAE,IACjCJ,eAAe;QAAEG,GAAGG,QAAQH;QAAGC,GAAGC,SAASD;IAAE,IAC7CJ,eAAe;QAAEG;QAAGC,GAAGC,SAASD;IAAE;AAEtC;AAEA,cAAc,GACd,OAAO,SAASK,eACdC,KAG8B,EAC9BC,YAAqB;IAErB,MAAMC,UACJb,oBAAoBW,MAAMG,aAAa,KAAKH,MAAMG,aAAa;IACjE,MAAMC,OAAOF,QAAQG,qBAAqB;IAC1C,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAEZ,MAAM,EAAEC,KAAK,EAAE,GAAGQ;I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C,MAAMyC,cAAcf,MAAME,OAAO,CAACC,SAAS,CAAC,CAACa,IAAMA,MAAMZ;IACzD,IAAIW,gBAAgB,CAAC,GAAG;QACtB,OAAOf;IACT;IAEA,MAAME,UAAUF,MAAME,OAAO,CAACI,KAAK;IACnC,IAAIO,SAAS,UAAU;QACrBX,QAAQe,MAAM,CAACF,aAAa;IAC9B,OAAO;QACL,MAAMV,UAAU,CAACS,WAAWN,KAAKC,GAAG,KAAKL,OAAOM,SAAS,GAAGZ;QAC5DI,OAAO,CAACa,YAAY,GAAG;YACrB,GAAGX,MAAM;YACTC;YACAE,SAAS;QACX;IACF;IAEA,OAAO;QAAE,GAAGP,KAAK;QAAEE;IAAQ;AAC7B"}
@@ -49,6 +49,7 @@ import { MenuBarProvider, useMenuBarProvider } from "./useMenuBarProvider.js";
49
49
  });
50
50
  const { activeId, enableHoverMode } = menuBarContext;
51
51
  const { movementProps, movementContext } = useKeyboardMovementProvider({
52
+ ref,
52
53
  onClick,
53
54
  onFocus,
54
55
  onKeyDown,
@@ -70,7 +71,6 @@ import { MenuBarProvider, useMenuBarProvider } from "./useMenuBarProvider.js";
70
71
  children: /*#__PURE__*/ _jsx(List, {
71
72
  ...remaining,
72
73
  ...movementProps,
73
- ref: ref,
74
74
  role: "menubar",
75
75
  horizontal: horizontal,
76
76
  children: children
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/menu/MenuBar.tsx"],"sourcesContent":["\"use client\";\n\nimport { forwardRef } from \"react\";\n\nimport { List, type ListProps } from \"../list/List.js\";\nimport {\n KeyboardMovementProvider,\n useKeyboardMovementProvider,\n} from \"../movement/useKeyboardMovementProvider.js\";\nimport { MenuBarProvider, useMenuBarProvider } from \"./useMenuBarProvider.js\";\n\nexport interface MenuBarProps extends Omit<ListProps, \"role\"> {\n /**\n * @defaultValue `true`\n */\n horizontal?: boolean;\n\n /**\n * Set this to a number greater than 0 to allow opening dropdown menus within\n * the menubar after hovering for the duration in milliseconds. Once a menu\n * becomes visible within the menubar, all subsequent menus will become\n * visible immediately on hover as well until the hover mode is ended.\n *\n * For example:\n *\n * - `0` - the dropdown menus become visible immediately on hover\n * - `1000` - the first dropdown menu becomes visible after hovering for 1\n * second\n * - `undefined` - the hover mode can only be activate after a click with\n * mouse, touch, or keyboard\n *\n * @defaultValue `undefined`\n */\n hoverTimeout?: number;\n}\n\n/**\n * **Client Component**\n *\n * @example Simple Example\n * ```tsx\n * import { DropdownMenu } from \"@react-md/core/menu/DropdownMenu\";\n * import { MenuBar } from \"@react-md/core/menu/MenuBar\";\n * import { MenuItem } from \"@react-md/core/menu/MenuItem\";\n * import type { ReactElement } from \"react\";\n *\n * export function SimpleExample(): ReactElement {\n * return (\n * <MenuBar>\n * <DropdownMenu buttonChildren=\"Item 1\">\n * <MenuItem>Menu Item 1</MenuItem>\n * <MenuItem>Menu Item 2</MenuItem>\n * <MenuItem>Menu Item 3</MenuItem>\n * </DropdownMenu>\n * <DropdownMenu buttonChildren=\"Item 2\">\n * <MenuItem>Menu Item 1</MenuItem>\n * <MenuItem>Menu Item 2</MenuItem>\n * <MenuItem>Menu Item 3</MenuItem>\n * </DropdownMenu>\n * <DropdownMenu buttonChildren=\"Item 3\">\n * <MenuItem>Menu Item 1</MenuItem>\n * <MenuItem>Menu Item 2</MenuItem>\n * <MenuItem>Menu Item 4</MenuItem>\n * </DropdownMenu>\n * </MenuBar>\n * );\n * }\n * ```\n *\n * @see {@link https://react-md.dev/components/menu | Menu Demos}\n * @since 5.0.0\n * @since 6.0.0 Combined with the previous `MenuBarWidget`\n */\nexport const MenuBar = forwardRef<HTMLUListElement, MenuBarProps>(\n function MenuBar(props, ref) {\n const {\n onClick,\n onFocus,\n onKeyDown,\n horizontal = true,\n hoverTimeout,\n children,\n ...remaining\n } = props;\n const menuBarContext = useMenuBarProvider({\n root: true,\n menubar: true,\n hoverTimeout,\n });\n const { activeId, enableHoverMode } = menuBarContext;\n const { movementProps, movementContext } = useKeyboardMovementProvider({\n onClick,\n onFocus,\n onKeyDown,\n loopable: true,\n searchable: true,\n horizontal,\n includeDisabled: true,\n tabIndexBehavior: \"roving\",\n onFocusChange(event) {\n if (activeId) {\n enableHoverMode(event.element.id);\n }\n },\n });\n\n return (\n <KeyboardMovementProvider value={movementContext}>\n <MenuBarProvider value={menuBarContext}>\n <List\n {...remaining}\n {...movementProps}\n ref={ref}\n role=\"menubar\"\n horizontal={horizontal}\n >\n {children}\n </List>\n </MenuBarProvider>\n </KeyboardMovementProvider>\n );\n }\n);\n"],"names":["forwardRef","List","KeyboardMovementProvider","useKeyboardMovementProvider","MenuBarProvider","useMenuBarProvider","MenuBar","props","ref","onClick","onFocus","onKeyDown","horizontal","hoverTimeout","children","remaining","menuBarContext","root","menubar","activeId","enableHoverMode","movementProps","movementContext","loopable","searchable","includeDisabled","tabIndexBehavior","onFocusChange","event","element","id","value","role"],"mappings":"AAAA;;AAEA,SAASA,UAAU,QAAQ,QAAQ;AAEnC,SAASC,IAAI,QAAwB,kBAAkB;AACvD,SACEC,wBAAwB,EACxBC,2BAA2B,QACtB,6CAA6C;AACpD,SAASC,eAAe,EAAEC,kBAAkB,QAAQ,0BAA0B;AA2B9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCC,GACD,OAAO,MAAMC,wBAAUN,WACrB,SAASM,QAAQC,KAAK,EAAEC,GAAG;IACzB,MAAM,EACJC,OAAO,EACPC,OAAO,EACPC,SAAS,EACTC,aAAa,IAAI,EACjBC,YAAY,EACZC,QAAQ,EACR,GAAGC,WACJ,GAAGR;IACJ,MAAMS,iBAAiBX,mBAAmB;QACxCY,MAAM;QACNC,SAAS;QACTL;IACF;IACA,MAAM,EAAEM,QAAQ,EAAEC,eAAe,EAAE,GAAGJ;IACtC,MAAM,EAAEK,aAAa,EAAEC,eAAe,EAAE,GAAGnB,4BAA4B;QACrEM;QACAC;QACAC;QACAY,UAAU;QACVC,YAAY;QACZZ;QACAa,iBAAiB;QACjBC,kBAAkB;QAClBC,eAAcC,KAAK;YACjB,IAAIT,UAAU;gBACZC,gBAAgBQ,MAAMC,OAAO,CAACC,EAAE;YAClC;QACF;IACF;IAEA,qBACE,KAAC5B;QAAyB6B,OAAOT;kBAC/B,cAAA,KAAClB;YAAgB2B,OAAOf;sBACtB,cAAA,KAACf;gBACE,GAAGc,SAAS;gBACZ,GAAGM,aAAa;gBACjBb,KAAKA;gBACLwB,MAAK;gBACLpB,YAAYA;0BAEXE;;;;AAKX,GACA"}
1
+ {"version":3,"sources":["../../src/menu/MenuBar.tsx"],"sourcesContent":["\"use client\";\n\nimport { forwardRef } from \"react\";\n\nimport { List, type ListProps } from \"../list/List.js\";\nimport {\n KeyboardMovementProvider,\n useKeyboardMovementProvider,\n} from \"../movement/useKeyboardMovementProvider.js\";\nimport { MenuBarProvider, useMenuBarProvider } from \"./useMenuBarProvider.js\";\n\nexport interface MenuBarProps extends Omit<ListProps, \"role\"> {\n /**\n * @defaultValue `true`\n */\n horizontal?: boolean;\n\n /**\n * Set this to a number greater than 0 to allow opening dropdown menus within\n * the menubar after hovering for the duration in milliseconds. Once a menu\n * becomes visible within the menubar, all subsequent menus will become\n * visible immediately on hover as well until the hover mode is ended.\n *\n * For example:\n *\n * - `0` - the dropdown menus become visible immediately on hover\n * - `1000` - the first dropdown menu becomes visible after hovering for 1\n * second\n * - `undefined` - the hover mode can only be activate after a click with\n * mouse, touch, or keyboard\n *\n * @defaultValue `undefined`\n */\n hoverTimeout?: number;\n}\n\n/**\n * **Client Component**\n *\n * @example Simple Example\n * ```tsx\n * import { DropdownMenu } from \"@react-md/core/menu/DropdownMenu\";\n * import { MenuBar } from \"@react-md/core/menu/MenuBar\";\n * import { MenuItem } from \"@react-md/core/menu/MenuItem\";\n * import type { ReactElement } from \"react\";\n *\n * export function SimpleExample(): ReactElement {\n * return (\n * <MenuBar>\n * <DropdownMenu buttonChildren=\"Item 1\">\n * <MenuItem>Menu Item 1</MenuItem>\n * <MenuItem>Menu Item 2</MenuItem>\n * <MenuItem>Menu Item 3</MenuItem>\n * </DropdownMenu>\n * <DropdownMenu buttonChildren=\"Item 2\">\n * <MenuItem>Menu Item 1</MenuItem>\n * <MenuItem>Menu Item 2</MenuItem>\n * <MenuItem>Menu Item 3</MenuItem>\n * </DropdownMenu>\n * <DropdownMenu buttonChildren=\"Item 3\">\n * <MenuItem>Menu Item 1</MenuItem>\n * <MenuItem>Menu Item 2</MenuItem>\n * <MenuItem>Menu Item 4</MenuItem>\n * </DropdownMenu>\n * </MenuBar>\n * );\n * }\n * ```\n *\n * @see {@link https://react-md.dev/components/menu | Menu Demos}\n * @since 5.0.0\n * @since 6.0.0 Combined with the previous `MenuBarWidget`\n */\nexport const MenuBar = forwardRef<HTMLUListElement, MenuBarProps>(\n function MenuBar(props, ref) {\n const {\n onClick,\n onFocus,\n onKeyDown,\n horizontal = true,\n hoverTimeout,\n children,\n ...remaining\n } = props;\n const menuBarContext = useMenuBarProvider({\n root: true,\n menubar: true,\n hoverTimeout,\n });\n const { activeId, enableHoverMode } = menuBarContext;\n const { movementProps, movementContext } = useKeyboardMovementProvider({\n ref,\n onClick,\n onFocus,\n onKeyDown,\n loopable: true,\n searchable: true,\n horizontal,\n includeDisabled: true,\n tabIndexBehavior: \"roving\",\n onFocusChange(event) {\n if (activeId) {\n enableHoverMode(event.element.id);\n }\n },\n });\n\n return (\n <KeyboardMovementProvider value={movementContext}>\n <MenuBarProvider value={menuBarContext}>\n <List\n {...remaining}\n {...movementProps}\n role=\"menubar\"\n horizontal={horizontal}\n >\n {children}\n </List>\n </MenuBarProvider>\n </KeyboardMovementProvider>\n );\n }\n);\n"],"names":["forwardRef","List","KeyboardMovementProvider","useKeyboardMovementProvider","MenuBarProvider","useMenuBarProvider","MenuBar","props","ref","onClick","onFocus","onKeyDown","horizontal","hoverTimeout","children","remaining","menuBarContext","root","menubar","activeId","enableHoverMode","movementProps","movementContext","loopable","searchable","includeDisabled","tabIndexBehavior","onFocusChange","event","element","id","value","role"],"mappings":"AAAA;;AAEA,SAASA,UAAU,QAAQ,QAAQ;AAEnC,SAASC,IAAI,QAAwB,kBAAkB;AACvD,SACEC,wBAAwB,EACxBC,2BAA2B,QACtB,6CAA6C;AACpD,SAASC,eAAe,EAAEC,kBAAkB,QAAQ,0BAA0B;AA2B9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCC,GACD,OAAO,MAAMC,wBAAUN,WACrB,SAASM,QAAQC,KAAK,EAAEC,GAAG;IACzB,MAAM,EACJC,OAAO,EACPC,OAAO,EACPC,SAAS,EACTC,aAAa,IAAI,EACjBC,YAAY,EACZC,QAAQ,EACR,GAAGC,WACJ,GAAGR;IACJ,MAAMS,iBAAiBX,mBAAmB;QACxCY,MAAM;QACNC,SAAS;QACTL;IACF;IACA,MAAM,EAAEM,QAAQ,EAAEC,eAAe,EAAE,GAAGJ;IACtC,MAAM,EAAEK,aAAa,EAAEC,eAAe,EAAE,GAAGnB,4BAA4B;QACrEK;QACAC;QACAC;QACAC;QACAY,UAAU;QACVC,YAAY;QACZZ;QACAa,iBAAiB;QACjBC,kBAAkB;QAClBC,eAAcC,KAAK;YACjB,IAAIT,UAAU;gBACZC,gBAAgBQ,MAAMC,OAAO,CAACC,EAAE;YAClC;QACF;IACF;IAEA,qBACE,KAAC5B;QAAyB6B,OAAOT;kBAC/B,cAAA,KAAClB;YAAgB2B,OAAOf;sBACtB,cAAA,KAACf;gBACE,GAAGc,SAAS;gBACZ,GAAGM,aAAa;gBACjBW,MAAK;gBACLpB,YAAYA;0BAEXE;;;;AAKX,GACA"}
@@ -3,14 +3,13 @@ import { type TextFieldProps } from "../form/TextField.js";
3
3
  import { type PropsWithRef } from "../types.js";
4
4
  /**
5
5
  * @since 5.0.0
6
+ * @since 6.3.0 Removed the invalid `stretch` prop
6
7
  */
7
8
  export interface MenuItemTextFieldProps extends TextFieldProps {
8
9
  /**
9
10
  * Any additional props or a `ref` to apply to the surrounding `<li>` element.
10
11
  */
11
12
  liProps?: PropsWithRef<HTMLAttributes<HTMLLIElement>>;
12
- /** @defaultValue `true` */
13
- stretch?: boolean;
14
13
  }
15
14
  /**
16
15
  * **Client Component**
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/menu/MenuItemTextField.tsx"],"sourcesContent":["\"use client\";\n\nimport { cnb } from \"cnbuilder\";\nimport { type HTMLAttributes, forwardRef } from \"react\";\n\nimport { TextField, type TextFieldProps } from \"../form/TextField.js\";\nimport { type PropsWithRef } from \"../types.js\";\n\n/**\n * @since 5.0.0\n */\nexport interface MenuItemTextFieldProps extends TextFieldProps {\n /**\n * Any additional props or a `ref` to apply to the surrounding `<li>` element.\n */\n liProps?: PropsWithRef<HTMLAttributes<HTMLLIElement>>;\n\n /** @defaultValue `true` */\n stretch?: boolean;\n}\n\n/**\n * **Client Component**\n *\n * This is a wrapper for the `TextField` component that can be used within\n * `Menu`s by updating the `onKeyDown` and `onClick` behavior.\n *\n * Note: This is **not** the `TextFieldWithMessage` since the message part is\n * hard to style nicely within menus. You'd most likely want to use another menu\n * for displaying errors.\n *\n * @see {@link https://react-md.dev/components/menu#menuitemtextfield-example | DropdownMenu Demos}\n * @since 5.0.0\n */\nexport const MenuItemTextField = forwardRef<\n HTMLInputElement,\n MenuItemTextFieldProps\n>(function MenuItemTextField(props, ref) {\n const { liProps, onKeyDown, ...remaining } = props;\n return (\n <li\n role=\"none\"\n {...liProps}\n onClick={(event) => {\n liProps?.onClick?.(event);\n event.stopPropagation();\n }}\n className={cnb(\"rmd-list-item rmd-menu-item\", liProps?.className)}\n >\n <TextField\n {...remaining}\n ref={ref}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n switch (event.key) {\n case \"Tab\":\n case \"Escape\":\n case \" \":\n // do default behavior\n break;\n default:\n if (event.key.length === 1 || event.currentTarget.value) {\n event.stopPropagation();\n }\n }\n }}\n />\n </li>\n );\n});\n"],"names":["cnb","forwardRef","TextField","MenuItemTextField","props","ref","liProps","onKeyDown","remaining","li","role","onClick","event","stopPropagation","className","key","length","currentTarget","value"],"mappings":"AAAA;;AAEA,SAASA,GAAG,QAAQ,YAAY;AAChC,SAA8BC,UAAU,QAAQ,QAAQ;AAExD,SAASC,SAAS,QAA6B,uBAAuB;AAgBtE;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,kCAAoBF,WAG/B,SAASE,kBAAkBC,KAAK,EAAEC,GAAG;IACrC,MAAM,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGC,WAAW,GAAGJ;IAC7C,qBACE,KAACK;QACCC,MAAK;QACJ,GAAGJ,OAAO;QACXK,SAAS,CAACC;YACRN,SAASK,UAAUC;YACnBA,MAAMC,eAAe;QACvB;QACAC,WAAWd,IAAI,+BAA+BM,SAASQ;kBAEvD,cAAA,KAACZ;YACE,GAAGM,SAAS;YACbH,KAAKA;YACLE,WAAW,CAACK;gBACVL,YAAYK;gBACZ,OAAQA,MAAMG,GAAG;oBACf,KAAK;oBACL,KAAK;oBACL,KAAK;wBAEH;oBACF;wBACE,IAAIH,MAAMG,GAAG,CAACC,MAAM,KAAK,KAAKJ,MAAMK,aAAa,CAACC,KAAK,EAAE;4BACvDN,MAAMC,eAAe;wBACvB;gBACJ;YACF;;;AAIR,GAAG"}
1
+ {"version":3,"sources":["../../src/menu/MenuItemTextField.tsx"],"sourcesContent":["\"use client\";\n\nimport { cnb } from \"cnbuilder\";\nimport { type HTMLAttributes, forwardRef } from \"react\";\n\nimport { TextField, type TextFieldProps } from \"../form/TextField.js\";\nimport { type PropsWithRef } from \"../types.js\";\n\n/**\n * @since 5.0.0\n * @since 6.3.0 Removed the invalid `stretch` prop\n */\nexport interface MenuItemTextFieldProps extends TextFieldProps {\n /**\n * Any additional props or a `ref` to apply to the surrounding `<li>` element.\n */\n liProps?: PropsWithRef<HTMLAttributes<HTMLLIElement>>;\n}\n\n/**\n * **Client Component**\n *\n * This is a wrapper for the `TextField` component that can be used within\n * `Menu`s by updating the `onKeyDown` and `onClick` behavior.\n *\n * Note: This is **not** the `TextFieldWithMessage` since the message part is\n * hard to style nicely within menus. You'd most likely want to use another menu\n * for displaying errors.\n *\n * @see {@link https://react-md.dev/components/menu#menuitemtextfield-example | DropdownMenu Demos}\n * @since 5.0.0\n */\nexport const MenuItemTextField = forwardRef<\n HTMLInputElement,\n MenuItemTextFieldProps\n>(function MenuItemTextField(props, ref) {\n const { liProps, onKeyDown, ...remaining } = props;\n return (\n <li\n role=\"none\"\n {...liProps}\n onClick={(event) => {\n liProps?.onClick?.(event);\n event.stopPropagation();\n }}\n className={cnb(\"rmd-list-item rmd-menu-item\", liProps?.className)}\n >\n <TextField\n {...remaining}\n ref={ref}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n switch (event.key) {\n case \"Tab\":\n case \"Escape\":\n case \" \":\n // do default behavior\n break;\n default:\n if (event.key.length === 1 || event.currentTarget.value) {\n event.stopPropagation();\n }\n }\n }}\n />\n </li>\n );\n});\n"],"names":["cnb","forwardRef","TextField","MenuItemTextField","props","ref","liProps","onKeyDown","remaining","li","role","onClick","event","stopPropagation","className","key","length","currentTarget","value"],"mappings":"AAAA;;AAEA,SAASA,GAAG,QAAQ,YAAY;AAChC,SAA8BC,UAAU,QAAQ,QAAQ;AAExD,SAASC,SAAS,QAA6B,uBAAuB;AActE;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,kCAAoBF,WAG/B,SAASE,kBAAkBC,KAAK,EAAEC,GAAG;IACrC,MAAM,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGC,WAAW,GAAGJ;IAC7C,qBACE,KAACK;QACCC,MAAK;QACJ,GAAGJ,OAAO;QACXK,SAAS,CAACC;YACRN,SAASK,UAAUC;YACnBA,MAAMC,eAAe;QACvB;QACAC,WAAWd,IAAI,+BAA+BM,SAASQ;kBAEvD,cAAA,KAACZ;YACE,GAAGM,SAAS;YACbH,KAAKA;YACLE,WAAW,CAACK;gBACVL,YAAYK;gBACZ,OAAQA,MAAMG,GAAG;oBACf,KAAK;oBACL,KAAK;oBACL,KAAK;wBAEH;oBACF;wBACE,IAAIH,MAAMG,GAAG,CAACC,MAAM,KAAK,KAAKJ,MAAMK,aAAa,CAACC,KAAK,EAAE;4BACvDN,MAAMC,eAAe;wBACvB;gBACJ;YACF;;;AAIR,GAAG"}
@@ -39,6 +39,7 @@ const noop = ()=>{
39
39
  defaultActiveId: id
40
40
  });
41
41
  const { movementProps, movementContext } = useKeyboardMovementProvider({
42
+ ref,
42
43
  onClick,
43
44
  onFocus (event) {
44
45
  onFocus(event);
@@ -67,10 +68,10 @@ const noop = ()=>{
67
68
  ...isListbox ? {
68
69
  onClick,
69
70
  onFocus,
70
- onKeyDown
71
+ onKeyDown,
72
+ ref
71
73
  } : movementProps,
72
74
  id: id,
73
- ref: ref,
74
75
  role: role,
75
76
  className: menu({
76
77
  className,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/menu/MenuWidget.tsx"],"sourcesContent":["\"use client\";\n\nimport { type HTMLAttributes, forwardRef, useRef, useState } from \"react\";\n\nimport { List } from \"../list/List.js\";\nimport { type GetDefaultFocusedIndex } from \"../movement/types.js\";\nimport { useKeyboardMovementProvider } from \"../movement/useKeyboardMovementProvider.js\";\nimport { type NonNullMutableRef } from \"../types.js\";\nimport { type MenuListConvenienceProps } from \"./Menu.js\";\nimport { MenuWidgetKeyboardProvider } from \"./MenuWidgetKeyboardProvider.js\";\nimport { menu } from \"./styles.js\";\nimport {\n MenuBarProvider,\n useMenuBarContext,\n useMenuBarProvider,\n} from \"./useMenuBarProvider.js\";\n\nconst noop = (): void => {\n // do nothing\n};\n\n/**\n * @internal\n */\nexport interface MenuWidgetProps\n extends HTMLAttributes<HTMLDivElement>,\n MenuListConvenienceProps {\n isSheet: boolean;\n horizontal: boolean;\n disableElevation?: boolean;\n cancelUnmountFocus: NonNullMutableRef<boolean>;\n getDefaultFocusedIndex?: GetDefaultFocusedIndex;\n}\n\n/**\n * **Client Component**\n *\n * This component was added to support the listbox role and the `useId()` hook.\n * If the `temporary` prop is set, the `MenuItem`'s ids will not be the same the\n * next time the menu opens, so the aria-activedescendant will point to a\n * non-existing id\n *\n * @internal\n */\nexport const MenuWidget = forwardRef<HTMLDivElement, MenuWidgetProps>(\n function MenuWidget(props, ref) {\n const {\n id,\n role = \"menu\",\n className,\n listStyle,\n listClassName,\n listProps,\n children,\n onClick,\n onBlur = noop,\n onFocus = noop,\n onKeyDown = noop,\n tabIndex = -1,\n isSheet,\n horizontal,\n disableElevation,\n cancelUnmountFocus,\n getDefaultFocusedIndex,\n ...remaining\n } = props;\n const isListbox = role === \"listbox\";\n const { menubar } = useMenuBarContext();\n\n // Since there is the possibility of other tab focusable elements within the\n // sheet and the menu items are programmatically focused, the menu's\n // tabIndex needs to be set to `-1` while one of the child menu items are\n // focused. This allows Shift+Tab correctly focuses the previous focusable\n // element within the sheet. Since `onFocus` and `onBlur` will be bubbled up\n // to the menu widget each time a new MenuItem is focused, only disable the\n // focused state if the blur event is fired without another focus event\n // within an animation frame.\n const [sheetMenuFocused, setSheetMenuFocused] = useState(false);\n const sheetBlurredFame = useRef(0);\n const menuBarContext = useMenuBarProvider({\n root: false,\n menubar,\n hoverTimeout: menubar ? 0 : undefined,\n defaultActiveId: id,\n });\n const { movementProps, movementContext } = useKeyboardMovementProvider({\n onClick,\n onFocus(event) {\n onFocus(event);\n\n if (!isSheet) {\n return;\n }\n\n window.cancelAnimationFrame(sheetBlurredFame.current);\n setSheetMenuFocused(true);\n },\n onKeyDown,\n horizontal,\n loopable: true,\n searchable: true,\n programmatic: true,\n includeDisabled: true,\n getDefaultFocusedIndex,\n });\n\n return (\n <MenuWidgetKeyboardProvider disabled={isListbox} value={movementContext}>\n <MenuBarProvider value={menuBarContext}>\n <div\n aria-orientation={horizontal ? \"horizontal\" : undefined}\n {...remaining}\n {...(isListbox ? { onClick, onFocus, onKeyDown } : movementProps)}\n id={id}\n ref={ref}\n role={role}\n className={menu({\n className,\n elevated: !disableElevation && !isSheet,\n horizontal,\n })}\n tabIndex={isSheet && !sheetMenuFocused ? 0 : tabIndex}\n onBlur={(event) => {\n onBlur(event);\n if (!isSheet) {\n return;\n }\n\n sheetBlurredFame.current = window.requestAnimationFrame(() => {\n setSheetMenuFocused(false);\n });\n }}\n >\n <List\n {...listProps}\n style={listStyle ?? listProps?.style}\n className={listClassName || listProps?.className}\n horizontal={horizontal}\n onClick={(event) => {\n listProps?.onClick?.(event);\n\n // this makes it so you can click on the menu/list without\n // closing the menu\n if (event.target === event.currentTarget) {\n event.stopPropagation();\n }\n\n // This might be a test only workaround since clicking links move focus\n // somewhere else\n if (event.target instanceof HTMLElement) {\n cancelUnmountFocus.current = event.currentTarget.contains(\n event.target.closest(\"a\")\n );\n }\n }}\n >\n {children}\n </List>\n </div>\n </MenuBarProvider>\n </MenuWidgetKeyboardProvider>\n );\n }\n);\n"],"names":["forwardRef","useRef","useState","List","useKeyboardMovementProvider","MenuWidgetKeyboardProvider","menu","MenuBarProvider","useMenuBarContext","useMenuBarProvider","noop","MenuWidget","props","ref","id","role","className","listStyle","listClassName","listProps","children","onClick","onBlur","onFocus","onKeyDown","tabIndex","isSheet","horizontal","disableElevation","cancelUnmountFocus","getDefaultFocusedIndex","remaining","isListbox","menubar","sheetMenuFocused","setSheetMenuFocused","sheetBlurredFame","menuBarContext","root","hoverTimeout","undefined","defaultActiveId","movementProps","movementContext","event","window","cancelAnimationFrame","current","loopable","searchable","programmatic","includeDisabled","disabled","value","div","aria-orientation","elevated","requestAnimationFrame","style","target","currentTarget","stopPropagation","HTMLElement","contains","closest"],"mappings":"AAAA;;AAEA,SAA8BA,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAE1E,SAASC,IAAI,QAAQ,kBAAkB;AAEvC,SAASC,2BAA2B,QAAQ,6CAA6C;AAGzF,SAASC,0BAA0B,QAAQ,kCAAkC;AAC7E,SAASC,IAAI,QAAQ,cAAc;AACnC,SACEC,eAAe,EACfC,iBAAiB,EACjBC,kBAAkB,QACb,0BAA0B;AAEjC,MAAMC,OAAO;AACX,aAAa;AACf;AAeA;;;;;;;;;C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ASE;oBAASC;gBAAU,IAAIkB,aAAa;gBAChE5B,IAAIA;gBACJD,KAAKA;gBACLE,MAAMA;gBACNC,WAAWV,KAAK;oBACdU;oBACAwC,UAAU,CAAC5B,oBAAoB,CAACF;oBAChCC;gBACF;gBACAF,UAAUC,WAAW,CAACQ,mBAAmB,IAAIT;gBAC7CH,QAAQ,CAACsB;oBACPtB,OAAOsB;oBACP,IAAI,CAAClB,SAAS;wBACZ;oBACF;oBAEAU,iBAAiBW,OAAO,GAAGF,OAAOY,qBAAqB,CAAC;wBACtDtB,oBAAoB;oBACtB;gBACF;0BAEA,cAAA,KAAChC;oBACE,GAAGgB,SAAS;oBACbuC,OAAOzC,aAAaE,WAAWuC;oBAC/B1C,WAAWE,iBAAiBC,WAAWH;oBACvCW,YAAYA;oBACZN,SAAS,CAACuB;wBACRzB,WAAWE,UAAUuB;wBAErB,0DAA0D;wBAC1D,mBAAmB;wBACnB,IAAIA,MAAMe,MAAM,KAAKf,MAAMgB,aAAa,EAAE;4BACxChB,MAAMiB,eAAe;wBACvB;wBAEA,uEAAuE;wBACvE,iBAAiB;wBACjB,IAAIjB,MAAMe,MAAM,YAAYG,aAAa;4BACvCjC,mBAAmBkB,OAAO,GAAGH,MAAMgB,aAAa,CAACG,QAAQ,CACvDnB,MAAMe,MAAM,CAACK,OAAO,CAAC;wBAEzB;oBACF;8BAEC5C;;;;;AAMb,GACA"}
1
+ {"version":3,"sources":["../../src/menu/MenuWidget.tsx"],"sourcesContent":["\"use client\";\n\nimport { type HTMLAttributes, forwardRef, useRef, useState } from \"react\";\n\nimport { List } from \"../list/List.js\";\nimport { type GetDefaultFocusedIndex } from \"../movement/types.js\";\nimport { useKeyboardMovementProvider } from \"../movement/useKeyboardMovementProvider.js\";\nimport { type NonNullMutableRef } from \"../types.js\";\nimport { type MenuListConvenienceProps } from \"./Menu.js\";\nimport { MenuWidgetKeyboardProvider } from \"./MenuWidgetKeyboardProvider.js\";\nimport { menu } from \"./styles.js\";\nimport {\n MenuBarProvider,\n useMenuBarContext,\n useMenuBarProvider,\n} from \"./useMenuBarProvider.js\";\n\nconst noop = (): void => {\n // do nothing\n};\n\n/**\n * @internal\n */\nexport interface MenuWidgetProps\n extends HTMLAttributes<HTMLDivElement>,\n MenuListConvenienceProps {\n isSheet: boolean;\n horizontal: boolean;\n disableElevation?: boolean;\n cancelUnmountFocus: NonNullMutableRef<boolean>;\n getDefaultFocusedIndex?: GetDefaultFocusedIndex;\n}\n\n/**\n * **Client Component**\n *\n * This component was added to support the listbox role and the `useId()` hook.\n * If the `temporary` prop is set, the `MenuItem`'s ids will not be the same the\n * next time the menu opens, so the aria-activedescendant will point to a\n * non-existing id\n *\n * @internal\n */\nexport const MenuWidget = forwardRef<HTMLDivElement, MenuWidgetProps>(\n function MenuWidget(props, ref) {\n const {\n id,\n role = \"menu\",\n className,\n listStyle,\n listClassName,\n listProps,\n children,\n onClick,\n onBlur = noop,\n onFocus = noop,\n onKeyDown = noop,\n tabIndex = -1,\n isSheet,\n horizontal,\n disableElevation,\n cancelUnmountFocus,\n getDefaultFocusedIndex,\n ...remaining\n } = props;\n const isListbox = role === \"listbox\";\n const { menubar } = useMenuBarContext();\n\n // Since there is the possibility of other tab focusable elements within the\n // sheet and the menu items are programmatically focused, the menu's\n // tabIndex needs to be set to `-1` while one of the child menu items are\n // focused. This allows Shift+Tab correctly focuses the previous focusable\n // element within the sheet. Since `onFocus` and `onBlur` will be bubbled up\n // to the menu widget each time a new MenuItem is focused, only disable the\n // focused state if the blur event is fired without another focus event\n // within an animation frame.\n const [sheetMenuFocused, setSheetMenuFocused] = useState(false);\n const sheetBlurredFame = useRef(0);\n const menuBarContext = useMenuBarProvider({\n root: false,\n menubar,\n hoverTimeout: menubar ? 0 : undefined,\n defaultActiveId: id,\n });\n const { movementProps, movementContext } = useKeyboardMovementProvider({\n ref,\n onClick,\n onFocus(event) {\n onFocus(event);\n\n if (!isSheet) {\n return;\n }\n\n window.cancelAnimationFrame(sheetBlurredFame.current);\n setSheetMenuFocused(true);\n },\n onKeyDown,\n horizontal,\n loopable: true,\n searchable: true,\n programmatic: true,\n includeDisabled: true,\n getDefaultFocusedIndex,\n });\n\n return (\n <MenuWidgetKeyboardProvider disabled={isListbox} value={movementContext}>\n <MenuBarProvider value={menuBarContext}>\n <div\n aria-orientation={horizontal ? \"horizontal\" : undefined}\n {...remaining}\n {...(isListbox\n ? { onClick, onFocus, onKeyDown, ref }\n : movementProps)}\n id={id}\n role={role}\n className={menu({\n className,\n elevated: !disableElevation && !isSheet,\n horizontal,\n })}\n tabIndex={isSheet && !sheetMenuFocused ? 0 : tabIndex}\n onBlur={(event) => {\n onBlur(event);\n if (!isSheet) {\n return;\n }\n\n sheetBlurredFame.current = window.requestAnimationFrame(() => {\n setSheetMenuFocused(false);\n });\n }}\n >\n <List\n {...listProps}\n style={listStyle ?? listProps?.style}\n className={listClassName || listProps?.className}\n horizontal={horizontal}\n onClick={(event) => {\n listProps?.onClick?.(event);\n\n // this makes it so you can click on the menu/list without\n // closing the menu\n if (event.target === event.currentTarget) {\n event.stopPropagation();\n }\n\n // This might be a test only workaround since clicking links move focus\n // somewhere else\n if (event.target instanceof HTMLElement) {\n cancelUnmountFocus.current = event.currentTarget.contains(\n event.target.closest(\"a\")\n );\n }\n }}\n >\n {children}\n </List>\n </div>\n </MenuBarProvider>\n </MenuWidgetKeyboardProvider>\n );\n }\n);\n"],"names":["forwardRef","useRef","useState","List","useKeyboardMovementProvider","MenuWidgetKeyboardProvider","menu","MenuBarProvider","useMenuBarContext","useMenuBarProvider","noop","MenuWidget","props","ref","id","role","className","listStyle","listClassName","listProps","children","onClick","onBlur","onFocus","onKeyDown","tabIndex","isSheet","horizontal","disableElevation","cancelUnmountFocus","getDefaultFocusedIndex","remaining","isListbox","menubar","sheetMenuFocused","setSheetMenuFocused","sheetBlurredFame","menuBarContext","root","hoverTimeout","undefined","defaultActiveId","movementProps","movementContext","event","window","cancelAnimationFrame","current","loopable","searchable","programmatic","includeDisabled","disabled","value","div","aria-orientation","elevated","requestAnimationFrame","style","target","currentTarget","stopPropagation","HTMLElement","contains","closest"],"mappings":"AAAA;;AAEA,SAA8BA,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAE1E,SAASC,IAAI,QAAQ,kBAAkB;AAEvC,SAASC,2BAA2B,QAAQ,6CAA6C;AAGzF,SAASC,0BAA0B,QAAQ,kCAAkC;AAC7E,SAASC,IAAI,QAAQ,cAAc;AACnC,SACEC,eAAe,EACfC,iBAAiB,EACjBC,kBAAkB,QACb,0BAA0B;AAEjC,MAAMC,OAAO;AACX,aAAa;AACf;AAeA;;;;;;;;;CASC,GACD,OAAO,MAAMC,2BAAaX,WACxB,SAASW,WAAWC,KAAK,EAAEC,GAAG;IAC5B,MAAM,EACJC,EAAE,EACFC,OAAO,MAAM,EACbC,SAAS,EACTC,SAAS,EACTC,aAAa,EACbC,SAAS,EACTC,QAAQ,EACRC,OAAO,EACPC,SAASZ,IAAI,EACba,UAAUb,IAAI,EACdc,YAAYd,IAAI,EAChBe,WAAW,CAAC,CAAC,EACbC,OAAO,EACPC,UAAU,EACVC,gBAAgB,EAChBC,kBAAkB,EAClBC,sBAAsB,EACtB,GAAGC,WACJ,GAAGnB;IACJ,MAAMoB,YAAYjB,SAAS;IAC3B,MAAM,EAAEkB,OAAO,EAAE,GAAGzB;IAEpB,4EAA4E;IAC5E,oEAAoE;IACpE,yEAAyE;IACzE,0EAA0E;IAC1E,4EAA4E;IAC5E,2EAA2E;IAC3E,uEAAuE;IACvE,6BAA6B;IAC7B,MAAM,CAAC0B,kBAAkBC,oBAAoB,GAAGjC,SAAS;IACzD,MAAMkC,mBAAmBnC,OAAO;IAChC,MAAMoC,iBAAiB5B,mBAAmB;QACxC6B,MAAM;QACNL;QACAM,cAAcN,UAAU,IAAIO;QAC5BC,iBAAiB3B;IACnB;IACA,MAAM,EAAE4B,aAAa,EAAEC,eAAe,EAAE,GAAGvC,4BAA4B;QACrES;QACAQ;QACAE,SAAQ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ACF;8BAEC5C;;;;;AAMb,GACA"}
@@ -6,11 +6,21 @@ import type { KeyboardMovementConfig } from "./types.js";
6
6
  * @internal
7
7
  */
8
8
  export declare const DEFAULT_KEYBOARD_MOVEMENT: Readonly<KeyboardMovementConfig>;
9
+ /**
10
+ * @since 6.3.0
11
+ * @internal
12
+ */
13
+ export declare const DEFAULT_LTR_KEYBOARD_MOVEMENT_WITHOUT_JUMP: Readonly<KeyboardMovementConfig>;
9
14
  /**
10
15
  * @since 5.1.2
11
16
  * @internal
12
17
  */
13
18
  export declare const DEFAULT_LTR_KEYBOARD_MOVEMENT: Readonly<KeyboardMovementConfig>;
19
+ /**
20
+ * @since 6.3.0
21
+ * @internal
22
+ */
23
+ export declare const DEFAULT_RTL_KEYBOARD_MOVEMENT_WITHOUT_JUMP: Readonly<KeyboardMovementConfig>;
14
24
  /**
15
25
  * @since 5.1.2
16
26
  * @internal
@@ -18,15 +18,23 @@
18
18
  ]
19
19
  };
20
20
  /**
21
- * @since 5.1.2
21
+ * @since 6.3.0
22
22
  * @internal
23
- */ export const DEFAULT_LTR_KEYBOARD_MOVEMENT = {
23
+ */ export const DEFAULT_LTR_KEYBOARD_MOVEMENT_WITHOUT_JUMP = {
24
24
  incrementKeys: [
25
25
  "ArrowRight"
26
26
  ],
27
27
  decrementKeys: [
28
28
  "ArrowLeft"
29
29
  ],
30
+ jumpToFirstKeys: [],
31
+ jumpToLastKeys: []
32
+ };
33
+ /**
34
+ * @since 5.1.2
35
+ * @internal
36
+ */ export const DEFAULT_LTR_KEYBOARD_MOVEMENT = {
37
+ ...DEFAULT_LTR_KEYBOARD_MOVEMENT_WITHOUT_JUMP,
30
38
  jumpToFirstKeys: [
31
39
  "Home"
32
40
  ],
@@ -35,15 +43,23 @@
35
43
  ]
36
44
  };
37
45
  /**
38
- * @since 5.1.2
46
+ * @since 6.3.0
39
47
  * @internal
40
- */ export const DEFAULT_RTL_KEYBOARD_MOVEMENT = {
48
+ */ export const DEFAULT_RTL_KEYBOARD_MOVEMENT_WITHOUT_JUMP = {
41
49
  incrementKeys: [
42
50
  "ArrowLeft"
43
51
  ],
44
52
  decrementKeys: [
45
53
  "ArrowRight"
46
54
  ],
55
+ jumpToFirstKeys: [],
56
+ jumpToLastKeys: []
57
+ };
58
+ /**
59
+ * @since 5.1.2
60
+ * @internal
61
+ */ export const DEFAULT_RTL_KEYBOARD_MOVEMENT = {
62
+ ...DEFAULT_RTL_KEYBOARD_MOVEMENT_WITHOUT_JUMP,
47
63
  jumpToFirstKeys: [
48
64
  "Home"
49
65
  ],
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/movement/constants.ts"],"sourcesContent":["import type { KeyboardMovementConfig } from \"./types.js\";\n\n/**\n * Most custom keyboard functionality use these keys.\n *\n * @since 5.0.0\n * @internal\n */\nexport const DEFAULT_KEYBOARD_MOVEMENT: Readonly<KeyboardMovementConfig> = {\n incrementKeys: [\"ArrowDown\"],\n decrementKeys: [\"ArrowUp\"],\n jumpToFirstKeys: [\"Home\"],\n jumpToLastKeys: [\"End\"],\n};\n\n/**\n * @since 5.1.2\n * @internal\n */\nexport const DEFAULT_LTR_KEYBOARD_MOVEMENT: Readonly<KeyboardMovementConfig> = {\n incrementKeys: [\"ArrowRight\"],\n decrementKeys: [\"ArrowLeft\"],\n jumpToFirstKeys: [\"Home\"],\n jumpToLastKeys: [\"End\"],\n};\n\n/**\n * @since 5.1.2\n * @internal\n */\nexport const DEFAULT_RTL_KEYBOARD_MOVEMENT: Readonly<KeyboardMovementConfig> = {\n incrementKeys: [\"ArrowLeft\"],\n decrementKeys: [\"ArrowRight\"],\n jumpToFirstKeys: [\"Home\"],\n jumpToLastKeys: [\"End\"],\n};\n"],"names":["DEFAULT_KEYBOARD_MOVEMENT","incrementKeys","decrementKeys","jumpToFirstKeys","jumpToLastKeys","DEFAULT_LTR_KEYBOARD_MOVEMENT","DEFAULT_RTL_KEYBOARD_MOVEMENT"],"mappings":"AAEA;;;;;CAKC,GACD,OAAO,MAAMA,4BAA8D;IACzEC,eAAe;QAAC;KAAY;IAC5BC,eAAe;QAAC;KAAU;IAC1BC,iBAAiB;QAAC;KAAO;IACzBC,gBAAgB;QAAC;KAAM;AACzB,EAAE;AAEF;;;CAGC,GACD,OAAO,MAAMC,gCAAkE;IAC7EJ,eAAe;QAAC;KAAa;IAC7BC,eAAe;QAAC;KAAY;IAC5BC,iBAAiB;QAAC;KAAO;IACzBC,gBAAgB;QAAC;KAAM;AACzB,EAAE;AAEF;;;CAGC,GACD,OAAO,MAAME,gCAAkE;IAC7EL,eAAe;QAAC;KAAY;IAC5BC,eAAe;QAAC;KAAa;IAC7BC,iBAAiB;QAAC;KAAO;IACzBC,gBAAgB;QAAC;KAAM;AACzB,EAAE"}
1
+ {"version":3,"sources":["../../src/movement/constants.ts"],"sourcesContent":["import type { KeyboardMovementConfig } from \"./types.js\";\n\n/**\n * Most custom keyboard functionality use these keys.\n *\n * @since 5.0.0\n * @internal\n */\nexport const DEFAULT_KEYBOARD_MOVEMENT: Readonly<KeyboardMovementConfig> = {\n incrementKeys: [\"ArrowDown\"],\n decrementKeys: [\"ArrowUp\"],\n jumpToFirstKeys: [\"Home\"],\n jumpToLastKeys: [\"End\"],\n};\n\n/**\n * @since 6.3.0\n * @internal\n */\nexport const DEFAULT_LTR_KEYBOARD_MOVEMENT_WITHOUT_JUMP: Readonly<KeyboardMovementConfig> =\n {\n incrementKeys: [\"ArrowRight\"],\n decrementKeys: [\"ArrowLeft\"],\n jumpToFirstKeys: [],\n jumpToLastKeys: [],\n };\n\n/**\n * @since 5.1.2\n * @internal\n */\nexport const DEFAULT_LTR_KEYBOARD_MOVEMENT: Readonly<KeyboardMovementConfig> = {\n ...DEFAULT_LTR_KEYBOARD_MOVEMENT_WITHOUT_JUMP,\n jumpToFirstKeys: [\"Home\"],\n jumpToLastKeys: [\"End\"],\n};\n\n/**\n * @since 6.3.0\n * @internal\n */\nexport const DEFAULT_RTL_KEYBOARD_MOVEMENT_WITHOUT_JUMP: Readonly<KeyboardMovementConfig> =\n {\n incrementKeys: [\"ArrowLeft\"],\n decrementKeys: [\"ArrowRight\"],\n jumpToFirstKeys: [],\n jumpToLastKeys: [],\n };\n\n/**\n * @since 5.1.2\n * @internal\n */\nexport const DEFAULT_RTL_KEYBOARD_MOVEMENT: Readonly<KeyboardMovementConfig> = {\n ...DEFAULT_RTL_KEYBOARD_MOVEMENT_WITHOUT_JUMP,\n jumpToFirstKeys: [\"Home\"],\n jumpToLastKeys: [\"End\"],\n};\n"],"names":["DEFAULT_KEYBOARD_MOVEMENT","incrementKeys","decrementKeys","jumpToFirstKeys","jumpToLastKeys","DEFAULT_LTR_KEYBOARD_MOVEMENT_WITHOUT_JUMP","DEFAULT_LTR_KEYBOARD_MOVEMENT","DEFAULT_RTL_KEYBOARD_MOVEMENT_WITHOUT_JUMP","DEFAULT_RTL_KEYBOARD_MOVEMENT"],"mappings":"AAEA;;;;;CAKC,GACD,OAAO,MAAMA,4BAA8D;IACzEC,eAAe;QAAC;KAAY;IAC5BC,eAAe;QAAC;KAAU;IAC1BC,iBAAiB;QAAC;KAAO;IACzBC,gBAAgB;QAAC;KAAM;AACzB,EAAE;AAEF;;;CAGC,GACD,OAAO,MAAMC,6CACX;IACEJ,eAAe;QAAC;KAAa;IAC7BC,eAAe;QAAC;KAAY;IAC5BC,iBAAiB,EAAE;IACnBC,gBAAgB,EAAE;AACpB,EAAE;AAEJ;;;CAGC,GACD,OAAO,MAAME,gCAAkE;IAC7E,GAAGD,0CAA0C;IAC7CF,iBAAiB;QAAC;KAAO;IACzBC,gBAAgB;QAAC;KAAM;AACzB,EAAE;AAEF;;;CAGC,GACD,OAAO,MAAMG,6CACX;IACEN,eAAe;QAAC;KAAY;IAC5BC,eAAe;QAAC;KAAa;IAC7BC,iBAAiB,EAAE;IACnBC,gBAAgB,EAAE;AACpB,EAAE;AAEJ;;;CAGC,GACD,OAAO,MAAMI,gCAAkE;IAC7E,GAAGD,0CAA0C;IAC7CJ,iBAAiB;QAAC;KAAO;IACzBC,gBAAgB;QAAC;KAAM;AACzB,EAAE"}
@@ -1,5 +1,5 @@
1
- import type { FocusEvent, FocusEventHandler, KeyboardEvent, KeyboardEventHandler, MouseEvent, MouseEventHandler } from "react";
2
- import type { NonNullMutableRef, NonNullRef, UseStateSetter } from "../types.js";
1
+ import { type HTMLAttributes, type KeyboardEvent, type Ref, type RefCallback, type RefObject } from "react";
2
+ import { type NonNullMutableRef, type NonNullRef, type UseStateSetter } from "../types.js";
3
3
  /**
4
4
  * Set this to `"roving"` when:
5
5
  * - there are a group of focusable elements that have a `tabIndex={-1}`
@@ -109,6 +109,20 @@ export interface KeyboardMovementBehavior {
109
109
  */
110
110
  horizontal?: boolean;
111
111
  }
112
+ /**
113
+ * @since 6.3.0
114
+ */
115
+ export interface KeyboardFocusFromKeyOptions {
116
+ key: string;
117
+ /** @defaultValue `false` */
118
+ reversed?: boolean;
119
+ /** @defaultValue `getFocusableElementsFromRef()` */
120
+ focusables?: readonly HTMLElement[];
121
+ }
122
+ /**
123
+ * @since 6.3.0
124
+ */
125
+ export type KeyboardFocusAction = (focusables?: readonly HTMLElement[]) => void;
112
126
  /**
113
127
  * @since 5.0.0
114
128
  * @since 6.0.0 Removed `attach`, `detach` and `watching`
@@ -124,6 +138,26 @@ export interface KeyboardMovementContext extends Required<KeyboardMovementBehavi
124
138
  * has been set to `"roving"` or `"virtual"`.
125
139
  */
126
140
  activeDescendantId: string;
141
+ /**
142
+ * @since 6.3.0
143
+ */
144
+ focusFirst: KeyboardFocusAction;
145
+ /**
146
+ * @since 6.3.0
147
+ */
148
+ focusLast: KeyboardFocusAction;
149
+ /**
150
+ * @since 6.3.0
151
+ */
152
+ focusNext: KeyboardFocusAction;
153
+ /**
154
+ * @since 6.3.0
155
+ */
156
+ focusPrevious: KeyboardFocusAction;
157
+ /**
158
+ * @since 6.3.0
159
+ */
160
+ focusFromKey: (options: KeyboardFocusFromKeyOptions) => void;
127
161
  }
128
162
  /**
129
163
  * @since 6.0.0
@@ -166,16 +200,23 @@ export interface KeyboardMovementExtensionData<E extends HTMLElement> extends Ke
166
200
  setFocusIndex: (index: number, focusables: readonly HTMLElement[]) => void;
167
201
  setActiveDescendantId: (id: string) => void;
168
202
  }
203
+ /**
204
+ * @since 6.3.0
205
+ */
206
+ export type KeyboardMovementEventHandlers<E extends HTMLElement> = Pick<HTMLAttributes<E>, "onClick" | "onFocus" | "onKeyDown">;
207
+ /**
208
+ * @since 6.3.0
209
+ */
210
+ export interface SimpleKeyboardMovementWrapperOptions<E extends HTMLElement> extends KeyboardMovementEventHandlers<E> {
211
+ ref?: Ref<E>;
212
+ }
169
213
  /**
170
214
  * @since 6.0.0
171
215
  * @internal
172
216
  */
173
- export interface KeyboardMovementProviderOptions<E extends HTMLElement> extends KeyboardMovementBehavior, KeyboardMovementConfiguration {
217
+ export interface KeyboardMovementProviderOptions<E extends HTMLElement> extends KeyboardMovementBehavior, SimpleKeyboardMovementWrapperOptions<E>, KeyboardMovementConfiguration {
174
218
  /** @see {@link TabIndexBehavior} */
175
219
  tabIndexBehavior?: TabIndexBehavior;
176
- onClick?: (event: MouseEvent<E>) => void;
177
- onFocus?: (event: FocusEvent<E>) => void;
178
- onKeyDown?: (event: KeyboardEvent<E>) => void;
179
220
  /** @defaultValue `false` */
180
221
  disabled?: boolean;
181
222
  /**
@@ -210,12 +251,21 @@ export interface KeyboardMovementProviderOptions<E extends HTMLElement> extends
210
251
  * @defaultValue `false`
211
252
  */
212
253
  isNegativeOneAllowed?: boolean;
254
+ /**
255
+ * This was added to support spinbutton groups so the user can either use the
256
+ * ArrowLeft, ArrowRight, or Tab keys to move. Without this, switching
257
+ * between tab and the arrow keys would have the wrong tab index.
258
+ *
259
+ * @since 6.3.0
260
+ * @defaultValue `false`
261
+ */
262
+ trackTabKeys?: boolean;
213
263
  }
214
264
  /**
215
265
  * @since 6.0.0
216
266
  * @internal
217
267
  */
218
- export interface KeyboardMovementProps<E extends HTMLElement> {
268
+ export interface KeyboardMovementProps<E extends HTMLElement> extends Required<KeyboardMovementEventHandlers<E>> {
219
269
  /**
220
270
  * This will only be provided if the {@link KeyboardMovementContext.tabIndexBehavior}
221
271
  * is set to `"virtual"`.
@@ -231,15 +281,14 @@ export interface KeyboardMovementProps<E extends HTMLElement> {
231
281
  * - a child element **should** have a `tabIndex={0}` instead
232
282
  */
233
283
  tabIndex?: number;
234
- onClick: MouseEventHandler<E>;
235
- onFocus: FocusEventHandler<E>;
236
- onKeyDown: KeyboardEventHandler<E>;
284
+ ref: RefCallback<E>;
237
285
  }
238
286
  /**
239
287
  * @since 6.0.0
240
288
  * @internal
241
289
  */
242
290
  export interface KeyboardMovementProviderImplementation<E extends HTMLElement> {
291
+ nodeRef: RefObject<E>;
243
292
  movementProps: Readonly<KeyboardMovementProps<E>>;
244
293
  movementContext: Readonly<KeyboardMovementContext>;
245
294
  currentFocusIndex: NonNullMutableRef<number>;