@workday/canvas-kit-react 9.0.0-alpha.409-next.11 → 9.0.0-alpha.411-next.13

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 (26) hide show
  1. package/collection/lib/keyUtils.ts +88 -0
  2. package/collection/lib/useListItemRovingFocus.tsx +17 -100
  3. package/collection/lib/useListResetCursorOnBlur.tsx +1 -1
  4. package/dist/commonjs/collection/lib/keyUtils.d.ts +26 -0
  5. package/dist/commonjs/collection/lib/keyUtils.d.ts.map +1 -0
  6. package/dist/commonjs/collection/lib/keyUtils.js +80 -0
  7. package/dist/commonjs/collection/lib/useListItemRovingFocus.d.ts +0 -24
  8. package/dist/commonjs/collection/lib/useListItemRovingFocus.d.ts.map +1 -1
  9. package/dist/commonjs/collection/lib/useListItemRovingFocus.js +18 -94
  10. package/dist/commonjs/collection/lib/useListResetCursorOnBlur.js +2 -2
  11. package/dist/commonjs/menu/lib/MenuItem.d.ts +0 -2
  12. package/dist/commonjs/menu/lib/MenuItem.d.ts.map +1 -1
  13. package/dist/commonjs/tabs/lib/TabsItem.d.ts +0 -2
  14. package/dist/commonjs/tabs/lib/TabsItem.d.ts.map +1 -1
  15. package/dist/es6/collection/lib/keyUtils.d.ts +26 -0
  16. package/dist/es6/collection/lib/keyUtils.d.ts.map +1 -0
  17. package/dist/es6/collection/lib/keyUtils.js +76 -0
  18. package/dist/es6/collection/lib/useListItemRovingFocus.d.ts +0 -24
  19. package/dist/es6/collection/lib/useListItemRovingFocus.d.ts.map +1 -1
  20. package/dist/es6/collection/lib/useListItemRovingFocus.js +17 -93
  21. package/dist/es6/collection/lib/useListResetCursorOnBlur.js +1 -1
  22. package/dist/es6/menu/lib/MenuItem.d.ts +0 -2
  23. package/dist/es6/menu/lib/MenuItem.d.ts.map +1 -1
  24. package/dist/es6/tabs/lib/TabsItem.d.ts +0 -2
  25. package/dist/es6/tabs/lib/TabsItem.d.ts.map +1 -1
  26. package/package.json +3 -3
@@ -0,0 +1,88 @@
1
+ import React from 'react';
2
+ import {useCursorListModel} from './useCursorListModel';
3
+
4
+ export const orientationKeyMap = {
5
+ horizontal: {
6
+ ArrowLeft: 'goToPrevious',
7
+ Left: 'goToPrevious',
8
+ ArrowRight: 'goToNext',
9
+ Right: 'goToNext',
10
+ Home: 'goToFirst',
11
+ End: 'goToLast',
12
+ PageDown: 'goToNextPage',
13
+ PageUp: 'goToPreviousPage',
14
+ },
15
+ vertical: {
16
+ ArrowUp: 'goToPrevious',
17
+ Up: 'goToPrevious',
18
+ ArrowDown: 'goToNext',
19
+ Down: 'goToNext',
20
+ Home: 'goToFirst',
21
+ End: 'goToLast',
22
+ PageDown: 'goToNextPage',
23
+ PageUp: 'goToPreviousPage',
24
+ },
25
+ } as const;
26
+
27
+ const rightToLeftMap = {
28
+ ArrowLeft: 'ArrowRight',
29
+ Left: 'Right',
30
+ ArrowRight: 'ArrowLeft',
31
+ Right: 'Left',
32
+ Home: 'Home',
33
+ End: 'End',
34
+ PageDown: 'PageDown',
35
+ PageUp: 'PageUp',
36
+ } as const;
37
+
38
+ const gridKeyMap = {
39
+ ...orientationKeyMap.horizontal,
40
+ Home: 'goToFirstOfRow',
41
+ End: 'goToLastOfRow',
42
+ ArrowUp: 'goToPreviousRow',
43
+ Up: 'goToPreviousRow',
44
+ ArrowDown: 'goToNextRow',
45
+ Down: 'goToNextRow',
46
+ } as const;
47
+
48
+ const ctrlKeyMap = {
49
+ Home: 'goToFirst',
50
+ End: 'goToLast',
51
+ } as const;
52
+
53
+ const hasOwnKey = <T extends object>(obj: T, key: any): key is keyof T => obj.hasOwnProperty(key);
54
+
55
+ export function keyboardEventToCursorEvents(
56
+ event: React.KeyboardEvent,
57
+ model: ReturnType<typeof useCursorListModel>,
58
+ isRTL: boolean
59
+ ): boolean {
60
+ // Test ctrl key first
61
+ if (event.ctrlKey) {
62
+ for (const key in ctrlKeyMap) {
63
+ if (hasOwnKey(ctrlKeyMap, key)) {
64
+ if (event.key === key) {
65
+ model.events[ctrlKeyMap[key]]?.();
66
+ return true;
67
+ }
68
+ }
69
+ }
70
+ }
71
+ // Try regular keys
72
+ const map = model.state.columnCount > 0 ? gridKeyMap : orientationKeyMap[model.state.orientation];
73
+ for (const key in map) {
74
+ if (hasOwnKey(map, key)) {
75
+ if (isRTL ? event.key === rightToLeftMap[key] : event.key === key) {
76
+ const eventName =
77
+ model.state.columnCount > 0
78
+ ? gridKeyMap[key]
79
+ : orientationKeyMap[model.state.orientation][key];
80
+ if (model.events[eventName]) {
81
+ model.events[eventName]?.();
82
+ return true;
83
+ }
84
+ }
85
+ }
86
+ }
87
+ return false;
88
+ }
@@ -2,58 +2,7 @@ import React from 'react';
2
2
  import {useIsRTL, createElemPropsHook} from '@workday/canvas-kit-react/common';
3
3
 
4
4
  import {useCursorListModel} from './useCursorListModel';
5
-
6
- export const orientationKeyMap = {
7
- horizontal: {
8
- ArrowLeft: 'goToPrevious',
9
- Left: 'goToPrevious',
10
- ArrowRight: 'goToNext',
11
- Right: 'goToNext',
12
- Home: 'goToFirst',
13
- End: 'goToLast',
14
- PageDown: 'goToNextPage',
15
- PageUp: 'goToPreviousPage',
16
- },
17
- vertical: {
18
- ArrowUp: 'goToPrevious',
19
- Up: 'goToPrevious',
20
- ArrowDown: 'goToNext',
21
- Down: 'goToNext',
22
- Home: 'goToFirst',
23
- End: 'goToLast',
24
- PageDown: 'goToNextPage',
25
- PageUp: 'goToPreviousPage',
26
- },
27
- } as const;
28
-
29
- const rightToLeftMap = {
30
- ArrowLeft: 'ArrowRight',
31
- Left: 'Right',
32
- ArrowRight: 'ArrowLeft',
33
- Right: 'Left',
34
- Home: 'Home',
35
- End: 'End',
36
- PageDown: 'PageDown',
37
- PageUp: 'PageUp',
38
- } as const;
39
-
40
- const gridKeyMap = {
41
- ...orientationKeyMap.horizontal,
42
- Home: 'goToFirstOfRow',
43
- End: 'goToLastOfRow',
44
- ArrowUp: 'goToPreviousRow',
45
- Up: 'goToPreviousRow',
46
- ArrowDown: 'goToNextRow',
47
- Down: 'goToNextRow',
48
- } as const;
49
-
50
- const ctrlKeyMap = {
51
- Home: 'goToFirst',
52
- End: 'goToLast',
53
- } as const;
54
-
55
- const keys = <T extends object>(obj: T): (keyof T)[] => Object.keys(obj) as (keyof T)[];
56
- const hasOwnKey = <T extends object>(obj: T, key: any): key is keyof T => obj.hasOwnProperty(key);
5
+ import {keyboardEventToCursorEvents} from './keyUtils';
57
6
 
58
7
  /**
59
8
  * This elemProps hook is used for cursor navigation by using [Roving
@@ -70,29 +19,25 @@ const hasOwnKey = <T extends object>(obj: T, key: any): key is keyof T => obj.ha
70
19
  ```
71
20
  */
72
21
  export const useListItemRovingFocus = createElemPropsHook(useCursorListModel)(
73
- ({state, events, navigation}, ref, elemProps: {'data-id'?: string} = {}) => {
74
- // Tracks when this element has focus. If this item is removed while still focused, we have to
75
- // inform the model to move the cursor to the next item.
76
- const focusRef = React.useRef(false);
77
-
22
+ (model, ref, elemProps: {'data-id'?: string} = {}) => {
78
23
  // Create a ref out of state. We don't want to watch state on unmount, so we use a ref to get the
79
24
  // current value at the time of unmounting. Otherwise, `state.items` would be a cached value of an
80
25
  // empty array
81
- const stateRef = React.useRef(state);
82
- stateRef.current = state;
26
+ const stateRef = React.useRef(model.state);
27
+ stateRef.current = model.state;
83
28
 
84
29
  const keyDownRef = React.useRef(false);
85
30
  const isRTL = useIsRTL();
86
31
 
87
32
  React.useEffect(() => {
88
33
  if (keyDownRef.current) {
89
- const item = navigation.getItem(state.cursorId, {state});
90
- if (state.isVirtualized) {
91
- state.UNSTABLE_virtual.scrollToIndex(item.index);
34
+ const item = model.navigation.getItem(model.state.cursorId, model);
35
+ if (model.state.isVirtualized) {
36
+ model.state.UNSTABLE_virtual.scrollToIndex(item.index);
92
37
  }
93
38
  requestAnimationFrame(() => {
94
39
  document
95
- .querySelector<HTMLElement>(`[data-focus-id="${`${state.id}-${item.id}`}"]`)
40
+ .querySelector<HTMLElement>(`[data-focus-id="${`${model.state.id}-${item.id}`}"]`)
96
41
  ?.focus();
97
42
  });
98
43
 
@@ -100,51 +45,23 @@ export const useListItemRovingFocus = createElemPropsHook(useCursorListModel)(
100
45
  }
101
46
  // we only want to run this effect if the cursor changes and not any other time
102
47
  // eslint-disable-next-line react-hooks/exhaustive-deps
103
- }, [state.cursorId]);
48
+ }, [model.state.cursorId]);
104
49
 
105
50
  return {
106
51
  onKeyDown(event: React.KeyboardEvent) {
107
- // Test ctrl key first
108
- if (event.ctrlKey) {
109
- for (const key in ctrlKeyMap) {
110
- if (hasOwnKey(ctrlKeyMap, key)) {
111
- if (event.key === key) {
112
- keyDownRef.current = true;
113
- events[ctrlKeyMap[key]]?.();
114
- event.preventDefault();
115
- return;
116
- }
117
- }
118
- }
52
+ const handled = keyboardEventToCursorEvents(event, model, isRTL);
53
+ if (handled) {
54
+ event.preventDefault();
55
+ keyDownRef.current = true;
119
56
  }
120
- // Try regular keys
121
- keys(state.columnCount > 0 ? gridKeyMap : orientationKeyMap[state.orientation]).forEach(
122
- key => {
123
- if (isRTL ? event.key === rightToLeftMap[key] : event.key === key) {
124
- const eventName =
125
- state.columnCount > 0 ? gridKeyMap[key] : orientationKeyMap[state.orientation][key];
126
- keyDownRef.current = true;
127
- if (events[eventName]) {
128
- events[eventName]?.();
129
- event.preventDefault();
130
- }
131
- }
132
- }
133
- );
134
- },
135
- onFocus() {
136
- focusRef.current = true;
137
- },
138
- onBlur() {
139
- focusRef.current = false;
140
57
  },
141
58
  onClick() {
142
- events.goTo({id: elemProps['data-id']!});
59
+ model.events.goTo({id: elemProps['data-id']!});
143
60
  },
144
- 'data-focus-id': `${state.id}-${elemProps['data-id']}`,
145
- tabIndex: !state.cursorId
61
+ 'data-focus-id': `${model.state.id}-${elemProps['data-id']}`,
62
+ tabIndex: !model.state.cursorId
146
63
  ? 0 // cursor isn't known yet, be safe and mark this as focusable
147
- : !!elemProps['data-id'] && state.cursorId === elemProps['data-id']
64
+ : !!elemProps['data-id'] && model.state.cursorId === elemProps['data-id']
148
65
  ? 0 // A name is known and cursor is here
149
66
  : -1, // A name is known an cursor is somewhere else
150
67
  ref,
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
 
3
3
  import {createElemPropsHook} from '@workday/canvas-kit-react/common';
4
- import {orientationKeyMap} from './useListItemRovingFocus';
4
+ import {orientationKeyMap} from './keyUtils';
5
5
  import {useListModel} from './useListModel';
6
6
 
7
7
  /**
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { useCursorListModel } from './useCursorListModel';
3
+ export declare const orientationKeyMap: {
4
+ readonly horizontal: {
5
+ readonly ArrowLeft: "goToPrevious";
6
+ readonly Left: "goToPrevious";
7
+ readonly ArrowRight: "goToNext";
8
+ readonly Right: "goToNext";
9
+ readonly Home: "goToFirst";
10
+ readonly End: "goToLast";
11
+ readonly PageDown: "goToNextPage";
12
+ readonly PageUp: "goToPreviousPage";
13
+ };
14
+ readonly vertical: {
15
+ readonly ArrowUp: "goToPrevious";
16
+ readonly Up: "goToPrevious";
17
+ readonly ArrowDown: "goToNext";
18
+ readonly Down: "goToNext";
19
+ readonly Home: "goToFirst";
20
+ readonly End: "goToLast";
21
+ readonly PageDown: "goToNextPage";
22
+ readonly PageUp: "goToPreviousPage";
23
+ };
24
+ };
25
+ export declare function keyboardEventToCursorEvents(event: React.KeyboardEvent, model: ReturnType<typeof useCursorListModel>, isRTL: boolean): boolean;
26
+ //# sourceMappingURL=keyUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyUtils.d.ts","sourceRoot":"","sources":["../../../../collection/lib/keyUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAExD,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;CAqBpB,CAAC;AA8BX,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,KAAK,CAAC,aAAa,EAC1B,KAAK,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,EAC5C,KAAK,EAAE,OAAO,GACb,OAAO,CA6BT"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.keyboardEventToCursorEvents = exports.orientationKeyMap = void 0;
4
+ exports.orientationKeyMap = {
5
+ horizontal: {
6
+ ArrowLeft: 'goToPrevious',
7
+ Left: 'goToPrevious',
8
+ ArrowRight: 'goToNext',
9
+ Right: 'goToNext',
10
+ Home: 'goToFirst',
11
+ End: 'goToLast',
12
+ PageDown: 'goToNextPage',
13
+ PageUp: 'goToPreviousPage',
14
+ },
15
+ vertical: {
16
+ ArrowUp: 'goToPrevious',
17
+ Up: 'goToPrevious',
18
+ ArrowDown: 'goToNext',
19
+ Down: 'goToNext',
20
+ Home: 'goToFirst',
21
+ End: 'goToLast',
22
+ PageDown: 'goToNextPage',
23
+ PageUp: 'goToPreviousPage',
24
+ },
25
+ };
26
+ const rightToLeftMap = {
27
+ ArrowLeft: 'ArrowRight',
28
+ Left: 'Right',
29
+ ArrowRight: 'ArrowLeft',
30
+ Right: 'Left',
31
+ Home: 'Home',
32
+ End: 'End',
33
+ PageDown: 'PageDown',
34
+ PageUp: 'PageUp',
35
+ };
36
+ const gridKeyMap = {
37
+ ...exports.orientationKeyMap.horizontal,
38
+ Home: 'goToFirstOfRow',
39
+ End: 'goToLastOfRow',
40
+ ArrowUp: 'goToPreviousRow',
41
+ Up: 'goToPreviousRow',
42
+ ArrowDown: 'goToNextRow',
43
+ Down: 'goToNextRow',
44
+ };
45
+ const ctrlKeyMap = {
46
+ Home: 'goToFirst',
47
+ End: 'goToLast',
48
+ };
49
+ const hasOwnKey = (obj, key) => obj.hasOwnProperty(key);
50
+ function keyboardEventToCursorEvents(event, model, isRTL) {
51
+ var _a, _b, _c, _d;
52
+ // Test ctrl key first
53
+ if (event.ctrlKey) {
54
+ for (const key in ctrlKeyMap) {
55
+ if (hasOwnKey(ctrlKeyMap, key)) {
56
+ if (event.key === key) {
57
+ (_b = (_a = model.events)[ctrlKeyMap[key]]) === null || _b === void 0 ? void 0 : _b.call(_a);
58
+ return true;
59
+ }
60
+ }
61
+ }
62
+ }
63
+ // Try regular keys
64
+ const map = model.state.columnCount > 0 ? gridKeyMap : exports.orientationKeyMap[model.state.orientation];
65
+ for (const key in map) {
66
+ if (hasOwnKey(map, key)) {
67
+ if (isRTL ? event.key === rightToLeftMap[key] : event.key === key) {
68
+ const eventName = model.state.columnCount > 0
69
+ ? gridKeyMap[key]
70
+ : exports.orientationKeyMap[model.state.orientation][key];
71
+ if (model.events[eventName]) {
72
+ (_d = (_c = model.events)[eventName]) === null || _d === void 0 ? void 0 : _d.call(_c);
73
+ return true;
74
+ }
75
+ }
76
+ }
77
+ }
78
+ return false;
79
+ }
80
+ exports.keyboardEventToCursorEvents = keyboardEventToCursorEvents;
@@ -1,26 +1,4 @@
1
1
  import React from 'react';
2
- export declare const orientationKeyMap: {
3
- readonly horizontal: {
4
- readonly ArrowLeft: "goToPrevious";
5
- readonly Left: "goToPrevious";
6
- readonly ArrowRight: "goToNext";
7
- readonly Right: "goToNext";
8
- readonly Home: "goToFirst";
9
- readonly End: "goToLast";
10
- readonly PageDown: "goToNextPage";
11
- readonly PageUp: "goToPreviousPage";
12
- };
13
- readonly vertical: {
14
- readonly ArrowUp: "goToPrevious";
15
- readonly Up: "goToPrevious";
16
- readonly ArrowDown: "goToNext";
17
- readonly Down: "goToNext";
18
- readonly Home: "goToFirst";
19
- readonly End: "goToLast";
20
- readonly PageDown: "goToNextPage";
21
- readonly PageUp: "goToPreviousPage";
22
- };
23
- };
24
2
  /**
25
3
  * This elemProps hook is used for cursor navigation by using [Roving
26
4
  * Tabindex](https://w3c.github.io/aria-practices/#kbd_roving_tabindex). Only a single item in the
@@ -84,8 +62,6 @@ export declare const useListItemRovingFocus: import("@workday/canvas-kit-react/c
84
62
  getId: (item: any) => string;
85
63
  }, {
86
64
  onKeyDown(event: React.KeyboardEvent): void;
87
- onFocus(): void;
88
- onBlur(): void;
89
65
  onClick(): void;
90
66
  'data-focus-id': string;
91
67
  tabIndex: number;
@@ -1 +1 @@
1
- {"version":3,"file":"useListItemRovingFocus.d.ts","sourceRoot":"","sources":["../../../../collection/lib/useListItemRovingFocus.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;CAqBpB,CAAC;AA+BX;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAkCZ,mBAAmB;;;;;;;EA+CzC,CAAC"}
1
+ {"version":3,"file":"useListItemRovingFocus.d.ts","sourceRoot":"","sources":["../../../../collection/lib/useListItemRovingFocus.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA8BZ,mBAAmB;;;;;EAmBzC,CAAC"}
@@ -3,57 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useListItemRovingFocus = exports.orientationKeyMap = void 0;
6
+ exports.useListItemRovingFocus = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const common_1 = require("@workday/canvas-kit-react/common");
9
9
  const useCursorListModel_1 = require("./useCursorListModel");
10
- exports.orientationKeyMap = {
11
- horizontal: {
12
- ArrowLeft: 'goToPrevious',
13
- Left: 'goToPrevious',
14
- ArrowRight: 'goToNext',
15
- Right: 'goToNext',
16
- Home: 'goToFirst',
17
- End: 'goToLast',
18
- PageDown: 'goToNextPage',
19
- PageUp: 'goToPreviousPage',
20
- },
21
- vertical: {
22
- ArrowUp: 'goToPrevious',
23
- Up: 'goToPrevious',
24
- ArrowDown: 'goToNext',
25
- Down: 'goToNext',
26
- Home: 'goToFirst',
27
- End: 'goToLast',
28
- PageDown: 'goToNextPage',
29
- PageUp: 'goToPreviousPage',
30
- },
31
- };
32
- const rightToLeftMap = {
33
- ArrowLeft: 'ArrowRight',
34
- Left: 'Right',
35
- ArrowRight: 'ArrowLeft',
36
- Right: 'Left',
37
- Home: 'Home',
38
- End: 'End',
39
- PageDown: 'PageDown',
40
- PageUp: 'PageUp',
41
- };
42
- const gridKeyMap = {
43
- ...exports.orientationKeyMap.horizontal,
44
- Home: 'goToFirstOfRow',
45
- End: 'goToLastOfRow',
46
- ArrowUp: 'goToPreviousRow',
47
- Up: 'goToPreviousRow',
48
- ArrowDown: 'goToNextRow',
49
- Down: 'goToNextRow',
50
- };
51
- const ctrlKeyMap = {
52
- Home: 'goToFirst',
53
- End: 'goToLast',
54
- };
55
- const keys = (obj) => Object.keys(obj);
56
- const hasOwnKey = (obj, key) => obj.hasOwnProperty(key);
10
+ const keyUtils_1 = require("./keyUtils");
57
11
  /**
58
12
  * This elemProps hook is used for cursor navigation by using [Roving
59
13
  * Tabindex](https://w3c.github.io/aria-practices/#kbd_roving_tabindex). Only a single item in the
@@ -68,75 +22,45 @@ const hasOwnKey = (obj, key) => obj.hasOwnProperty(key);
68
22
  * );
69
23
  ```
70
24
  */
71
- exports.useListItemRovingFocus = common_1.createElemPropsHook(useCursorListModel_1.useCursorListModel)(({ state, events, navigation }, ref, elemProps = {}) => {
72
- // Tracks when this element has focus. If this item is removed while still focused, we have to
73
- // inform the model to move the cursor to the next item.
74
- const focusRef = react_1.default.useRef(false);
25
+ exports.useListItemRovingFocus = common_1.createElemPropsHook(useCursorListModel_1.useCursorListModel)((model, ref, elemProps = {}) => {
75
26
  // Create a ref out of state. We don't want to watch state on unmount, so we use a ref to get the
76
27
  // current value at the time of unmounting. Otherwise, `state.items` would be a cached value of an
77
28
  // empty array
78
- const stateRef = react_1.default.useRef(state);
79
- stateRef.current = state;
29
+ const stateRef = react_1.default.useRef(model.state);
30
+ stateRef.current = model.state;
80
31
  const keyDownRef = react_1.default.useRef(false);
81
32
  const isRTL = common_1.useIsRTL();
82
33
  react_1.default.useEffect(() => {
83
34
  if (keyDownRef.current) {
84
- const item = navigation.getItem(state.cursorId, { state });
85
- if (state.isVirtualized) {
86
- state.UNSTABLE_virtual.scrollToIndex(item.index);
35
+ const item = model.navigation.getItem(model.state.cursorId, model);
36
+ if (model.state.isVirtualized) {
37
+ model.state.UNSTABLE_virtual.scrollToIndex(item.index);
87
38
  }
88
39
  requestAnimationFrame(() => {
89
40
  var _a;
90
41
  (_a = document
91
- .querySelector(`[data-focus-id="${`${state.id}-${item.id}`}"]`)) === null || _a === void 0 ? void 0 : _a.focus();
42
+ .querySelector(`[data-focus-id="${`${model.state.id}-${item.id}`}"]`)) === null || _a === void 0 ? void 0 : _a.focus();
92
43
  });
93
44
  keyDownRef.current = false;
94
45
  }
95
46
  // we only want to run this effect if the cursor changes and not any other time
96
47
  // eslint-disable-next-line react-hooks/exhaustive-deps
97
- }, [state.cursorId]);
48
+ }, [model.state.cursorId]);
98
49
  return {
99
50
  onKeyDown(event) {
100
- var _a;
101
- // Test ctrl key first
102
- if (event.ctrlKey) {
103
- for (const key in ctrlKeyMap) {
104
- if (hasOwnKey(ctrlKeyMap, key)) {
105
- if (event.key === key) {
106
- keyDownRef.current = true;
107
- (_a = events[ctrlKeyMap[key]]) === null || _a === void 0 ? void 0 : _a.call(events);
108
- event.preventDefault();
109
- return;
110
- }
111
- }
112
- }
51
+ const handled = keyUtils_1.keyboardEventToCursorEvents(event, model, isRTL);
52
+ if (handled) {
53
+ event.preventDefault();
54
+ keyDownRef.current = true;
113
55
  }
114
- // Try regular keys
115
- keys(state.columnCount > 0 ? gridKeyMap : exports.orientationKeyMap[state.orientation]).forEach(key => {
116
- var _a;
117
- if (isRTL ? event.key === rightToLeftMap[key] : event.key === key) {
118
- const eventName = state.columnCount > 0 ? gridKeyMap[key] : exports.orientationKeyMap[state.orientation][key];
119
- keyDownRef.current = true;
120
- if (events[eventName]) {
121
- (_a = events[eventName]) === null || _a === void 0 ? void 0 : _a.call(events);
122
- event.preventDefault();
123
- }
124
- }
125
- });
126
- },
127
- onFocus() {
128
- focusRef.current = true;
129
- },
130
- onBlur() {
131
- focusRef.current = false;
132
56
  },
133
57
  onClick() {
134
- events.goTo({ id: elemProps['data-id'] });
58
+ model.events.goTo({ id: elemProps['data-id'] });
135
59
  },
136
- 'data-focus-id': `${state.id}-${elemProps['data-id']}`,
137
- tabIndex: !state.cursorId
60
+ 'data-focus-id': `${model.state.id}-${elemProps['data-id']}`,
61
+ tabIndex: !model.state.cursorId
138
62
  ? 0 // cursor isn't known yet, be safe and mark this as focusable
139
- : !!elemProps['data-id'] && state.cursorId === elemProps['data-id']
63
+ : !!elemProps['data-id'] && model.state.cursorId === elemProps['data-id']
140
64
  ? 0 // A name is known and cursor is here
141
65
  : -1,
142
66
  ref,
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.useListResetCursorOnBlur = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const common_1 = require("@workday/canvas-kit-react/common");
9
- const useListItemRovingFocus_1 = require("./useListItemRovingFocus");
9
+ const keyUtils_1 = require("./keyUtils");
10
10
  const useListModel_1 = require("./useListModel");
11
11
  /**
12
12
  * This elemProps hook resets the cursor when the list looses focus. By default,
@@ -27,7 +27,7 @@ exports.useListResetCursorOnBlur = common_1.createElemPropsHook(useListModel_1.u
27
27
  return {
28
28
  onKeyDown(event) {
29
29
  // Programmatic focus only on any focus change via keyboard
30
- if (Object.keys(useListItemRovingFocus_1.orientationKeyMap[state.orientation]).indexOf(event.key) !== -1) {
30
+ if (Object.keys(keyUtils_1.orientationKeyMap[state.orientation]).indexOf(event.key) !== -1) {
31
31
  programmaticFocusRef.current = true;
32
32
  }
33
33
  },
@@ -93,8 +93,6 @@ export declare const useMenuItem: import("@workday/canvas-kit-react/common").Beh
93
93
  onClick: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
94
94
  } & {
95
95
  onKeyDown(event: React.KeyboardEvent<Element>): void;
96
- onFocus(): void;
97
- onBlur(): void;
98
96
  onClick(): void;
99
97
  'data-focus-id': string;
100
98
  tabIndex: number;
@@ -1 +1 @@
1
- {"version":3,"file":"MenuItem.d.ts","sourceRoot":"","sources":["../../../../menu/lib/MenuItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAsB/B,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AA4FD,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBA0BF,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;EAazC,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBnB,CAAC"}
1
+ {"version":3,"file":"MenuItem.d.ts","sourceRoot":"","sources":["../../../../menu/lib/MenuItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAsB/B,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AA4FD,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBA0BF,MAAM,cAAc;;;;;;;;;;;;;;;;;;EAazC,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBnB,CAAC"}
@@ -228,8 +228,6 @@ export declare const useTabsItem: import("@workday/canvas-kit-react/common").Beh
228
228
  style: {};
229
229
  } & {
230
230
  onKeyDown(event: React.KeyboardEvent<Element>): void;
231
- onFocus(): void;
232
- onBlur(): void;
233
231
  onClick(): void;
234
232
  'data-focus-id': string;
235
233
  tabIndex: number;
@@ -1 +1 @@
1
- {"version":3,"file":"TabsItem.d.ts","sourceRoot":"","sources":["../../../../tabs/lib/TabsItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAIL,UAAU,EAGV,YAAY,EAKb,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAC,GAAG,EAAE,SAAS,EAAC,MAAM,kCAAkC,CAAC;AAYhE,MAAM,WAAW,aACf,SAAQ,YAAY,CAAC,OAAO,GAAG,EAAE,KAAK,CAAC,EACrC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACjC;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;;;;;;;OAaG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,aAAa;;;;oDAsFzB,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBvB,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiBnB,CAAC"}
1
+ {"version":3,"file":"TabsItem.d.ts","sourceRoot":"","sources":["../../../../tabs/lib/TabsItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAIL,UAAU,EAGV,YAAY,EAKb,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAC,GAAG,EAAE,SAAS,EAAC,MAAM,kCAAkC,CAAC;AAYhE,MAAM,WAAW,aACf,SAAQ,YAAY,CAAC,OAAO,GAAG,EAAE,KAAK,CAAC,EACrC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACjC;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;;;;;;;OAaG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,aAAa;;;;oDAsFzB,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBvB,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiBnB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { useCursorListModel } from './useCursorListModel';
3
+ export declare const orientationKeyMap: {
4
+ readonly horizontal: {
5
+ readonly ArrowLeft: "goToPrevious";
6
+ readonly Left: "goToPrevious";
7
+ readonly ArrowRight: "goToNext";
8
+ readonly Right: "goToNext";
9
+ readonly Home: "goToFirst";
10
+ readonly End: "goToLast";
11
+ readonly PageDown: "goToNextPage";
12
+ readonly PageUp: "goToPreviousPage";
13
+ };
14
+ readonly vertical: {
15
+ readonly ArrowUp: "goToPrevious";
16
+ readonly Up: "goToPrevious";
17
+ readonly ArrowDown: "goToNext";
18
+ readonly Down: "goToNext";
19
+ readonly Home: "goToFirst";
20
+ readonly End: "goToLast";
21
+ readonly PageDown: "goToNextPage";
22
+ readonly PageUp: "goToPreviousPage";
23
+ };
24
+ };
25
+ export declare function keyboardEventToCursorEvents(event: React.KeyboardEvent, model: ReturnType<typeof useCursorListModel>, isRTL: boolean): boolean;
26
+ //# sourceMappingURL=keyUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyUtils.d.ts","sourceRoot":"","sources":["../../../../collection/lib/keyUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAExD,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;CAqBpB,CAAC;AA8BX,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,KAAK,CAAC,aAAa,EAC1B,KAAK,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,EAC5C,KAAK,EAAE,OAAO,GACb,OAAO,CA6BT"}
@@ -0,0 +1,76 @@
1
+ export const orientationKeyMap = {
2
+ horizontal: {
3
+ ArrowLeft: 'goToPrevious',
4
+ Left: 'goToPrevious',
5
+ ArrowRight: 'goToNext',
6
+ Right: 'goToNext',
7
+ Home: 'goToFirst',
8
+ End: 'goToLast',
9
+ PageDown: 'goToNextPage',
10
+ PageUp: 'goToPreviousPage',
11
+ },
12
+ vertical: {
13
+ ArrowUp: 'goToPrevious',
14
+ Up: 'goToPrevious',
15
+ ArrowDown: 'goToNext',
16
+ Down: 'goToNext',
17
+ Home: 'goToFirst',
18
+ End: 'goToLast',
19
+ PageDown: 'goToNextPage',
20
+ PageUp: 'goToPreviousPage',
21
+ },
22
+ };
23
+ const rightToLeftMap = {
24
+ ArrowLeft: 'ArrowRight',
25
+ Left: 'Right',
26
+ ArrowRight: 'ArrowLeft',
27
+ Right: 'Left',
28
+ Home: 'Home',
29
+ End: 'End',
30
+ PageDown: 'PageDown',
31
+ PageUp: 'PageUp',
32
+ };
33
+ const gridKeyMap = {
34
+ ...orientationKeyMap.horizontal,
35
+ Home: 'goToFirstOfRow',
36
+ End: 'goToLastOfRow',
37
+ ArrowUp: 'goToPreviousRow',
38
+ Up: 'goToPreviousRow',
39
+ ArrowDown: 'goToNextRow',
40
+ Down: 'goToNextRow',
41
+ };
42
+ const ctrlKeyMap = {
43
+ Home: 'goToFirst',
44
+ End: 'goToLast',
45
+ };
46
+ const hasOwnKey = (obj, key) => obj.hasOwnProperty(key);
47
+ export function keyboardEventToCursorEvents(event, model, isRTL) {
48
+ var _a, _b, _c, _d;
49
+ // Test ctrl key first
50
+ if (event.ctrlKey) {
51
+ for (const key in ctrlKeyMap) {
52
+ if (hasOwnKey(ctrlKeyMap, key)) {
53
+ if (event.key === key) {
54
+ (_b = (_a = model.events)[ctrlKeyMap[key]]) === null || _b === void 0 ? void 0 : _b.call(_a);
55
+ return true;
56
+ }
57
+ }
58
+ }
59
+ }
60
+ // Try regular keys
61
+ const map = model.state.columnCount > 0 ? gridKeyMap : orientationKeyMap[model.state.orientation];
62
+ for (const key in map) {
63
+ if (hasOwnKey(map, key)) {
64
+ if (isRTL ? event.key === rightToLeftMap[key] : event.key === key) {
65
+ const eventName = model.state.columnCount > 0
66
+ ? gridKeyMap[key]
67
+ : orientationKeyMap[model.state.orientation][key];
68
+ if (model.events[eventName]) {
69
+ (_d = (_c = model.events)[eventName]) === null || _d === void 0 ? void 0 : _d.call(_c);
70
+ return true;
71
+ }
72
+ }
73
+ }
74
+ }
75
+ return false;
76
+ }
@@ -1,26 +1,4 @@
1
1
  import React from 'react';
2
- export declare const orientationKeyMap: {
3
- readonly horizontal: {
4
- readonly ArrowLeft: "goToPrevious";
5
- readonly Left: "goToPrevious";
6
- readonly ArrowRight: "goToNext";
7
- readonly Right: "goToNext";
8
- readonly Home: "goToFirst";
9
- readonly End: "goToLast";
10
- readonly PageDown: "goToNextPage";
11
- readonly PageUp: "goToPreviousPage";
12
- };
13
- readonly vertical: {
14
- readonly ArrowUp: "goToPrevious";
15
- readonly Up: "goToPrevious";
16
- readonly ArrowDown: "goToNext";
17
- readonly Down: "goToNext";
18
- readonly Home: "goToFirst";
19
- readonly End: "goToLast";
20
- readonly PageDown: "goToNextPage";
21
- readonly PageUp: "goToPreviousPage";
22
- };
23
- };
24
2
  /**
25
3
  * This elemProps hook is used for cursor navigation by using [Roving
26
4
  * Tabindex](https://w3c.github.io/aria-practices/#kbd_roving_tabindex). Only a single item in the
@@ -84,8 +62,6 @@ export declare const useListItemRovingFocus: import("@workday/canvas-kit-react/c
84
62
  getId: (item: any) => string;
85
63
  }, {
86
64
  onKeyDown(event: React.KeyboardEvent): void;
87
- onFocus(): void;
88
- onBlur(): void;
89
65
  onClick(): void;
90
66
  'data-focus-id': string;
91
67
  tabIndex: number;
@@ -1 +1 @@
1
- {"version":3,"file":"useListItemRovingFocus.d.ts","sourceRoot":"","sources":["../../../../collection/lib/useListItemRovingFocus.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;CAqBpB,CAAC;AA+BX;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAkCZ,mBAAmB;;;;;;;EA+CzC,CAAC"}
1
+ {"version":3,"file":"useListItemRovingFocus.d.ts","sourceRoot":"","sources":["../../../../collection/lib/useListItemRovingFocus.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA8BZ,mBAAmB;;;;;EAmBzC,CAAC"}
@@ -1,53 +1,7 @@
1
1
  import React from 'react';
2
2
  import { useIsRTL, createElemPropsHook } from '@workday/canvas-kit-react/common';
3
3
  import { useCursorListModel } from './useCursorListModel';
4
- export const orientationKeyMap = {
5
- horizontal: {
6
- ArrowLeft: 'goToPrevious',
7
- Left: 'goToPrevious',
8
- ArrowRight: 'goToNext',
9
- Right: 'goToNext',
10
- Home: 'goToFirst',
11
- End: 'goToLast',
12
- PageDown: 'goToNextPage',
13
- PageUp: 'goToPreviousPage',
14
- },
15
- vertical: {
16
- ArrowUp: 'goToPrevious',
17
- Up: 'goToPrevious',
18
- ArrowDown: 'goToNext',
19
- Down: 'goToNext',
20
- Home: 'goToFirst',
21
- End: 'goToLast',
22
- PageDown: 'goToNextPage',
23
- PageUp: 'goToPreviousPage',
24
- },
25
- };
26
- const rightToLeftMap = {
27
- ArrowLeft: 'ArrowRight',
28
- Left: 'Right',
29
- ArrowRight: 'ArrowLeft',
30
- Right: 'Left',
31
- Home: 'Home',
32
- End: 'End',
33
- PageDown: 'PageDown',
34
- PageUp: 'PageUp',
35
- };
36
- const gridKeyMap = {
37
- ...orientationKeyMap.horizontal,
38
- Home: 'goToFirstOfRow',
39
- End: 'goToLastOfRow',
40
- ArrowUp: 'goToPreviousRow',
41
- Up: 'goToPreviousRow',
42
- ArrowDown: 'goToNextRow',
43
- Down: 'goToNextRow',
44
- };
45
- const ctrlKeyMap = {
46
- Home: 'goToFirst',
47
- End: 'goToLast',
48
- };
49
- const keys = (obj) => Object.keys(obj);
50
- const hasOwnKey = (obj, key) => obj.hasOwnProperty(key);
4
+ import { keyboardEventToCursorEvents } from './keyUtils';
51
5
  /**
52
6
  * This elemProps hook is used for cursor navigation by using [Roving
53
7
  * Tabindex](https://w3c.github.io/aria-practices/#kbd_roving_tabindex). Only a single item in the
@@ -62,75 +16,45 @@ const hasOwnKey = (obj, key) => obj.hasOwnProperty(key);
62
16
  * );
63
17
  ```
64
18
  */
65
- export const useListItemRovingFocus = createElemPropsHook(useCursorListModel)(({ state, events, navigation }, ref, elemProps = {}) => {
66
- // Tracks when this element has focus. If this item is removed while still focused, we have to
67
- // inform the model to move the cursor to the next item.
68
- const focusRef = React.useRef(false);
19
+ export const useListItemRovingFocus = createElemPropsHook(useCursorListModel)((model, ref, elemProps = {}) => {
69
20
  // Create a ref out of state. We don't want to watch state on unmount, so we use a ref to get the
70
21
  // current value at the time of unmounting. Otherwise, `state.items` would be a cached value of an
71
22
  // empty array
72
- const stateRef = React.useRef(state);
73
- stateRef.current = state;
23
+ const stateRef = React.useRef(model.state);
24
+ stateRef.current = model.state;
74
25
  const keyDownRef = React.useRef(false);
75
26
  const isRTL = useIsRTL();
76
27
  React.useEffect(() => {
77
28
  if (keyDownRef.current) {
78
- const item = navigation.getItem(state.cursorId, { state });
79
- if (state.isVirtualized) {
80
- state.UNSTABLE_virtual.scrollToIndex(item.index);
29
+ const item = model.navigation.getItem(model.state.cursorId, model);
30
+ if (model.state.isVirtualized) {
31
+ model.state.UNSTABLE_virtual.scrollToIndex(item.index);
81
32
  }
82
33
  requestAnimationFrame(() => {
83
34
  var _a;
84
35
  (_a = document
85
- .querySelector(`[data-focus-id="${`${state.id}-${item.id}`}"]`)) === null || _a === void 0 ? void 0 : _a.focus();
36
+ .querySelector(`[data-focus-id="${`${model.state.id}-${item.id}`}"]`)) === null || _a === void 0 ? void 0 : _a.focus();
86
37
  });
87
38
  keyDownRef.current = false;
88
39
  }
89
40
  // we only want to run this effect if the cursor changes and not any other time
90
41
  // eslint-disable-next-line react-hooks/exhaustive-deps
91
- }, [state.cursorId]);
42
+ }, [model.state.cursorId]);
92
43
  return {
93
44
  onKeyDown(event) {
94
- var _a;
95
- // Test ctrl key first
96
- if (event.ctrlKey) {
97
- for (const key in ctrlKeyMap) {
98
- if (hasOwnKey(ctrlKeyMap, key)) {
99
- if (event.key === key) {
100
- keyDownRef.current = true;
101
- (_a = events[ctrlKeyMap[key]]) === null || _a === void 0 ? void 0 : _a.call(events);
102
- event.preventDefault();
103
- return;
104
- }
105
- }
106
- }
45
+ const handled = keyboardEventToCursorEvents(event, model, isRTL);
46
+ if (handled) {
47
+ event.preventDefault();
48
+ keyDownRef.current = true;
107
49
  }
108
- // Try regular keys
109
- keys(state.columnCount > 0 ? gridKeyMap : orientationKeyMap[state.orientation]).forEach(key => {
110
- var _a;
111
- if (isRTL ? event.key === rightToLeftMap[key] : event.key === key) {
112
- const eventName = state.columnCount > 0 ? gridKeyMap[key] : orientationKeyMap[state.orientation][key];
113
- keyDownRef.current = true;
114
- if (events[eventName]) {
115
- (_a = events[eventName]) === null || _a === void 0 ? void 0 : _a.call(events);
116
- event.preventDefault();
117
- }
118
- }
119
- });
120
- },
121
- onFocus() {
122
- focusRef.current = true;
123
- },
124
- onBlur() {
125
- focusRef.current = false;
126
50
  },
127
51
  onClick() {
128
- events.goTo({ id: elemProps['data-id'] });
52
+ model.events.goTo({ id: elemProps['data-id'] });
129
53
  },
130
- 'data-focus-id': `${state.id}-${elemProps['data-id']}`,
131
- tabIndex: !state.cursorId
54
+ 'data-focus-id': `${model.state.id}-${elemProps['data-id']}`,
55
+ tabIndex: !model.state.cursorId
132
56
  ? 0 // cursor isn't known yet, be safe and mark this as focusable
133
- : !!elemProps['data-id'] && state.cursorId === elemProps['data-id']
57
+ : !!elemProps['data-id'] && model.state.cursorId === elemProps['data-id']
134
58
  ? 0 // A name is known and cursor is here
135
59
  : -1,
136
60
  ref,
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { createElemPropsHook } from '@workday/canvas-kit-react/common';
3
- import { orientationKeyMap } from './useListItemRovingFocus';
3
+ import { orientationKeyMap } from './keyUtils';
4
4
  import { useListModel } from './useListModel';
5
5
  /**
6
6
  * This elemProps hook resets the cursor when the list looses focus. By default,
@@ -93,8 +93,6 @@ export declare const useMenuItem: import("@workday/canvas-kit-react/common").Beh
93
93
  onClick: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
94
94
  } & {
95
95
  onKeyDown(event: React.KeyboardEvent<Element>): void;
96
- onFocus(): void;
97
- onBlur(): void;
98
96
  onClick(): void;
99
97
  'data-focus-id': string;
100
98
  tabIndex: number;
@@ -1 +1 @@
1
- {"version":3,"file":"MenuItem.d.ts","sourceRoot":"","sources":["../../../../menu/lib/MenuItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAsB/B,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AA4FD,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBA0BF,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;EAazC,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBnB,CAAC"}
1
+ {"version":3,"file":"MenuItem.d.ts","sourceRoot":"","sources":["../../../../menu/lib/MenuItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAsB/B,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AA4FD,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBA0BF,MAAM,cAAc;;;;;;;;;;;;;;;;;;EAazC,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBnB,CAAC"}
@@ -228,8 +228,6 @@ export declare const useTabsItem: import("@workday/canvas-kit-react/common").Beh
228
228
  style: {};
229
229
  } & {
230
230
  onKeyDown(event: React.KeyboardEvent<Element>): void;
231
- onFocus(): void;
232
- onBlur(): void;
233
231
  onClick(): void;
234
232
  'data-focus-id': string;
235
233
  tabIndex: number;
@@ -1 +1 @@
1
- {"version":3,"file":"TabsItem.d.ts","sourceRoot":"","sources":["../../../../tabs/lib/TabsItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAIL,UAAU,EAGV,YAAY,EAKb,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAC,GAAG,EAAE,SAAS,EAAC,MAAM,kCAAkC,CAAC;AAYhE,MAAM,WAAW,aACf,SAAQ,YAAY,CAAC,OAAO,GAAG,EAAE,KAAK,CAAC,EACrC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACjC;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;;;;;;;OAaG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,aAAa;;;;oDAsFzB,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBvB,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiBnB,CAAC"}
1
+ {"version":3,"file":"TabsItem.d.ts","sourceRoot":"","sources":["../../../../tabs/lib/TabsItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAIL,UAAU,EAGV,YAAY,EAKb,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAC,GAAG,EAAE,SAAS,EAAC,MAAM,kCAAkC,CAAC;AAYhE,MAAM,WAAW,aACf,SAAQ,YAAY,CAAC,OAAO,GAAG,EAAE,KAAK,CAAC,EACrC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACjC;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;;;;;;;OAaG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,aAAa;;;;oDAsFzB,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBvB,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiBnB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workday/canvas-kit-react",
3
- "version": "9.0.0-alpha.409-next.11+ce4ca6f8",
3
+ "version": "9.0.0-alpha.411-next.13+45ee94ee",
4
4
  "description": "The parent module that contains all Workday Canvas Kit React components",
5
5
  "author": "Workday, Inc. (https://www.workday.com)",
6
6
  "license": "Apache-2.0",
@@ -49,7 +49,7 @@
49
49
  "@emotion/styled": "^11.6.0",
50
50
  "@popperjs/core": "^2.5.4",
51
51
  "@workday/canvas-colors-web": "^2.0.0",
52
- "@workday/canvas-kit-popup-stack": "^9.0.0-alpha.409-next.11+ce4ca6f8",
52
+ "@workday/canvas-kit-popup-stack": "^9.0.0-alpha.411-next.13+45ee94ee",
53
53
  "@workday/canvas-system-icons-web": "^3.0.0",
54
54
  "@workday/design-assets-types": "^0.2.8",
55
55
  "chroma-js": "^2.1.0",
@@ -66,5 +66,5 @@
66
66
  "@workday/canvas-accent-icons-web": "^3.0.0",
67
67
  "@workday/canvas-applet-icons-web": "^2.0.0"
68
68
  },
69
- "gitHead": "ce4ca6f8301d805a48b5b3694e873d98635939b5"
69
+ "gitHead": "45ee94ee899decb70dbf73bc22defa276f05899a"
70
70
  }