downshift 9.3.2 → 9.4.0-alpha.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 (155) hide show
  1. package/dist/downshift.cjs.cjs +617 -698
  2. package/dist/downshift.d.ts +49 -55
  3. package/dist/downshift.esm.mjs +618 -699
  4. package/dist/downshift.native.cjs.cjs +575 -653
  5. package/dist/downshift.nativeweb.cjs.cjs +615 -693
  6. package/dist/downshift.types.d.ts +205 -0
  7. package/dist/downshift.umd.js +621 -702
  8. package/dist/downshift.umd.js.map +1 -1
  9. package/dist/downshift.umd.min.js +1 -1
  10. package/dist/downshift.umd.min.js.map +1 -1
  11. package/dist/hooks/testUtils/MemoizedItem.d.ts +10 -0
  12. package/dist/hooks/testUtils/fixtures.d.ts +16 -0
  13. package/dist/hooks/testUtils/index.d.ts +4 -0
  14. package/dist/hooks/testUtils/interactions.d.ts +16 -0
  15. package/dist/hooks/testUtils/testCases.d.ts +2 -0
  16. package/dist/hooks/useCombobox/__tests__/utils/index.d.ts +5 -0
  17. package/dist/hooks/useCombobox/__tests__/utils/interactions.d.ts +6 -0
  18. package/dist/hooks/useCombobox/__tests__/utils/renderCombobox.d.ts +72 -0
  19. package/dist/hooks/useCombobox/__tests__/utils/renderUseCombobox.d.ts +2 -0
  20. package/dist/hooks/useCombobox/index.d.ts +4 -94
  21. package/dist/hooks/useCombobox/index.types.d.ts +302 -0
  22. package/dist/hooks/useCombobox/reducer.d.ts +4 -1
  23. package/dist/hooks/useCombobox/stateChangeTypes.d.ts +24 -23
  24. package/dist/hooks/useCombobox/utils/getInitialState.d.ts +10 -0
  25. package/dist/hooks/useCombobox/utils/index.d.ts +3 -0
  26. package/dist/hooks/useCombobox/{utils.d.ts → utils/propTypes.d.ts} +2 -30
  27. package/dist/hooks/useCombobox/utils/useControlledReducer.d.ts +16 -0
  28. package/dist/hooks/useMultipleSelection/index.d.ts +25 -13
  29. package/dist/hooks/useMultipleSelection/index.types.d.ts +117 -0
  30. package/dist/hooks/useMultipleSelection/reducer.d.ts +1 -1
  31. package/dist/hooks/useMultipleSelection/utils.d.ts +14 -15
  32. package/dist/hooks/useSelect/__tests__/utils/getItemIndexByCharacter.d.ts +7 -0
  33. package/dist/hooks/useSelect/__tests__/utils/index.d.ts +6 -0
  34. package/dist/hooks/useSelect/__tests__/utils/renderSelect.d.ts +71 -0
  35. package/dist/hooks/useSelect/__tests__/utils/renderUseSelect.d.ts +2 -0
  36. package/dist/hooks/useSelect/__tests__/utils/stateChangeTestCases.d.ts +182 -0
  37. package/dist/hooks/useSelect/index.d.ts +4 -71
  38. package/dist/hooks/useSelect/index.types.d.ts +266 -0
  39. package/dist/hooks/useSelect/reducer.d.ts +4 -1
  40. package/dist/hooks/useSelect/stateChangeTypes.d.ts +23 -22
  41. package/dist/hooks/useSelect/utils/index.d.ts +0 -1
  42. package/dist/hooks/useTagGroup/__tests__/utils/renderTagGroup.d.ts +1 -1
  43. package/dist/hooks/useTagGroup/index.types.d.ts +10 -13
  44. package/dist/hooks/useTagGroup/reducer.d.ts +4 -2
  45. package/dist/hooks/useTagGroup/utils/index.d.ts +3 -1
  46. package/dist/hooks/utils/__tests__/dropdownDefaultProps.test.d.ts +1 -0
  47. package/dist/hooks/utils/__tests__/getChangesOnSelection.test.d.ts +1 -0
  48. package/dist/hooks/utils/__tests__/getDefaultHighlightedIndex.test.d.ts +1 -0
  49. package/dist/hooks/utils/__tests__/getDefaultValue.test.d.ts +1 -0
  50. package/dist/hooks/utils/__tests__/getHighlightedIndexOnOpen.test.d.ts +1 -0
  51. package/dist/hooks/utils/__tests__/getInitialValue.test.d.ts +1 -0
  52. package/dist/hooks/utils/__tests__/getItemAndIndex.test.d.ts +1 -0
  53. package/dist/hooks/utils/__tests__/isDropdownStateEqual.test.d.ts +1 -0
  54. package/dist/hooks/utils/__tests__/useA11yMessageStatus.test.d.ts +1 -0
  55. package/dist/hooks/utils/__tests__/useControlPropsValidator.test.d.ts +1 -0
  56. package/dist/hooks/utils/__tests__/useControlledReducer.test.d.ts +1 -0
  57. package/dist/hooks/utils/__tests__/useElementIds.legacy.test.d.ts +1 -0
  58. package/dist/hooks/utils/__tests__/useElementIds.r18.test.d.ts +1 -0
  59. package/dist/hooks/utils/__tests__/useEnhancedReducer.test.d.ts +1 -0
  60. package/dist/hooks/utils/__tests__/useGetterPropsCalledChecker.test.d.ts +1 -0
  61. package/dist/hooks/utils/__tests__/useIsInitialMount.test.d.ts +1 -0
  62. package/dist/hooks/utils/__tests__/useMouseAndTouchTracker.test.d.ts +1 -0
  63. package/dist/hooks/utils/__tests__/useScrollIntoView.test.d.ts +1 -0
  64. package/dist/hooks/utils/callOnChangeProps.d.ts +4 -0
  65. package/dist/hooks/utils/dropdownDefaultProps.d.ts +13 -0
  66. package/dist/hooks/{utils.dropdown/defaultStateValues.d.ts → utils/dropdownDefaultStateValues.d.ts} +2 -2
  67. package/dist/hooks/{utils.dropdown/propTypes.d.ts → utils/dropdownPropTypes.d.ts} +1 -1
  68. package/dist/hooks/utils/getChangesOnSelection.d.ts +17 -0
  69. package/dist/hooks/utils/getDefaultHighlightedIndex.d.ts +7 -0
  70. package/dist/hooks/utils/getDefaultValue.d.ts +8 -0
  71. package/dist/hooks/utils/getHighlightedIndexOnOpen.d.ts +16 -0
  72. package/dist/hooks/utils/getInitialState.d.ts +23 -0
  73. package/dist/hooks/utils/getInitialValue.d.ts +14 -0
  74. package/dist/hooks/utils/index.d.ts +24 -0
  75. package/dist/hooks/utils/index.types.d.ts +26 -0
  76. package/dist/hooks/utils/isDropdownStateEqual.d.ts +16 -0
  77. package/dist/hooks/utils/reducer.d.ts +27 -0
  78. package/dist/hooks/utils/useControlPropsValidator.d.ts +6 -0
  79. package/dist/hooks/utils/useControlledReducer.d.ts +13 -0
  80. package/dist/hooks/utils/useEnhancedReducer.d.ts +15 -0
  81. package/dist/hooks/utils/useGetterPropsCalledChecker.d.ts +2 -0
  82. package/dist/hooks/utils/useMouseAndTouchTracker.d.ts +15 -0
  83. package/dist/hooks/utils/useScrollIntoView.d.ts +11 -0
  84. package/dist/index.d.ts +1 -1
  85. package/dist/utils/__tests__/callAllEventHandlers.test.d.ts +1 -0
  86. package/dist/utils/__tests__/debounce.test.d.ts +1 -0
  87. package/dist/utils/__tests__/generateId.r18.test.d.ts +1 -0
  88. package/dist/utils/__tests__/generateId.test.d.ts +1 -0
  89. package/dist/utils/__tests__/getHighlightedIndex.test.d.ts +1 -0
  90. package/dist/utils/__tests__/getNonDisabledIndex.test.d.ts +1 -0
  91. package/dist/utils/__tests__/getState.test.d.ts +1 -0
  92. package/dist/utils/__tests__/handleRefs.test.d.ts +1 -0
  93. package/dist/utils/__tests__/normalizeArrowKey.test.d.ts +1 -0
  94. package/dist/utils/__tests__/scrollIntoView.test.d.ts +1 -0
  95. package/dist/utils/__tests__/setA11yStatus.test.d.ts +1 -0
  96. package/dist/utils/__tests__/targetWithinDownshift.test.d.ts +1 -0
  97. package/dist/utils/__tests__/useLatestRef.test.d.ts +1 -0
  98. package/dist/utils/__tests__/validateControlledUnchanged.test.d.ts +1 -0
  99. package/dist/utils/__tests__/validatePropTypes.test.d.ts +1 -0
  100. package/dist/utils/getHighlightedIndex.d.ts +11 -0
  101. package/dist/utils/getNonDisabledIndex.d.ts +11 -0
  102. package/dist/utils/getState.d.ts +12 -0
  103. package/dist/utils/handleRefs.d.ts +2 -0
  104. package/dist/{utils-ts → utils}/index.d.ts +5 -1
  105. package/dist/utils/normalizeArrowKey.d.ts +6 -0
  106. package/dist/utils/targetWithinDownshift.d.ts +12 -0
  107. package/dist/utils/validateControlledUnchanged.d.ts +1 -0
  108. package/dist/utils/validatePropTypes.d.ts +2 -0
  109. package/dist/utils.legacy.d.ts +54 -0
  110. package/flow-typed/npm/downshift_v2.x.x.js.flow +87 -62
  111. package/package.json +2 -4
  112. package/preact/dist/downshift.cjs.cjs +617 -698
  113. package/preact/dist/downshift.cjs.js +4265 -0
  114. package/preact/dist/downshift.esm.js +4238 -0
  115. package/preact/dist/downshift.esm.mjs +618 -699
  116. package/preact/dist/downshift.umd.js +617 -698
  117. package/preact/dist/downshift.umd.js.map +1 -1
  118. package/preact/dist/downshift.umd.min.js +1 -1
  119. package/preact/dist/downshift.umd.min.js.map +1 -1
  120. package/typings/index.d.ts +13 -21
  121. package/dist/hooks/reducer.d.ts +0 -1
  122. package/dist/hooks/useSelect/utils/defaultProps.d.ts +0 -8
  123. package/dist/hooks/utils-ts/callOnChangeProps.d.ts +0 -2
  124. package/dist/hooks/utils-ts/getDefaultValue.d.ts +0 -2
  125. package/dist/hooks/utils-ts/getInitialValue.d.ts +0 -2
  126. package/dist/hooks/utils-ts/index.d.ts +0 -11
  127. package/dist/hooks/utils-ts/stateReducer.d.ts +0 -6
  128. package/dist/hooks/utils-ts/useControlledReducer.d.ts +0 -12
  129. package/dist/hooks/utils-ts/useEnhancedReducer.d.ts +0 -13
  130. package/dist/hooks/utils.d.ts +0 -58
  131. package/dist/hooks/utils.dropdown/defaultProps.d.ts +0 -9
  132. package/dist/hooks/utils.dropdown/index.d.ts +0 -3
  133. package/dist/utils-ts/getState.d.ts +0 -22
  134. package/dist/utils-ts/handleRefs.d.ts +0 -2
  135. package/dist/utils-ts/validatePropTypes.d.ts +0 -2
  136. package/dist/utils.d.ts +0 -123
  137. package/typings/index.legacy.d.ts +0 -888
  138. /package/dist/hooks/{utils-ts/__tests__/getItemAndIndex.test.d.ts → useCombobox/utils/__tests__/getInitialState.test.d.ts} +0 -0
  139. /package/dist/hooks/{utils.dropdown/__tests__/useElementIds.legacy.test.d.ts → useCombobox/utils/__tests__/useControlledReducer.test.d.ts} +0 -0
  140. /package/dist/hooks/{utils.dropdown/__tests__/useElementIds.r18.test.d.ts → useSelect/utils/__tests__/getItemIndexByCharacterKey.test.d.ts} +0 -0
  141. /package/dist/{utils-ts/__tests__/getState.test.d.ts → hooks/utils/__tests__/callOnChangeProps.test.d.ts} +0 -0
  142. /package/dist/{utils-ts/__tests__/handleRefs.test.d.ts → hooks/utils/__tests__/capitalizeString.test.d.ts} +0 -0
  143. /package/dist/hooks/{utils-ts → utils}/capitalizeString.d.ts +0 -0
  144. /package/dist/hooks/{utils-ts → utils}/getItemAndIndex.d.ts +0 -0
  145. /package/dist/hooks/{utils-ts → utils}/propTypes.d.ts +0 -0
  146. /package/dist/hooks/{utils-ts → utils}/useA11yMessageStatus.d.ts +0 -0
  147. /package/dist/hooks/{utils.dropdown → utils}/useElementIds.d.ts +0 -0
  148. /package/dist/hooks/{utils-ts → utils}/useIsInitialMount.d.ts +0 -0
  149. /package/dist/{utils-ts → utils}/callAllEventHandlers.d.ts +0 -0
  150. /package/dist/{utils-ts → utils}/debounce.d.ts +0 -0
  151. /package/dist/{utils-ts → utils}/generateId.d.ts +0 -0
  152. /package/dist/{utils-ts → utils}/noop.d.ts +0 -0
  153. /package/dist/{utils-ts → utils}/scrollIntoView.d.ts +0 -0
  154. /package/dist/{utils-ts → utils}/setA11yStatus.d.ts +0 -0
  155. /package/dist/{utils-ts → utils}/useLatestRef.d.ts +0 -0
@@ -0,0 +1,26 @@
1
+ type StateReducerProp<S extends object, A extends {
2
+ type: string;
3
+ }> = (state: S, actionAndChanges: (A & {
4
+ props: any;
5
+ }) & {
6
+ changes: Partial<S>;
7
+ }) => Partial<S>;
8
+ export type Props<S extends object, A extends {
9
+ type: string;
10
+ }> = Partial<S> & {
11
+ stateReducer: StateReducerProp<S, A>;
12
+ onStateChange?: (changes: {
13
+ type: A['type'];
14
+ } & Partial<S>) => void;
15
+ };
16
+ export type Action<S extends object, A extends {
17
+ type: string;
18
+ }, P extends Props<S, A>> = A & {
19
+ props: P;
20
+ };
21
+ export type Reducer<S extends object, A extends {
22
+ type: string;
23
+ }> = (state: S, action: A & {
24
+ props: any;
25
+ }) => Partial<S>;
26
+ export {};
@@ -0,0 +1,16 @@
1
+ type DropdownState<Item> = {
2
+ isOpen: boolean;
3
+ inputValue: string;
4
+ highlightedIndex: number;
5
+ selectedItem: Item | null;
6
+ };
7
+ /**
8
+ * Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
9
+ * Used by useSelect and useCombobox.
10
+ *
11
+ * @param prevState The previous dropdown state.
12
+ * @param newState The new dropdown state.
13
+ * @returns Wheather the states are deeply equal.
14
+ */
15
+ export declare function isDropdownStateEqual<Item>(prevState: DropdownState<Item>, newState: DropdownState<Item>): boolean;
16
+ export {};
@@ -0,0 +1,27 @@
1
+ type CommonState<Item> = {
2
+ highlightedIndex: number;
3
+ isOpen: boolean;
4
+ selectedItem: Item | null;
5
+ inputValue: string;
6
+ };
7
+ type CommonProps<Item> = {
8
+ items: Item[];
9
+ isItemDisabled: (item: Item, index: number) => boolean;
10
+ itemToKey: (item: Item | null) => unknown;
11
+ initialHighlightedIndex?: number;
12
+ defaultHighlightedIndex?: number;
13
+ defaultIsOpen?: boolean;
14
+ defaultSelectedItem?: Item | null;
15
+ defaultInputValue?: string;
16
+ };
17
+ type CommonAction<Item> = {
18
+ type: string;
19
+ index?: number;
20
+ disabled?: boolean;
21
+ highlightedIndex?: number;
22
+ inputValue?: string;
23
+ selectedItem?: Item | null;
24
+ };
25
+ type CommonStateChangeTypes = Record<string, string>;
26
+ export default function downshiftCommonReducer<Item>(state: CommonState<Item>, props: CommonProps<Item>, action: CommonAction<Item>, stateChangeTypes: CommonStateChangeTypes): CommonState<Item>;
27
+ export {};
@@ -0,0 +1,6 @@
1
+ type UseControlPropsValidatorOptions = {
2
+ state: Record<string, any>;
3
+ props: Record<string, any>;
4
+ };
5
+ export declare let useControlPropsValidator: (options: UseControlPropsValidatorOptions) => void;
6
+ export {};
@@ -0,0 +1,13 @@
1
+ import { type Props, type Reducer } from './index.types';
2
+ /**
3
+ * Wraps the useEnhancedReducer and applies the controlled prop values before
4
+ * returning the new state.
5
+ * @param reducer Reducer function from downshift.
6
+ * @param props The hook props, also passed to createInitialState.
7
+ * @param createInitialState Function that returns the initial state.
8
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
9
+ * @returns An array with the state and an action dispatcher.
10
+ */
11
+ export declare function useControlledReducer<S extends object, A extends {
12
+ type: string;
13
+ }, P extends Props<S, A>>(reducer: Reducer<S, A>, props: P, createInitialState: (props: P) => S, isStateEqual: (prev: S, next: S) => boolean): [S, (action: A) => void];
@@ -0,0 +1,15 @@
1
+ import { type Props, type Reducer } from './index.types';
2
+ /**
3
+ * Computes the controlled state using a the previous state, props,
4
+ * two reducers, one from downshift and an optional one from the user.
5
+ * Also calls the onChange handlers for state values that have changed.
6
+ *
7
+ * @param reducer Reducer function from downshift.
8
+ * @param props The hook props, also passed to createInitialState.
9
+ * @param createInitialState Function that returns the initial state.
10
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
11
+ * @returns An array with the state and an action dispatcher.
12
+ */
13
+ export declare function useEnhancedReducer<S extends object, A extends {
14
+ type: string;
15
+ }, P extends Props<S, A>>(reducer: Reducer<S, A>, props: P, createInitialState: (props: P) => S, isStateEqual: (prev: S, next: S) => boolean): [S, (action: A) => void];
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ export declare let useGetterPropsCalledChecker: (...propKeys: string[]) => (propKey: string, suppressRefError: boolean, refKey: string, elementRef: React.RefObject<HTMLElement> | undefined) => void;
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import { Environment } from '../../downshift.types';
3
+ /**
4
+ * Tracks mouse and touch events, such as mouseDown, touchMove and touchEnd.
5
+ *
6
+ * @param environment The environment to add the event listeners to, for instance window.
7
+ * @param handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
8
+ * @param downshiftRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
9
+ * @returns The mouse and touch events information.
10
+ */
11
+ export declare function useMouseAndTouchTracker(environment: Environment | undefined, handleBlur: () => void, downshiftRefs: React.RefObject<HTMLElement>[]): {
12
+ isMouseDown: boolean;
13
+ isTouchMove: boolean;
14
+ isTouchEnd: boolean;
15
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Utility hook that scrolls an item from a menu into view.
3
+ * @param scrollIntoView The function that does the scroll.
4
+ * @param highlightedIndex The index of the item that should be scrolled.
5
+ * @param isOpen If the menu is open or not.
6
+ * @param menuElement The menu element.
7
+ * @param itemElements The object containing item elements.
8
+ * @param getItemId The function to get the item id from index.
9
+ * @returns Function that when called prevents the scroll.
10
+ */
11
+ export declare function useScrollIntoView(scrollIntoView: (node: HTMLElement, menuNode: HTMLElement) => void, highlightedIndex: number, isOpen: boolean, menuElement: HTMLElement | null, itemElements: Record<string, HTMLElement>, getItemId: (index: number) => string): () => void;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { default } from './downshift';
2
- export { resetIdCounter } from './utils-ts';
2
+ export { resetIdCounter } from './utils';
3
3
  export { useSelect, useCombobox, useTagGroup } from './hooks';
4
4
  /**
5
5
  * @deprecated Not maintained anymore. Use the new useTagGroup instead.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Returns the next non-disabled highlightedIndex value.
3
+ *
4
+ * @param start The current highlightedIndex.
5
+ * @param offset The offset from the current highlightedIndex to start searching.
6
+ * @param items The items array.
7
+ * @param isItemDisabled Function that tells if an item is disabled or not.
8
+ * @param circular If the search reaches the end, if it can search again starting from the other end.
9
+ * @returns The next highlightedIndex.
10
+ */
11
+ export declare function getHighlightedIndex<Item>(start: number, offset: number, items: Item[], isItemDisabled: (item: Item, index: number) => boolean, circular?: boolean): number;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Returns the next non-disabled highlightedIndex value.
3
+ *
4
+ * @param start The current highlightedIndex.
5
+ * @param backwards If true, it will search backwards from the start.
6
+ * @param items The items array.
7
+ * @param isItemDisabled Function that tells if an item is disabled or not.
8
+ * @param circular If the search reaches the end, if it can search again starting from the other end.
9
+ * @returns The next non-disabled index.
10
+ */
11
+ export declare function getNonDisabledIndex<Item>(start: number, backwards: boolean, items: Item[], isItemDisabled: (item: Item, index: number) => boolean, circular?: boolean): number;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * This will perform a shallow merge of the given state object
3
+ * with the state coming from props
4
+ * (for the controlled component scenario)
5
+ * This is used in state updater functions so they're referencing
6
+ * the right state regardless of where it comes from.
7
+ *
8
+ * @param state The state of the component/hook.
9
+ * @param props The props that may contain controlled values.
10
+ * @returns The merged controlled state.
11
+ */
12
+ export declare function getState<S extends object>(state: S, props?: Partial<S>): S;
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ export declare function handleRefs<T extends HTMLElement>(...refs: (React.Ref<T> | undefined)[]): (node: T) => void;
@@ -7,5 +7,9 @@ export { setStatus, cleanupStatusDiv } from './setA11yStatus';
7
7
  export { noop } from './noop';
8
8
  export { validatePropTypes } from './validatePropTypes';
9
9
  export { getState } from './getState';
10
- export type { Action, Props, State } from './getState';
11
10
  export { scrollIntoView } from './scrollIntoView';
11
+ export { normalizeArrowKey } from './normalizeArrowKey';
12
+ export { getHighlightedIndex } from './getHighlightedIndex';
13
+ export { getNonDisabledIndex } from './getNonDisabledIndex';
14
+ export { validateControlledUnchanged } from './validateControlledUnchanged';
15
+ export { targetWithinDownshift } from './targetWithinDownshift';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Normalizes the 'key' property of a KeyboardEvent in IE/Edge
3
+ * @param event a keyboardEvent object
4
+ * @return keyboard key
5
+ */
6
+ export declare function normalizeArrowKey(event: KeyboardEvent): string;
@@ -0,0 +1,12 @@
1
+ import { Environment } from '../downshift.types';
2
+ /**
3
+ * Checks if event target is within the downshift elements.
4
+ *
5
+ * @param target Target to check.
6
+ * @param downshiftElements The elements that form downshift (list, toggle button etc).
7
+ * @param environment The window context where downshift renders.
8
+ * @param checkActiveElement Whether to also check activeElement.
9
+ *
10
+ * @returns Whether or not the target is within downshift elements.
11
+ */
12
+ export declare function targetWithinDownshift(target: EventTarget | undefined | null, downshiftElements: (HTMLElement | undefined | null)[], environment: Environment | undefined, checkActiveElement?: boolean): boolean;
@@ -0,0 +1 @@
1
+ export declare let validateControlledUnchanged: (state: Record<string, any>, prevProps: Record<string, any>, nextProps: Record<string, any>) => void;
@@ -0,0 +1,2 @@
1
+ import PropTypes from 'prop-types';
2
+ export declare let validatePropTypes: (options: unknown, caller: Function, propTypes: Record<string, PropTypes.Validator<unknown>>) => void;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Accepts a parameter and returns it if it's a function
3
+ * or a noop function if it's not. This allows us to
4
+ * accept a callback, but not worry about it if it's not
5
+ * passed.
6
+ * @param {Function} cb the callback
7
+ * @return {Function} a function
8
+ */
9
+ export function cbToCb(cb: Function): Function;
10
+ /**
11
+ * Default implementation for status message. Only added when menu is open.
12
+ * Will specify if there are results in the list, and if so, how many,
13
+ * and what keys are relevant.
14
+ *
15
+ * @param {Object} param the downshift state and other relevant properties
16
+ * @return {String} the a11y status message
17
+ */
18
+ export function getA11yStatusMessage({ isOpen, resultCount, previousResultCount }: Object): string;
19
+ /**
20
+ * Takes an argument and if it's an array, returns the first item in the array
21
+ * otherwise returns the argument
22
+ * @param {*} arg the maybe-array
23
+ * @param {*} defaultValue the value if arg is falsey not defined
24
+ * @return {*} the arg or it's first item
25
+ */
26
+ export function unwrapArray(arg: any, defaultValue: any): any;
27
+ /**
28
+ * @param {Object} element (P)react element
29
+ * @return {Boolean} whether it's a DOM element
30
+ */
31
+ export function isDOMElement(element: Object): boolean;
32
+ /**
33
+ * @param {Object} element (P)react element
34
+ * @return {Object} the props
35
+ */
36
+ export function getElementProps(element: Object): Object;
37
+ /**
38
+ * Throws a helpful error message for required properties. Useful
39
+ * to be used as a default in destructuring or object params.
40
+ * @param {String} fnName the function name
41
+ * @param {String} propName the prop name
42
+ */
43
+ export function requiredProp(fnName: string, propName: string): void;
44
+ /**
45
+ * @param {Object} state the state object
46
+ * @return {Object} state that is relevant to downshift
47
+ */
48
+ export function pickState(state?: Object): Object;
49
+ /**
50
+ * Simple check if the value passed is object literal
51
+ * @param {*} obj any things
52
+ * @return {Boolean} whether it's object literal
53
+ */
54
+ export function isPlainObject(obj: any): boolean;
@@ -115,80 +115,89 @@ declare module downshift {
115
115
  ) => StateChangeOptions<Item>
116
116
 
117
117
  declare export type GetRootPropsReturn = {
118
- role: 'combobox';
119
- 'aria-expanded': boolean;
120
- 'aria-haspopup': 'listbox';
121
- 'aria-owns': string | null;
122
- 'aria-labelledby': string;
118
+ role: 'combobox',
119
+ 'aria-expanded': boolean,
120
+ 'aria-haspopup': 'listbox',
121
+ 'aria-owns': string | null,
122
+ 'aria-labelledby': string,
123
123
  }
124
124
  declare export interface GetRootPropsOptions {
125
125
  refKey: string;
126
126
  }
127
127
 
128
- declare type GetToggleButtonCallbacks = {
129
- onMouseMove: (e: SyntheticEvent<Element>) => void;
130
- onMouseDown: (e: SyntheticEvent<Element>) => void;
131
- onBlur: (e: SyntheticEvent<Element>) => void;
132
- } | {
133
- onPress: (e: SyntheticEvent<Element>) => void; // should be react native type
134
- } | {}
128
+ declare type GetToggleButtonCallbacks =
129
+ | {
130
+ onMouseMove: (e: SyntheticEvent<Element>) => void,
131
+ onMouseDown: (e: SyntheticEvent<Element>) => void,
132
+ onBlur: (e: SyntheticEvent<Element>) => void,
133
+ }
134
+ | {
135
+ onPress: (e: SyntheticEvent<Element>) => void, // should be react native type
136
+ }
137
+ | {}
135
138
  declare export type GetToggleButtonReturn = {
136
- type: 'button';
137
- role: 'button';
138
- 'aria-label': 'close menu' | 'open menu';
139
- 'aria-haspopup': true;
140
- 'data-toggle': true;
139
+ type: 'button',
140
+ role: 'button',
141
+ 'aria-label': 'close menu' | 'open menu',
142
+ 'aria-haspopup': true,
143
+ 'data-toggle': true,
141
144
  } & GetInputPropsCallbacks
142
- declare export interface getToggleButtonPropsOptions
143
- extends React.HTMLProps<HTMLButtonElement> {}
145
+ declare export interface getToggleButtonPropsOptions extends React.HTMLProps<HTMLButtonElement> {}
144
146
 
145
147
  declare export interface GetLabelPropsReturn {
146
148
  htmlFor: string;
147
149
  id: string;
148
150
  }
149
- declare export interface GetLabelPropsOptions
150
- extends React.HTMLProps<HTMLLabelElement> {}
151
+ declare export interface GetLabelPropsOptions extends React.HTMLProps<HTMLLabelElement> {}
151
152
 
152
153
  declare export type getMenuPropsReturn = {
153
- role: 'listbox';
154
- 'aria-labelledby': string | null;
155
- id: string;
154
+ role: 'listbox',
155
+ 'aria-labelledby': string | null,
156
+ id: string,
156
157
  }
157
158
 
158
- declare type GetInputPropsCallbacks = ({
159
- onKeyDown: (e: SyntheticEvent<Element>) => void;
160
- onBlur: (e: SyntheticEvent<Element>) => void;
161
- } & ({
162
- onInput: (e: SyntheticEvent<Element>) => void;
163
- } | {
164
- onChangeText: (e: SyntheticEvent<Element>) => void;
165
- } | {
166
- onChange: (e: SyntheticEvent<Element>) => void;
167
- })) | {}
159
+ declare type GetInputPropsCallbacks =
160
+ | ({
161
+ onKeyDown: (e: SyntheticEvent<Element>) => void,
162
+ onBlur: (e: SyntheticEvent<Element>) => void,
163
+ } & (
164
+ | {
165
+ onInput: (e: SyntheticEvent<Element>) => void,
166
+ }
167
+ | {
168
+ onChangeText: (e: SyntheticEvent<Element>) => void,
169
+ }
170
+ | {
171
+ onChange: (e: SyntheticEvent<Element>) => void,
172
+ }
173
+ ))
174
+ | {}
168
175
  declare export type GetInputPropsReturn = {
169
- 'aria-autocomplete': 'list';
170
- 'aria-activedescendant': string | null;
171
- 'aria-controls': string | null;
172
- 'aria-labelledby': string;
173
- autoComplete: 'off';
174
- value: string;
175
- id: string;
176
- } & GetInputPropsCallbacks;
177
- declare export interface GetInputPropsOptions
178
- extends React.HTMLProps<HTMLInputElement> {}
176
+ 'aria-autocomplete': 'list',
177
+ 'aria-activedescendant': string | null,
178
+ 'aria-controls': string | null,
179
+ 'aria-labelledby': string,
180
+ autoComplete: 'off',
181
+ value: string,
182
+ id: string,
183
+ } & GetInputPropsCallbacks
184
+ declare export interface GetInputPropsOptions extends React.HTMLProps<HTMLInputElement> {}
179
185
 
180
186
  declare type GetItemPropsCallbacks = {
181
- onMouseMove: (e: SyntheticEvent<Element>) => void;
182
- onMouseDown: (e: SyntheticEvent<Element>) => void;
183
- } & ({
184
- onPress: (e: SyntheticEvent<Element>) => void;
185
- } | {
186
- onClick: (e: SyntheticEvent<Element>) => void;
187
- })
187
+ onMouseMove: (e: SyntheticEvent<Element>) => void,
188
+ onMouseDown: (e: SyntheticEvent<Element>) => void,
189
+ } & (
190
+ | {
191
+ onPress: (e: SyntheticEvent<Element>) => void,
192
+ }
193
+ | {
194
+ onClick: (e: SyntheticEvent<Element>) => void,
195
+ }
196
+ )
188
197
  declare export type GetItemPropsReturn = {
189
- id: string;
190
- role: 'option';
191
- 'aria-selected': boolean;
198
+ id: string,
199
+ role: 'option',
200
+ 'aria-selected': boolean,
192
201
  } & GetItemPropsCallbacks
193
202
  declare export type GetItemPropsOptions<Item> = {
194
203
  index?: number,
@@ -196,20 +205,36 @@ declare module downshift {
196
205
  }
197
206
 
198
207
  declare export interface PropGetters<Item> {
199
- getRootProps: <T:{}>(options: GetRootPropsOptions & T) => GetRootPropsReturn & T;
200
- getButtonProps: <T:{}>(options?: getToggleButtonPropsOptions & T) => GetToggleButtonReturn & T;
201
- getToggleButtonProps: <T:{}>(options?: getToggleButtonPropsOptions & T) => GetToggleButtonReturn & T;
202
- getLabelProps: <T:{}>(options?: GetLabelPropsOptions & T) => GetLabelPropsReturn & T;
203
- getMenuProps: <T:{}>(options?: T) => getMenuPropsReturn & T;
204
- getInputProps: <T:{}>(options?: GetInputPropsOptions & T) => GetInputPropsReturn & T;
205
- getItemProps: <T:{}>(options: GetItemPropsOptions<Item> & T) => GetItemPropsReturn & T;
208
+ getRootProps: <T: {}>(
209
+ options: GetRootPropsOptions & T,
210
+ ) => GetRootPropsReturn & T;
211
+ getButtonProps: <T: {}>(
212
+ options?: getToggleButtonPropsOptions & T,
213
+ ) => GetToggleButtonReturn & T;
214
+ getToggleButtonProps: <T: {}>(
215
+ options?: getToggleButtonPropsOptions & T,
216
+ ) => GetToggleButtonReturn & T;
217
+ getLabelProps: <T: {}>(
218
+ options?: GetLabelPropsOptions & T,
219
+ ) => GetLabelPropsReturn & T;
220
+ getMenuProps: <T: {}>(options?: T) => getMenuPropsReturn & T;
221
+ getInputProps: <T: {}>(
222
+ options?: GetInputPropsOptions & T,
223
+ ) => GetInputPropsReturn & T;
224
+ getItemProps: <T: {}>(
225
+ options: GetItemPropsOptions<Item> & T,
226
+ ) => GetItemPropsReturn & T;
206
227
  }
207
228
  declare export interface Actions<Item> {
208
229
  reset: (otherStateToSet?: {}, cb?: Callback) => void;
209
230
  openMenu: (cb?: Callback) => void;
210
231
  closeMenu: (cb?: Callback) => void;
211
232
  toggleMenu: (otherStateToSet?: {}, cb?: Callback) => void;
212
- selectItem: (item: Item | null, otherStateToSet?: {}, cb?: Callback) => void;
233
+ selectItem: (
234
+ item: Item | null,
235
+ otherStateToSet?: {},
236
+ cb?: Callback,
237
+ ) => void;
213
238
  selectItemAtIndex: (
214
239
  index: number,
215
240
  otherStateToSet?: {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "downshift",
3
- "version": "9.3.2",
3
+ "version": "9.4.0-alpha.0",
4
4
  "description": "🏎 A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete, combobox or select dropdown components.",
5
5
  "main": "dist/downshift.cjs.cjs",
6
6
  "react-native": "dist/downshift.native.cjs.cjs",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "husky": {
41
41
  "hooks": {
42
- "pre-commit": "kcd-scripts pre-commit"
42
+ "pre-commit": "unset ELECTRON_RUN_AS_NODE && kcd-scripts pre-commit"
43
43
  }
44
44
  },
45
45
  "files": [
@@ -91,7 +91,6 @@
91
91
  "@babel/helpers": "^7.28.6",
92
92
  "@babel/plugin-proposal-private-methods": "^7.18.6",
93
93
  "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
94
- "@cypress/webpack-preprocessor": "^7.0.2",
95
94
  "@docusaurus/core": "3.3.2",
96
95
  "@docusaurus/module-type-aliases": "3.3.2",
97
96
  "@docusaurus/preset-classic": "3.3.2",
@@ -197,7 +196,6 @@
197
196
  "dist",
198
197
  ".docusaurus",
199
198
  "build",
200
- "typings",
201
199
  "test"
202
200
  ],
203
201
  "repository": {