@elliemae/ds-hooks-keyboard-navigation 3.80.0-next.8 → 3.80.0-next.80
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.
- package/dist/cjs/DSHooksKeyboardNavigation.js +1 -0
- package/dist/cjs/DSHooksKeyboardNavigation.js.map +2 -2
- package/dist/esm/DSHooksKeyboardNavigation.js +1 -0
- package/dist/esm/DSHooksKeyboardNavigation.js.map +2 -2
- package/dist/types/DSHooksKeyboardNavigation.d.ts +14 -11
- package/package.json +6 -6
|
@@ -118,6 +118,7 @@ const useKeyboardNavigation = (props) => {
|
|
|
118
118
|
[getWrapperProps, getItemProps, focusedOption, setFocusedOption]
|
|
119
119
|
);
|
|
120
120
|
};
|
|
121
|
+
useKeyboardNavigation.displayName = "useKeyboardNavigation";
|
|
121
122
|
const UseKeyboardNavigationWithSchema = (0, import_ds_props_helpers.describe)(useKeyboardNavigation);
|
|
122
123
|
UseKeyboardNavigationWithSchema.propTypes = import_react_desc_prop_types2.propTypes;
|
|
123
124
|
//# sourceMappingURL=DSHooksKeyboardNavigation.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/DSHooksKeyboardNavigation.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable complexity */\nimport { useCallback, useMemo, useRef } from 'react';\nimport { useOnBlurOut, type DSHooksUseOBlurOutT } from '@elliemae/ds-hooks-on-blur-out';\nimport { describe } from '@elliemae/ds-props-helpers';\nimport { type TypescriptHelpersT } from '@elliemae/ds-typescript-helpers';\nimport { type DSHooksKeyboardNaviationT } from './react-desc-prop-types.js';\nimport { propTypes } from './react-desc-prop-types.js';\nimport { findInCircularList } from './utils.js';\n\nconst defaultFocusCriteria = () => true;\nconst useKeyboardNavigation = (props: DSHooksKeyboardNaviationT.Props) => {\n const {\n options,\n direction = 'agnostic',\n disableRoving = false,\n focusCriteria = defaultFocusCriteria,\n onKeyDown: userOnKeyDown,\n focusedOption,\n setFocusedOption,\n } = props;\n const previousFocusedOption = useRef<string | null>(null);\n const focusedOptionMutable = useRef<string | null>(null);\n\n const config: {\n onBlur: DSHooksUseOBlurOutT.OnBlurCb;\n } = useMemo(\n () => ({\n onBlur: () => {\n // if (e.currentTarget !== e.target) return;\n if (options.includes(focusedOption as string)) {\n previousFocusedOption.current = focusedOption;\n setFocusedOption(null);\n }\n },\n }),\n [focusedOption, options, setFocusedOption],\n );\n const handleParentOnBlur = useOnBlurOut(config);\n\n const prevArrowKeys = useMemo(() => {\n if (direction === 'vertical') return ['ArrowUp'];\n if (direction === 'horizontal') return ['ArrowLeft'];\n return ['ArrowUp', 'ArrowLeft'];\n }, [direction]);\n const nextArrowKeys = useMemo(() => {\n if (direction === 'vertical') return ['ArrowDown'];\n if (direction === 'horizontal') return ['ArrowRight'];\n return ['ArrowDown', 'ArrowRight'];\n }, [direction]);\n const onKeyDown: React.KeyboardEventHandler = useCallback(\n (e) => {\n if (userOnKeyDown) userOnKeyDown(e);\n const { key } = e;\n const index = options.findIndex((option) => option === focusedOptionMutable.current);\n if (prevArrowKeys.includes(key)) {\n e.preventDefault();\n const previous = findInCircularList(options, index, focusCriteria, -1);\n setFocusedOption(options[previous]);\n } else if (nextArrowKeys.includes(key)) {\n e.preventDefault();\n const next = findInCircularList(options, index, focusCriteria, 1);\n\n setFocusedOption(options[next]);\n }\n },\n [userOnKeyDown, options, prevArrowKeys, nextArrowKeys, focusCriteria, setFocusedOption],\n );\n\n const getItemProps = useCallback(\n (dsId: string) => ({\n innerRef: (el: HTMLElement | null) => {\n if (el && dsId === focusedOption && focusedOptionMutable.current !== dsId) {\n el?.focus();\n }\n },\n onFocus: () => {\n setFocusedOption(dsId);\n focusedOptionMutable.current = dsId;\n },\n tabIndex: (disableRoving ||\n dsId === focusedOption ||\n (focusedOptionMutable.current === dsId && (focusedOption === null || !options.includes(focusedOption))) ||\n // (previousFocusedOption.current === dsId && focusedOption === null) ||\n (dsId === options[0] && focusedOptionMutable.current === null && previousFocusedOption.current === null)\n ? 0\n : -1) as TypescriptHelpersT.WCAGTabIndex,\n }),\n [disableRoving, focusedOption, options, setFocusedOption],\n );\n\n const getWrapperProps = useCallback(\n () => ({\n onKeyDown,\n onBlur: handleParentOnBlur,\n }),\n [onKeyDown, handleParentOnBlur],\n );\n\n return useMemo(\n () => ({ getWrapperProps, getItemProps, focusedOption, setFocusedOption }),\n [getWrapperProps, getItemProps, focusedOption, setFocusedOption],\n );\n};\n\nconst UseKeyboardNavigationWithSchema = describe(useKeyboardNavigation);\nUseKeyboardNavigationWithSchema.propTypes = propTypes;\n\nexport { useKeyboardNavigation, UseKeyboardNavigationWithSchema };\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAA6C;AAC7C,kCAAuD;AACvD,8BAAyB;AAGzB,IAAAA,gCAA0B;AAC1B,mBAAmC;AAEnC,MAAM,uBAAuB,MAAM;AACnC,MAAM,wBAAwB,CAAC,UAA2C;AACxE,QAAM;AAAA,IACJ;AAAA,IACA,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,WAAW;AAAA,IACX;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,4BAAwB,qBAAsB,IAAI;AACxD,QAAM,2BAAuB,qBAAsB,IAAI;AAEvD,QAAM,aAEF;AAAA,IACF,OAAO;AAAA,MACL,QAAQ,MAAM;AAEZ,YAAI,QAAQ,SAAS,aAAuB,GAAG;AAC7C,gCAAsB,UAAU;AAChC,2BAAiB,IAAI;AAAA,QACvB;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,eAAe,SAAS,gBAAgB;AAAA,EAC3C;AACA,QAAM,yBAAqB,0CAAa,MAAM;AAE9C,QAAM,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SAAS,aAAa;AAAA,MAEnG,SAAS,QAAQ,CAAC,KAAK,qBAAqB,YAAY,QAAQ,sBAAsB,YAAY,OAC/F,IACA;AAAA,IACN;AAAA,IACA,CAAC,eAAe,eAAe,SAAS,gBAAgB;AAAA,EAC1D;AAEA,QAAM,sBAAkB;AAAA,IACtB,OAAO;AAAA,MACL;AAAA,MACA,QAAQ;AAAA,IACV;AAAA,IACA,CAAC,WAAW,kBAAkB;AAAA,EAChC;AAEA,aAAO;AAAA,IACL,OAAO,EAAE,iBAAiB,cAAc,eAAe,iBAAiB;AAAA,IACxE,CAAC,iBAAiB,cAAc,eAAe,gBAAgB;AAAA,EACjE;AACF;AAEA,MAAM,sCAAkC,kCAAS,qBAAqB;AACtE,gCAAgC,YAAY;",
|
|
4
|
+
"sourcesContent": ["/* eslint-disable complexity */\nimport { useCallback, useMemo, useRef } from 'react';\nimport { useOnBlurOut, type DSHooksUseOBlurOutT } from '@elliemae/ds-hooks-on-blur-out';\nimport { describe } from '@elliemae/ds-props-helpers';\nimport { type TypescriptHelpersT } from '@elliemae/ds-typescript-helpers';\nimport { type DSHooksKeyboardNaviationT } from './react-desc-prop-types.js';\nimport { propTypes } from './react-desc-prop-types.js';\nimport { findInCircularList } from './utils.js';\n\nconst defaultFocusCriteria = () => true;\nconst useKeyboardNavigation = (props: DSHooksKeyboardNaviationT.Props) => {\n const {\n options,\n direction = 'agnostic',\n disableRoving = false,\n focusCriteria = defaultFocusCriteria,\n onKeyDown: userOnKeyDown,\n focusedOption,\n setFocusedOption,\n } = props;\n const previousFocusedOption = useRef<string | null>(null);\n const focusedOptionMutable = useRef<string | null>(null);\n\n const config: {\n onBlur: DSHooksUseOBlurOutT.OnBlurCb;\n } = useMemo(\n () => ({\n onBlur: () => {\n // if (e.currentTarget !== e.target) return;\n if (options.includes(focusedOption as string)) {\n previousFocusedOption.current = focusedOption;\n setFocusedOption(null);\n }\n },\n }),\n [focusedOption, options, setFocusedOption],\n );\n const handleParentOnBlur = useOnBlurOut(config);\n\n const prevArrowKeys = useMemo(() => {\n if (direction === 'vertical') return ['ArrowUp'];\n if (direction === 'horizontal') return ['ArrowLeft'];\n return ['ArrowUp', 'ArrowLeft'];\n }, [direction]);\n const nextArrowKeys = useMemo(() => {\n if (direction === 'vertical') return ['ArrowDown'];\n if (direction === 'horizontal') return ['ArrowRight'];\n return ['ArrowDown', 'ArrowRight'];\n }, [direction]);\n const onKeyDown: React.KeyboardEventHandler = useCallback(\n (e) => {\n if (userOnKeyDown) userOnKeyDown(e);\n const { key } = e;\n const index = options.findIndex((option) => option === focusedOptionMutable.current);\n if (prevArrowKeys.includes(key)) {\n e.preventDefault();\n const previous = findInCircularList(options, index, focusCriteria, -1);\n setFocusedOption(options[previous]);\n } else if (nextArrowKeys.includes(key)) {\n e.preventDefault();\n const next = findInCircularList(options, index, focusCriteria, 1);\n\n setFocusedOption(options[next]);\n }\n },\n [userOnKeyDown, options, prevArrowKeys, nextArrowKeys, focusCriteria, setFocusedOption],\n );\n\n const getItemProps = useCallback(\n (dsId: string) => ({\n innerRef: (el: HTMLElement | null) => {\n if (el && dsId === focusedOption && focusedOptionMutable.current !== dsId) {\n el?.focus();\n }\n },\n onFocus: () => {\n setFocusedOption(dsId);\n focusedOptionMutable.current = dsId;\n },\n tabIndex: (disableRoving ||\n dsId === focusedOption ||\n (focusedOptionMutable.current === dsId && (focusedOption === null || !options.includes(focusedOption))) ||\n // (previousFocusedOption.current === dsId && focusedOption === null) ||\n (dsId === options[0] && focusedOptionMutable.current === null && previousFocusedOption.current === null)\n ? 0\n : -1) as TypescriptHelpersT.WCAGTabIndex,\n }),\n [disableRoving, focusedOption, options, setFocusedOption],\n );\n\n const getWrapperProps = useCallback(\n () => ({\n onKeyDown,\n onBlur: handleParentOnBlur,\n }),\n [onKeyDown, handleParentOnBlur],\n );\n\n return useMemo(\n () => ({ getWrapperProps, getItemProps, focusedOption, setFocusedOption }),\n [getWrapperProps, getItemProps, focusedOption, setFocusedOption],\n );\n};\n\nuseKeyboardNavigation.displayName = 'useKeyboardNavigation';\nconst UseKeyboardNavigationWithSchema = describe(useKeyboardNavigation);\nUseKeyboardNavigationWithSchema.propTypes = propTypes;\n\nexport { useKeyboardNavigation, UseKeyboardNavigationWithSchema };\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAA6C;AAC7C,kCAAuD;AACvD,8BAAyB;AAGzB,IAAAA,gCAA0B;AAC1B,mBAAmC;AAEnC,MAAM,uBAAuB,MAAM;AACnC,MAAM,wBAAwB,CAAC,UAA2C;AACxE,QAAM;AAAA,IACJ;AAAA,IACA,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,WAAW;AAAA,IACX;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,4BAAwB,qBAAsB,IAAI;AACxD,QAAM,2BAAuB,qBAAsB,IAAI;AAEvD,QAAM,aAEF;AAAA,IACF,OAAO;AAAA,MACL,QAAQ,MAAM;AAEZ,YAAI,QAAQ,SAAS,aAAuB,GAAG;AAC7C,gCAAsB,UAAU;AAChC,2BAAiB,IAAI;AAAA,QACvB;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,eAAe,SAAS,gBAAgB;AAAA,EAC3C;AACA,QAAM,yBAAqB,0CAAa,MAAM;AAE9C,QAAM,oBAAgB,sBAAQ,MAAM;AAClC,QAAI,cAAc,WAAY,QAAO,CAAC,SAAS;AAC/C,QAAI,cAAc,aAAc,QAAO,CAAC,WAAW;AACnD,WAAO,CAAC,WAAW,WAAW;AAAA,EAChC,GAAG,CAAC,SAAS,CAAC;AACd,QAAM,oBAAgB,sBAAQ,MAAM;AAClC,QAAI,cAAc,WAAY,QAAO,CAAC,WAAW;AACjD,QAAI,cAAc,aAAc,QAAO,CAAC,YAAY;AACpD,WAAO,CAAC,aAAa,YAAY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,iBAAiB,cAAc,eAAe,iBAAiB;AAAA,IACxE,CAAC,iBAAiB,cAAc,eAAe,gBAAgB;AAAA,EACjE;AACF;AAEA,sBAAsB,cAAc;AACpC,MAAM,sCAAkC,kCAAS,qBAAqB;AACtE,gCAAgC,YAAY;",
|
|
6
6
|
"names": ["import_react_desc_prop_types"]
|
|
7
7
|
}
|
|
@@ -84,6 +84,7 @@ const useKeyboardNavigation = (props) => {
|
|
|
84
84
|
[getWrapperProps, getItemProps, focusedOption, setFocusedOption]
|
|
85
85
|
);
|
|
86
86
|
};
|
|
87
|
+
useKeyboardNavigation.displayName = "useKeyboardNavigation";
|
|
87
88
|
const UseKeyboardNavigationWithSchema = describe(useKeyboardNavigation);
|
|
88
89
|
UseKeyboardNavigationWithSchema.propTypes = propTypes;
|
|
89
90
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/DSHooksKeyboardNavigation.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\nimport { useCallback, useMemo, useRef } from 'react';\nimport { useOnBlurOut, type DSHooksUseOBlurOutT } from '@elliemae/ds-hooks-on-blur-out';\nimport { describe } from '@elliemae/ds-props-helpers';\nimport { type TypescriptHelpersT } from '@elliemae/ds-typescript-helpers';\nimport { type DSHooksKeyboardNaviationT } from './react-desc-prop-types.js';\nimport { propTypes } from './react-desc-prop-types.js';\nimport { findInCircularList } from './utils.js';\n\nconst defaultFocusCriteria = () => true;\nconst useKeyboardNavigation = (props: DSHooksKeyboardNaviationT.Props) => {\n const {\n options,\n direction = 'agnostic',\n disableRoving = false,\n focusCriteria = defaultFocusCriteria,\n onKeyDown: userOnKeyDown,\n focusedOption,\n setFocusedOption,\n } = props;\n const previousFocusedOption = useRef<string | null>(null);\n const focusedOptionMutable = useRef<string | null>(null);\n\n const config: {\n onBlur: DSHooksUseOBlurOutT.OnBlurCb;\n } = useMemo(\n () => ({\n onBlur: () => {\n // if (e.currentTarget !== e.target) return;\n if (options.includes(focusedOption as string)) {\n previousFocusedOption.current = focusedOption;\n setFocusedOption(null);\n }\n },\n }),\n [focusedOption, options, setFocusedOption],\n );\n const handleParentOnBlur = useOnBlurOut(config);\n\n const prevArrowKeys = useMemo(() => {\n if (direction === 'vertical') return ['ArrowUp'];\n if (direction === 'horizontal') return ['ArrowLeft'];\n return ['ArrowUp', 'ArrowLeft'];\n }, [direction]);\n const nextArrowKeys = useMemo(() => {\n if (direction === 'vertical') return ['ArrowDown'];\n if (direction === 'horizontal') return ['ArrowRight'];\n return ['ArrowDown', 'ArrowRight'];\n }, [direction]);\n const onKeyDown: React.KeyboardEventHandler = useCallback(\n (e) => {\n if (userOnKeyDown) userOnKeyDown(e);\n const { key } = e;\n const index = options.findIndex((option) => option === focusedOptionMutable.current);\n if (prevArrowKeys.includes(key)) {\n e.preventDefault();\n const previous = findInCircularList(options, index, focusCriteria, -1);\n setFocusedOption(options[previous]);\n } else if (nextArrowKeys.includes(key)) {\n e.preventDefault();\n const next = findInCircularList(options, index, focusCriteria, 1);\n\n setFocusedOption(options[next]);\n }\n },\n [userOnKeyDown, options, prevArrowKeys, nextArrowKeys, focusCriteria, setFocusedOption],\n );\n\n const getItemProps = useCallback(\n (dsId: string) => ({\n innerRef: (el: HTMLElement | null) => {\n if (el && dsId === focusedOption && focusedOptionMutable.current !== dsId) {\n el?.focus();\n }\n },\n onFocus: () => {\n setFocusedOption(dsId);\n focusedOptionMutable.current = dsId;\n },\n tabIndex: (disableRoving ||\n dsId === focusedOption ||\n (focusedOptionMutable.current === dsId && (focusedOption === null || !options.includes(focusedOption))) ||\n // (previousFocusedOption.current === dsId && focusedOption === null) ||\n (dsId === options[0] && focusedOptionMutable.current === null && previousFocusedOption.current === null)\n ? 0\n : -1) as TypescriptHelpersT.WCAGTabIndex,\n }),\n [disableRoving, focusedOption, options, setFocusedOption],\n );\n\n const getWrapperProps = useCallback(\n () => ({\n onKeyDown,\n onBlur: handleParentOnBlur,\n }),\n [onKeyDown, handleParentOnBlur],\n );\n\n return useMemo(\n () => ({ getWrapperProps, getItemProps, focusedOption, setFocusedOption }),\n [getWrapperProps, getItemProps, focusedOption, setFocusedOption],\n );\n};\n\nconst UseKeyboardNavigationWithSchema = describe(useKeyboardNavigation);\nUseKeyboardNavigationWithSchema.propTypes = propTypes;\n\nexport { useKeyboardNavigation, UseKeyboardNavigationWithSchema };\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACCvB,SAAS,aAAa,SAAS,cAAc;AAC7C,SAAS,oBAA8C;AACvD,SAAS,gBAAgB;AAGzB,SAAS,iBAAiB;AAC1B,SAAS,0BAA0B;AAEnC,MAAM,uBAAuB,MAAM;AACnC,MAAM,wBAAwB,CAAC,UAA2C;AACxE,QAAM;AAAA,IACJ;AAAA,IACA,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,WAAW;AAAA,IACX;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,wBAAwB,OAAsB,IAAI;AACxD,QAAM,uBAAuB,OAAsB,IAAI;AAEvD,QAAM,SAEF;AAAA,IACF,OAAO;AAAA,MACL,QAAQ,MAAM;AAEZ,YAAI,QAAQ,SAAS,aAAuB,GAAG;AAC7C,gCAAsB,UAAU;AAChC,2BAAiB,IAAI;AAAA,QACvB;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,eAAe,SAAS,gBAAgB;AAAA,EAC3C;AACA,QAAM,qBAAqB,aAAa,MAAM;AAE9C,QAAM,gBAAgB,QAAQ,MAAM;AAClC,QAAI,cAAc,WAAY,QAAO,CAAC,SAAS;AAC/C,QAAI,cAAc,aAAc,QAAO,CAAC,WAAW;AACnD,WAAO,CAAC,WAAW,WAAW;AAAA,EAChC,GAAG,CAAC,SAAS,CAAC;AACd,QAAM,gBAAgB,QAAQ,MAAM;AAClC,QAAI,cAAc,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AQ;AAAA,IACV;AAAA,IACA,CAAC,WAAW,kBAAkB;AAAA,EAChC;AAEA,SAAO;AAAA,IACL,OAAO,EAAE,iBAAiB,cAAc,eAAe,iBAAiB;AAAA,IACxE,CAAC,iBAAiB,cAAc,eAAe,gBAAgB;AAAA,EACjE;AACF;AAEA,MAAM,kCAAkC,SAAS,qBAAqB;AACtE,gCAAgC,YAAY;",
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\nimport { useCallback, useMemo, useRef } from 'react';\nimport { useOnBlurOut, type DSHooksUseOBlurOutT } from '@elliemae/ds-hooks-on-blur-out';\nimport { describe } from '@elliemae/ds-props-helpers';\nimport { type TypescriptHelpersT } from '@elliemae/ds-typescript-helpers';\nimport { type DSHooksKeyboardNaviationT } from './react-desc-prop-types.js';\nimport { propTypes } from './react-desc-prop-types.js';\nimport { findInCircularList } from './utils.js';\n\nconst defaultFocusCriteria = () => true;\nconst useKeyboardNavigation = (props: DSHooksKeyboardNaviationT.Props) => {\n const {\n options,\n direction = 'agnostic',\n disableRoving = false,\n focusCriteria = defaultFocusCriteria,\n onKeyDown: userOnKeyDown,\n focusedOption,\n setFocusedOption,\n } = props;\n const previousFocusedOption = useRef<string | null>(null);\n const focusedOptionMutable = useRef<string | null>(null);\n\n const config: {\n onBlur: DSHooksUseOBlurOutT.OnBlurCb;\n } = useMemo(\n () => ({\n onBlur: () => {\n // if (e.currentTarget !== e.target) return;\n if (options.includes(focusedOption as string)) {\n previousFocusedOption.current = focusedOption;\n setFocusedOption(null);\n }\n },\n }),\n [focusedOption, options, setFocusedOption],\n );\n const handleParentOnBlur = useOnBlurOut(config);\n\n const prevArrowKeys = useMemo(() => {\n if (direction === 'vertical') return ['ArrowUp'];\n if (direction === 'horizontal') return ['ArrowLeft'];\n return ['ArrowUp', 'ArrowLeft'];\n }, [direction]);\n const nextArrowKeys = useMemo(() => {\n if (direction === 'vertical') return ['ArrowDown'];\n if (direction === 'horizontal') return ['ArrowRight'];\n return ['ArrowDown', 'ArrowRight'];\n }, [direction]);\n const onKeyDown: React.KeyboardEventHandler = useCallback(\n (e) => {\n if (userOnKeyDown) userOnKeyDown(e);\n const { key } = e;\n const index = options.findIndex((option) => option === focusedOptionMutable.current);\n if (prevArrowKeys.includes(key)) {\n e.preventDefault();\n const previous = findInCircularList(options, index, focusCriteria, -1);\n setFocusedOption(options[previous]);\n } else if (nextArrowKeys.includes(key)) {\n e.preventDefault();\n const next = findInCircularList(options, index, focusCriteria, 1);\n\n setFocusedOption(options[next]);\n }\n },\n [userOnKeyDown, options, prevArrowKeys, nextArrowKeys, focusCriteria, setFocusedOption],\n );\n\n const getItemProps = useCallback(\n (dsId: string) => ({\n innerRef: (el: HTMLElement | null) => {\n if (el && dsId === focusedOption && focusedOptionMutable.current !== dsId) {\n el?.focus();\n }\n },\n onFocus: () => {\n setFocusedOption(dsId);\n focusedOptionMutable.current = dsId;\n },\n tabIndex: (disableRoving ||\n dsId === focusedOption ||\n (focusedOptionMutable.current === dsId && (focusedOption === null || !options.includes(focusedOption))) ||\n // (previousFocusedOption.current === dsId && focusedOption === null) ||\n (dsId === options[0] && focusedOptionMutable.current === null && previousFocusedOption.current === null)\n ? 0\n : -1) as TypescriptHelpersT.WCAGTabIndex,\n }),\n [disableRoving, focusedOption, options, setFocusedOption],\n );\n\n const getWrapperProps = useCallback(\n () => ({\n onKeyDown,\n onBlur: handleParentOnBlur,\n }),\n [onKeyDown, handleParentOnBlur],\n );\n\n return useMemo(\n () => ({ getWrapperProps, getItemProps, focusedOption, setFocusedOption }),\n [getWrapperProps, getItemProps, focusedOption, setFocusedOption],\n );\n};\n\nuseKeyboardNavigation.displayName = 'useKeyboardNavigation';\nconst UseKeyboardNavigationWithSchema = describe(useKeyboardNavigation);\nUseKeyboardNavigationWithSchema.propTypes = propTypes;\n\nexport { useKeyboardNavigation, UseKeyboardNavigationWithSchema };\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACCvB,SA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emae/ds-hooks-on-blur-out';
|
|
2
2
|
import { type TypescriptHelpersT } from '@elliemae/ds-typescript-helpers';
|
|
3
3
|
import { type DSHooksKeyboardNaviationT } from './react-desc-prop-types.js';
|
|
4
|
-
declare const useKeyboardNavigation:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
declare const useKeyboardNavigation: {
|
|
5
|
+
(props: DSHooksKeyboardNaviationT.Props): {
|
|
6
|
+
getWrapperProps: () => {
|
|
7
|
+
onKeyDown: import("react").KeyboardEventHandler<Element>;
|
|
8
|
+
onBlur: DSHooksUseOBlurOutT.OnBlurCb;
|
|
9
|
+
};
|
|
10
|
+
getItemProps: (dsId: string) => {
|
|
11
|
+
innerRef: (el: HTMLElement | null) => void;
|
|
12
|
+
onFocus: () => void;
|
|
13
|
+
tabIndex: TypescriptHelpersT.WCAGTabIndex;
|
|
14
|
+
};
|
|
15
|
+
focusedOption: string | null;
|
|
16
|
+
setFocusedOption: import("react").Dispatch<import("react").SetStateAction<string | null>>;
|
|
8
17
|
};
|
|
9
|
-
|
|
10
|
-
innerRef: (el: HTMLElement | null) => void;
|
|
11
|
-
onFocus: () => void;
|
|
12
|
-
tabIndex: TypescriptHelpersT.WCAGTabIndex;
|
|
13
|
-
};
|
|
14
|
-
focusedOption: string | null;
|
|
15
|
-
setFocusedOption: import("react").Dispatch<import("react").SetStateAction<string | null>>;
|
|
18
|
+
displayName: string;
|
|
16
19
|
};
|
|
17
20
|
declare const UseKeyboardNavigationWithSchema: import("@elliemae/ds-props-helpers/dist/types/propTypes/types.js").DocumentedReactComponent<DSHooksKeyboardNaviationT.Props>;
|
|
18
21
|
export { useKeyboardNavigation, UseKeyboardNavigationWithSchema };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-hooks-keyboard-navigation",
|
|
3
|
-
"version": "3.80.0-next.
|
|
3
|
+
"version": "3.80.0-next.80",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Hooks Keyboaord Navigation",
|
|
6
6
|
"files": [
|
|
@@ -36,15 +36,15 @@
|
|
|
36
36
|
"indent": 4
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@elliemae/ds-hooks-on-blur-out": "3.80.0-next.
|
|
40
|
-
"@elliemae/ds-
|
|
41
|
-
"@elliemae/ds-
|
|
39
|
+
"@elliemae/ds-hooks-on-blur-out": "3.80.0-next.80",
|
|
40
|
+
"@elliemae/ds-props-helpers": "3.80.0-next.80",
|
|
41
|
+
"@elliemae/ds-typescript-helpers": "3.80.0-next.80"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
+
"@elliemae/ds-monorepo-devops": "3.80.0-next.80",
|
|
44
45
|
"jest": "^30.0.0",
|
|
45
46
|
"styled-components": "~5.3.11",
|
|
46
|
-
"styled-system": "^5.1.5"
|
|
47
|
-
"@elliemae/ds-monorepo-devops": "3.80.0-next.8"
|
|
47
|
+
"styled-system": "^5.1.5"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"lodash-es": "^4.18.1",
|