@workday/canvas-kit-preview-react 15.0.0-alpha.0074-next.0 → 15.0.0-alpha.0076-next.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 (125) hide show
  1. package/dist/commonjs/index.d.ts +0 -2
  2. package/dist/commonjs/index.d.ts.map +1 -1
  3. package/dist/commonjs/index.js +0 -2
  4. package/dist/commonjs/multi-select/lib/MultiSelectedItem.js +1 -1
  5. package/dist/es6/index.d.ts +0 -2
  6. package/dist/es6/index.d.ts.map +1 -1
  7. package/dist/es6/index.js +0 -2
  8. package/dist/es6/multi-select/lib/MultiSelectedItem.js +1 -1
  9. package/index.ts +0 -2
  10. package/multi-select/lib/MultiSelectedItem.tsx +1 -1
  11. package/package.json +4 -4
  12. package/dist/commonjs/pill/index.d.ts +0 -8
  13. package/dist/commonjs/pill/index.d.ts.map +0 -1
  14. package/dist/commonjs/pill/index.js +0 -23
  15. package/dist/commonjs/pill/lib/Pill.d.ts +0 -265
  16. package/dist/commonjs/pill/lib/Pill.d.ts.map +0 -1
  17. package/dist/commonjs/pill/lib/Pill.js +0 -147
  18. package/dist/commonjs/pill/lib/PillAvatar.d.ts +0 -526
  19. package/dist/commonjs/pill/lib/PillAvatar.d.ts.map +0 -1
  20. package/dist/commonjs/pill/lib/PillAvatar.js +0 -22
  21. package/dist/commonjs/pill/lib/PillCount.d.ts +0 -12
  22. package/dist/commonjs/pill/lib/PillCount.d.ts.map +0 -1
  23. package/dist/commonjs/pill/lib/PillCount.js +0 -21
  24. package/dist/commonjs/pill/lib/PillIcon.d.ts +0 -54
  25. package/dist/commonjs/pill/lib/PillIcon.d.ts.map +0 -1
  26. package/dist/commonjs/pill/lib/PillIcon.js +0 -20
  27. package/dist/commonjs/pill/lib/PillIconButton.d.ts +0 -148
  28. package/dist/commonjs/pill/lib/PillIconButton.d.ts.map +0 -1
  29. package/dist/commonjs/pill/lib/PillIconButton.js +0 -21
  30. package/dist/commonjs/pill/lib/PillLabel.d.ts +0 -14
  31. package/dist/commonjs/pill/lib/PillLabel.d.ts.map +0 -1
  32. package/dist/commonjs/pill/lib/PillLabel.js +0 -17
  33. package/dist/commonjs/pill/lib/usePillModel.d.ts +0 -46
  34. package/dist/commonjs/pill/lib/usePillModel.d.ts.map +0 -1
  35. package/dist/commonjs/pill/lib/usePillModel.js +0 -24
  36. package/dist/commonjs/select/index.d.ts +0 -3
  37. package/dist/commonjs/select/index.d.ts.map +0 -1
  38. package/dist/commonjs/select/index.js +0 -17
  39. package/dist/commonjs/select/lib/Select.d.ts +0 -31
  40. package/dist/commonjs/select/lib/Select.d.ts.map +0 -1
  41. package/dist/commonjs/select/lib/Select.js +0 -486
  42. package/dist/commonjs/select/lib/SelectBase.d.ts +0 -165
  43. package/dist/commonjs/select/lib/SelectBase.d.ts.map +0 -1
  44. package/dist/commonjs/select/lib/SelectBase.js +0 -235
  45. package/dist/commonjs/select/lib/SelectMenu.d.ts +0 -45
  46. package/dist/commonjs/select/lib/SelectMenu.d.ts.map +0 -1
  47. package/dist/commonjs/select/lib/SelectMenu.js +0 -195
  48. package/dist/commonjs/select/lib/SelectOption.d.ts +0 -38
  49. package/dist/commonjs/select/lib/SelectOption.d.ts.map +0 -1
  50. package/dist/commonjs/select/lib/SelectOption.js +0 -73
  51. package/dist/commonjs/select/lib/scrolling.d.ts +0 -5
  52. package/dist/commonjs/select/lib/scrolling.d.ts.map +0 -1
  53. package/dist/commonjs/select/lib/scrolling.js +0 -36
  54. package/dist/commonjs/select/lib/types.d.ts +0 -37
  55. package/dist/commonjs/select/lib/types.d.ts.map +0 -1
  56. package/dist/commonjs/select/lib/types.js +0 -2
  57. package/dist/commonjs/select/lib/utils.d.ts +0 -10
  58. package/dist/commonjs/select/lib/utils.d.ts.map +0 -1
  59. package/dist/commonjs/select/lib/utils.js +0 -27
  60. package/dist/es6/pill/index.d.ts +0 -8
  61. package/dist/es6/pill/index.d.ts.map +0 -1
  62. package/dist/es6/pill/index.js +0 -7
  63. package/dist/es6/pill/lib/Pill.d.ts +0 -265
  64. package/dist/es6/pill/lib/Pill.d.ts.map +0 -1
  65. package/dist/es6/pill/lib/Pill.js +0 -144
  66. package/dist/es6/pill/lib/PillAvatar.d.ts +0 -526
  67. package/dist/es6/pill/lib/PillAvatar.d.ts.map +0 -1
  68. package/dist/es6/pill/lib/PillAvatar.js +0 -19
  69. package/dist/es6/pill/lib/PillCount.d.ts +0 -12
  70. package/dist/es6/pill/lib/PillCount.d.ts.map +0 -1
  71. package/dist/es6/pill/lib/PillCount.js +0 -18
  72. package/dist/es6/pill/lib/PillIcon.d.ts +0 -54
  73. package/dist/es6/pill/lib/PillIcon.d.ts.map +0 -1
  74. package/dist/es6/pill/lib/PillIcon.js +0 -17
  75. package/dist/es6/pill/lib/PillIconButton.d.ts +0 -148
  76. package/dist/es6/pill/lib/PillIconButton.d.ts.map +0 -1
  77. package/dist/es6/pill/lib/PillIconButton.js +0 -18
  78. package/dist/es6/pill/lib/PillLabel.d.ts +0 -14
  79. package/dist/es6/pill/lib/PillLabel.d.ts.map +0 -1
  80. package/dist/es6/pill/lib/PillLabel.js +0 -14
  81. package/dist/es6/pill/lib/usePillModel.d.ts +0 -46
  82. package/dist/es6/pill/lib/usePillModel.d.ts.map +0 -1
  83. package/dist/es6/pill/lib/usePillModel.js +0 -21
  84. package/dist/es6/select/index.d.ts +0 -3
  85. package/dist/es6/select/index.d.ts.map +0 -1
  86. package/dist/es6/select/index.js +0 -1
  87. package/dist/es6/select/lib/Select.d.ts +0 -31
  88. package/dist/es6/select/lib/Select.d.ts.map +0 -1
  89. package/dist/es6/select/lib/Select.js +0 -460
  90. package/dist/es6/select/lib/SelectBase.d.ts +0 -165
  91. package/dist/es6/select/lib/SelectBase.d.ts.map +0 -1
  92. package/dist/es6/select/lib/SelectBase.js +0 -208
  93. package/dist/es6/select/lib/SelectMenu.d.ts +0 -45
  94. package/dist/es6/select/lib/SelectMenu.d.ts.map +0 -1
  95. package/dist/es6/select/lib/SelectMenu.js +0 -191
  96. package/dist/es6/select/lib/SelectOption.d.ts +0 -38
  97. package/dist/es6/select/lib/SelectOption.d.ts.map +0 -1
  98. package/dist/es6/select/lib/SelectOption.js +0 -69
  99. package/dist/es6/select/lib/scrolling.d.ts +0 -5
  100. package/dist/es6/select/lib/scrolling.d.ts.map +0 -1
  101. package/dist/es6/select/lib/scrolling.js +0 -32
  102. package/dist/es6/select/lib/types.d.ts +0 -37
  103. package/dist/es6/select/lib/types.d.ts.map +0 -1
  104. package/dist/es6/select/lib/types.js +0 -1
  105. package/dist/es6/select/lib/utils.d.ts +0 -10
  106. package/dist/es6/select/lib/utils.d.ts.map +0 -1
  107. package/dist/es6/select/lib/utils.js +0 -22
  108. package/pill/index.ts +0 -7
  109. package/pill/lib/Pill.tsx +0 -285
  110. package/pill/lib/PillAvatar.tsx +0 -35
  111. package/pill/lib/PillCount.tsx +0 -44
  112. package/pill/lib/PillIcon.tsx +0 -32
  113. package/pill/lib/PillIconButton.tsx +0 -86
  114. package/pill/lib/PillLabel.tsx +0 -32
  115. package/pill/lib/usePillModel.tsx +0 -23
  116. package/pill/package.json +0 -6
  117. package/select/index.ts +0 -8
  118. package/select/lib/Select.tsx +0 -595
  119. package/select/lib/SelectBase.tsx +0 -493
  120. package/select/lib/SelectMenu.tsx +0 -304
  121. package/select/lib/SelectOption.tsx +0 -133
  122. package/select/lib/scrolling.ts +0 -42
  123. package/select/lib/types.ts +0 -37
  124. package/select/lib/utils.ts +0 -30
  125. package/select/package.json +0 -6
@@ -1,486 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Select = void 0;
27
- const jsx_runtime_1 = require("react/jsx-runtime");
28
- const React = __importStar(require("react"));
29
- const common_1 = require("@workday/canvas-kit-react/common");
30
- const SelectMenu_1 = require("./SelectMenu");
31
- const SelectBase_1 = require("./SelectBase");
32
- const utils_1 = require("./utils");
33
- class SelectContainer extends React.Component {
34
- constructor(props) {
35
- super(props);
36
- this.state = {
37
- focusedOptionIndex: 0,
38
- menuVisibility: 'closed',
39
- };
40
- this.localButtonRef = React.createRef();
41
- this.inputRef = React.createRef();
42
- this.menuRef = React.createRef();
43
- // For type-ahead functionality
44
- this.keysSoFar = '';
45
- this.clearKeysSoFarTimeout = 500;
46
- // Cached values
47
- this.normalizedOptions = [];
48
- this.areOptionsDefined = () => {
49
- const { options } = this.props;
50
- if (!options || options.length === 0) {
51
- return false;
52
- }
53
- return true;
54
- };
55
- // Store normalized options since the options prop can take on multiple
56
- // forms. It can be an array of strings, an array of objects (sometimes with
57
- // arbitrary keys), or an array that contains both strings and objects
58
- this.setNormalizedOptions = () => {
59
- const { options } = this.props;
60
- // Abort if options weren't defined
61
- if (!this.areOptionsDefined()) {
62
- return;
63
- }
64
- this.normalizedOptions = options.map(option => {
65
- let data = {};
66
- let disabled, id, label, value;
67
- if (typeof option === 'string') {
68
- disabled = false;
69
- id = (0, common_1.generateUniqueId)();
70
- value = option;
71
- label = option;
72
- }
73
- else {
74
- data = option.data || data;
75
- disabled = !!option.disabled;
76
- id = option.id || (0, common_1.generateUniqueId)();
77
- value = option.value;
78
- label = option.label || option.value;
79
- }
80
- return {
81
- data,
82
- disabled,
83
- id,
84
- label,
85
- value,
86
- };
87
- });
88
- };
89
- this.getIndexByStartString = (startIndex, startString, endIndex = this.normalizedOptions.length, ignoreDisabled = true) => {
90
- for (let i = startIndex; i < endIndex; i++) {
91
- const label = this.normalizedOptions[i].label.toLowerCase();
92
- if (label.indexOf(startString.toLowerCase()) === 0) {
93
- if (!ignoreDisabled || (ignoreDisabled && !this.normalizedOptions[i].disabled)) {
94
- return i;
95
- }
96
- }
97
- }
98
- return -1;
99
- };
100
- // This helper focuses the next enabled option given a startIndex and a
101
- // direction. If startIndex refers to an enabled option, we focus that option
102
- // immediately. Otherwise, we advance `direction` number of spaces in the options
103
- // array and check again if that index refers to an enabled option.
104
- //
105
- // This is useful for manipulating focus using the keyboard where pressing the
106
- // Up/Down key means "focus the first enabled option above/below the currently
107
- // focused option", or pressing the Home/End key means "focus the first/last
108
- // enabled option on the menu."
109
- this.focusNextEnabledOption = (startIndex, direction) => {
110
- // Ensure direction is non-zero
111
- if (direction === 0) {
112
- return;
113
- }
114
- const numOptions = this.normalizedOptions.length;
115
- let currentIndex = startIndex;
116
- // Check if currentIndex refers to an enabled option. If not, keep moving
117
- // the index in the prescribed direction until we find an enabled option.
118
- while (currentIndex >= 0 &&
119
- currentIndex < numOptions &&
120
- this.normalizedOptions[currentIndex].disabled) {
121
- currentIndex += direction;
122
- }
123
- // Update the focused index only if currentIndex is inbounds and
124
- // refers to an enabled option
125
- if (currentIndex >= 0 &&
126
- currentIndex < numOptions &&
127
- !this.normalizedOptions[currentIndex].disabled) {
128
- this.setState({ focusedOptionIndex: currentIndex });
129
- }
130
- };
131
- this.updateStateFromValue = () => {
132
- this.setState({
133
- focusedOptionIndex: (0, utils_1.getCorrectedIndexByValue)(this.normalizedOptions, this.props.value),
134
- });
135
- };
136
- this.focusButton = () => {
137
- if (this.localButtonRef.current) {
138
- this.localButtonRef.current.focus();
139
- }
140
- };
141
- this.setMenuAnimationTimeout = (callback) => {
142
- if (this.menuAnimationTimer) {
143
- clearTimeout(this.menuAnimationTimer);
144
- }
145
- this.menuAnimationTimer = setTimeout(callback, SelectMenu_1.menuAnimationDuration);
146
- };
147
- this.openMenu = () => {
148
- this.setState({ menuVisibility: 'opening' });
149
- this.setMenuAnimationTimeout(() => {
150
- this.setState({ menuVisibility: 'opened' });
151
- });
152
- };
153
- this.closeMenu = () => {
154
- this.setState({ menuVisibility: 'closing' });
155
- this.setMenuAnimationTimeout(() => {
156
- this.setState({
157
- // Reset the focused option to the currently selected option in case
158
- // the user focused a different option but chose not to select it. The
159
- // next time the menu opens, focus should begin on the selected option.
160
- focusedOptionIndex: (0, utils_1.getCorrectedIndexByValue)(this.normalizedOptions, this.props.value),
161
- menuVisibility: 'closed',
162
- });
163
- });
164
- };
165
- this.toggleMenu = (open) => {
166
- const { menuVisibility } = this.state;
167
- if (open) {
168
- switch (menuVisibility) {
169
- // We're opening a menu which is currently closed: set the menu state
170
- // to open before kicking off openMenu. This allows us to transition
171
- // from 0 opacity in the open state to the targeted 1.0 opacity in
172
- // the opening state.
173
- case 'closed':
174
- this.setState({ menuVisibility: 'open' }, this.openMenu);
175
- break;
176
- // We're opening a menu which is in the process of closing. Since the
177
- // menu isn't closed, there's no need to set the open state: kick off
178
- // openMenu immediately.
179
- case 'close':
180
- case 'closing':
181
- this.openMenu();
182
- break;
183
- // Otherwise, we're opening a menu is already opened or in the process of
184
- // opening; no need to do anything further.
185
- default:
186
- break;
187
- }
188
- }
189
- else {
190
- switch (menuVisibility) {
191
- // We're closing a menu which is currently opened: set the menu state to
192
- // close before kicking off closeMenu.
193
- case 'opened':
194
- this.setState({ menuVisibility: 'close' }, this.closeMenu);
195
- break;
196
- // We're closing a menu which is in the process of opening. Since the
197
- // menu isn't opened, there's no need to set the close state: kick off
198
- // closeMenu immediately.
199
- case 'open':
200
- case 'opening':
201
- this.closeMenu();
202
- break;
203
- // Otherwise, we're closing a menu which is already closed or in the process
204
- // of closing; no need to do anything further.
205
- default:
206
- break;
207
- }
208
- }
209
- };
210
- // Code inspired by: https://stackoverflow.com/a/46012210
211
- // In order for Select to be usable as a controlled component, we
212
- // need to programmatically change the value of the SelectInput
213
- // in such a way that triggers its change event
214
- this.fireChangeEvent = (value) => {
215
- if (this.inputRef && this.inputRef.current) {
216
- const nativeInputValue = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.inputRef.current), 'value');
217
- if (nativeInputValue && nativeInputValue.set) {
218
- nativeInputValue.set.call(this.inputRef.current, value);
219
- }
220
- let event;
221
- if (typeof Event === 'function') {
222
- // Modern browsers
223
- event = new Event('change', { bubbles: true });
224
- }
225
- else {
226
- // IE 11
227
- event = document.createEvent('Event');
228
- event.initEvent('change', true, true);
229
- }
230
- this.inputRef.current.dispatchEvent(event);
231
- }
232
- };
233
- this.handleKeyboardTypeAhead = (key, numOptions) => {
234
- // Abort immediately if the menu is the process of closing
235
- if (this.state.menuVisibility === 'closing') {
236
- return;
237
- }
238
- // Set the starting point of the search to one of two locations
239
- // based on the search string so far (keysSoFar):
240
- //
241
- // 1. If the search string is empty, start the search from the
242
- // next option AFTER the currently focused option. For example,
243
- // if the Select is currently focused on "San Francisco", typing
244
- // "s" again advances focus to the next option that begins with "s".
245
- //
246
- // 2. If the search string is populated, start the search from the
247
- // CURRENTLY focused option. For example, if the Select is currently
248
- // focused on "San Francisco", typing "san j" retains focus on
249
- // "San Francisco" as you type "san " (because "san " still matches
250
- // "San Francisco") and then advances focus to "San Jose" after you
251
- // type the "j" at the end.
252
- let start = this.keysSoFar.length === 0
253
- ? this.state.focusedOptionIndex + 1
254
- : this.state.focusedOptionIndex;
255
- // If the starting point is beyond the list of options, reset it
256
- // to the beginning of the list
257
- start = start === numOptions ? 0 : start;
258
- this.keysSoFar += key;
259
- this.startClearKeysSoFarTimer();
260
- // First, look for a match from start to end
261
- let matchIndex;
262
- matchIndex = this.getIndexByStartString(start, this.keysSoFar);
263
- // If a match isn't found between start and end, wrap the search
264
- // around and search again from the beginning (0) to start
265
- if (matchIndex === -1) {
266
- matchIndex = this.getIndexByStartString(0, this.keysSoFar, start);
267
- }
268
- // A match was found...
269
- if (matchIndex > -1) {
270
- if (this.state.menuVisibility === 'closed') {
271
- // If the menu is closed, fire the change event
272
- this.fireChangeEvent(this.normalizedOptions[matchIndex].value);
273
- }
274
- else {
275
- // Otherwise the menu is visible (or at least partially visible);
276
- // focus the matched option
277
- this.setState({ focusedOptionIndex: matchIndex });
278
- }
279
- }
280
- };
281
- this.startClearKeysSoFarTimer = () => {
282
- if (this.clearKeysSoFarTimer) {
283
- clearTimeout(this.clearKeysSoFarTimer);
284
- }
285
- this.clearKeysSoFarTimer = setTimeout(() => {
286
- this.keysSoFar = '';
287
- }, this.clearKeysSoFarTimeout);
288
- };
289
- this.handleClick = (event) => {
290
- const { menuVisibility } = this.state;
291
- switch (menuVisibility) {
292
- // If we click the button while the menu is in the process of closing,
293
- // we want to toggle the menu back on. However, we also need to focus
294
- // the menu since it won't be focused using Popper's onFirstUpdate
295
- // callback (because the menu already exists).
296
- case 'close':
297
- case 'closing':
298
- if (this.menuRef.current) {
299
- this.menuRef.current.focus();
300
- }
301
- this.toggleMenu(true);
302
- break;
303
- case 'closed':
304
- this.toggleMenu(true);
305
- break;
306
- // Otherwise, the menu is opened or in the process of opening; toggle
307
- // the menu off.
308
- default:
309
- this.toggleMenu(false);
310
- break;
311
- }
312
- };
313
- this.handleOptionSelection = (index) => {
314
- // Abort if a disabled option was clicked (we ignore these clicks)
315
- if (this.normalizedOptions[index].disabled) {
316
- return;
317
- }
318
- // Toggle menu off, shift focus back to the button, and fire change event
319
- this.toggleMenu(false);
320
- this.focusButton();
321
- this.fireChangeEvent(this.normalizedOptions[index].value);
322
- };
323
- this.handleMenuCloseOnKeyPress = () => {
324
- // Toggle menu off and shift focus back to the button
325
- this.handleClose();
326
- this.focusButton();
327
- };
328
- this.handleClose = () => {
329
- this.toggleMenu(false);
330
- };
331
- this.handleKeyDown = (event) => {
332
- const { options } = this.props;
333
- const numOptions = options.length;
334
- const { focusedOptionIndex, menuVisibility } = this.state;
335
- let isShortcut = false;
336
- // Check for type-ahead first
337
- if (event.key.length === 1 && event.key.match(/\S/)) {
338
- isShortcut = true;
339
- this.handleKeyboardTypeAhead(event.key, numOptions);
340
- }
341
- else {
342
- switch (event.key) {
343
- case 'ArrowUp':
344
- case 'Up': // IE/Edge specific value
345
- case 'ArrowDown':
346
- case 'Down': // IE/Edge specific value
347
- isShortcut = true;
348
- if (menuVisibility === 'closed' || menuVisibility === 'closing') {
349
- this.toggleMenu(true);
350
- }
351
- else {
352
- const direction = event.key === 'ArrowUp' || event.key === 'Up' ? -1 : 1;
353
- const startIndex = focusedOptionIndex + direction;
354
- this.focusNextEnabledOption(startIndex, direction);
355
- }
356
- break;
357
- case 'Home':
358
- case 'End':
359
- isShortcut = true;
360
- const direction = event.key === 'Home' ? 1 : -1;
361
- const startIndex = event.key === 'Home' ? 0 : numOptions - 1;
362
- this.focusNextEnabledOption(startIndex, direction);
363
- break;
364
- case 'Tab':
365
- if (menuVisibility !== 'closed') {
366
- isShortcut = true;
367
- this.handleMenuCloseOnKeyPress();
368
- }
369
- break;
370
- case 'Spacebar':
371
- case ' ':
372
- isShortcut = true;
373
- // If the user is in the middle of typing a string, treat
374
- // space key as type-ahead rather than option selection
375
- if (this.keysSoFar !== '') {
376
- this.handleKeyboardTypeAhead(' ', numOptions);
377
- }
378
- else if (menuVisibility === 'closed' || menuVisibility === 'closing') {
379
- this.toggleMenu(true);
380
- }
381
- else {
382
- this.handleOptionSelection(focusedOptionIndex);
383
- }
384
- break;
385
- case 'Enter':
386
- isShortcut = true;
387
- if (menuVisibility === 'closed' || menuVisibility === 'closing') {
388
- // allow the click
389
- isShortcut = false;
390
- }
391
- else {
392
- this.handleOptionSelection(focusedOptionIndex);
393
- }
394
- break;
395
- default:
396
- }
397
- }
398
- if (isShortcut) {
399
- // Call stopPropagation here to limit shortcut key handling to the Select
400
- // component. Otherwise, for example, using the typeahead feature of the
401
- // Select would end up triggering a number of undesired if actions if the
402
- // containing application supports its own keyboard shortcuts.
403
- event.stopPropagation();
404
- // Call preventDefault here to maintain control of what happens when
405
- // handling shortcut keys. For example, without this call, pressing the
406
- // down arrow key would scroll the menu down (since the menu has DOM
407
- // focus while its visible and scrolling is the default behavior of the
408
- // down arrow key). Instead, we want to provide our own custom behavior
409
- // of assistively focusing the next option.
410
- event.preventDefault();
411
- }
412
- };
413
- this.setNormalizedOptions();
414
- // We need a local ref (RefObject) to the Select component's underlying
415
- // button to manage focus within the component and to serve as its Popper
416
- // Menu's anchorElement. If the buttonRef prop (to be forwarded to the
417
- // underlying button) passed in through createComponent was a ref object,
418
- // we could reuse it for our internal purposes. buttonRef may be a callback
419
- // ref, however, or it may not even be defined.
420
- //
421
- // To guarantee we have access to a ref object, we created one earlier when
422
- // declaring the localButtonRef instance variable. We then use useForkRef
423
- // to combine localButtonRef and buttonRef into a single callback ref
424
- // (forwardedButtonRef) which can be forwarded to the underlying button.
425
- // When the component mounts/unmounts, this callback will both:
426
- //
427
- // (1) Update the current value of localButtonRef, and;
428
- // (2) Either update the current value of buttonRef if it was a ref object,
429
- // or call buttonRef with the underlying button element if it was a
430
- // callback ref.
431
- // eslint-disable-next-line react-hooks/rules-of-hooks
432
- this.forwardedButtonRef = (0, common_1.useForkRef)(props.buttonRef, this.localButtonRef);
433
- }
434
- componentDidMount() {
435
- this.updateStateFromValue();
436
- }
437
- componentDidUpdate(prevProps) {
438
- const { options, value } = this.props;
439
- if (options !== prevProps.options) {
440
- this.setNormalizedOptions();
441
- this.updateStateFromValue();
442
- }
443
- if (value !== prevProps.value) {
444
- this.updateStateFromValue();
445
- }
446
- }
447
- componentWillUnmount() {
448
- // Clear timers
449
- if (this.menuAnimationTimer) {
450
- clearTimeout(this.menuAnimationTimer);
451
- }
452
- if (this.clearKeysSoFarTimer) {
453
- clearTimeout(this.clearKeysSoFarTimer);
454
- }
455
- }
456
- render() {
457
- const { value,
458
- // Strip props we don't want to pass down from elemProps
459
- buttonRef, options, onKeyDown, onBlur, ...elemProps } = this.props;
460
- const { focusedOptionIndex, menuVisibility } = this.state;
461
- // Don't pass in event handlers if options weren't defined
462
- const eventHandlers = this.areOptionsDefined()
463
- ? {
464
- onClick: this.handleClick,
465
- onKeyDown: this.handleKeyDown,
466
- onClose: this.handleClose,
467
- onOptionSelection: this.handleOptionSelection,
468
- }
469
- : {};
470
- return ((0, jsx_runtime_1.jsx)(SelectBase_1.SelectBase, { forwardedButtonRef: this.forwardedButtonRef, localButtonRef: this.localButtonRef, focusedOptionIndex: focusedOptionIndex, inputRef: this.inputRef, menuRef: this.menuRef, menuVisibility: menuVisibility, options: this.normalizedOptions, value: value, ...eventHandlers, ...elemProps }));
471
- }
472
- }
473
- SelectContainer.ErrorType = common_1.ErrorType;
474
- /**
475
- * @deprecated ⚠️ `Select` in Preview has been deprecated and will be removed in a future major version. Please use [`Select` in Main](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--docs) instead.
476
- */
477
- exports.Select = (0, common_1.createComponent)('button')({
478
- displayName: 'Select',
479
- Component: (props, ref, Element) => (
480
- // Select is still a class component, so we render a renamed version of it
481
- // (SelectContainer) and pass it ref and Element
482
- (0, jsx_runtime_1.jsx)(SelectContainer, { as: Element, buttonRef: ref, ...props })),
483
- subComponents: {
484
- ErrorType: common_1.ErrorType,
485
- },
486
- });
@@ -1,165 +0,0 @@
1
- import React from 'react';
2
- import { GrowthBehavior, ErrorType, StyledType, Themeable } from '@workday/canvas-kit-react/common';
3
- import { MenuPlacement, MenuVisibility } from './types';
4
- interface OptionData {
5
- [key: string]: any;
6
- }
7
- /**
8
- * @deprecated ⚠️ `Option` in Preview has been deprecated and will be removed in a future major version. Please use [`Select` in Main](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--docs) instead.
9
- */
10
- export interface Option {
11
- data?: OptionData;
12
- disabled?: boolean;
13
- id?: string;
14
- label?: string;
15
- value: string;
16
- }
17
- /**
18
- * @deprecated ⚠️ `NormalizedOption` in Preview has been deprecated and will be removed in a future major version. Please use [`Select` in Main](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--docs) instead.
19
- */
20
- export interface NormalizedOption extends Option {
21
- data: OptionData;
22
- disabled: boolean;
23
- id: string;
24
- label: string;
25
- }
26
- /**
27
- * @deprecated ⚠️ `RenderSelectedFunction` in Preview has been deprecated and will be removed in a future major version. Please use [`Select` in Main](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--docs) instead.
28
- */
29
- export interface RenderSelectedFunction {
30
- (option: NormalizedOption): React.ReactNode;
31
- }
32
- /**
33
- * @deprecated ⚠️ `RenderableOption` in Preview has been deprecated and will be removed in a future major version. Please use [`Select` in Main](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--docs) instead.
34
- */
35
- export interface RenderableOption extends NormalizedOption {
36
- focused: boolean;
37
- selected: boolean;
38
- }
39
- /**
40
- * @deprecated ⚠️ `RenderOptionFunction` in Preview has been deprecated and will be removed in a future major version. Please use [`Select` in Main](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--docs) instead.
41
- */
42
- export interface RenderOptionFunction {
43
- (option: RenderableOption): React.ReactNode;
44
- }
45
- /**
46
- * @deprecated ⚠️ `CoreSelectBaseProps` in Preview has been deprecated and will be removed in a future major version. Please use [`Select` in Main](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--docs) instead.
47
- */
48
- export interface CoreSelectBaseProps extends Themeable, GrowthBehavior, Pick<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'>, Pick<React.SelectHTMLAttributes<HTMLSelectElement>, 'required'>, Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'onChange'> {
49
- /**
50
- * The type of error associated with the Select (if applicable).
51
- */
52
- error?: ErrorType;
53
- /**
54
- * The function called to render the content of each option.
55
- *
56
- * The `option` argument passed to the function is an object which contains the following:
57
- *
58
- * * `data: object` (data object carried over from the corresponding option originally passed into the component)
59
- * * `disabled: boolean`
60
- * * `focused: boolean` (set to `true` if the option has keyboard focus)
61
- * * `id: string`
62
- * * `label: string`
63
- * * `selected: boolean` (set to `true` if the option is selected)
64
- * * `value: string`
65
- *
66
- * If you omit the `renderOption` prop, each option will be rendered using a `defaultRenderOption` function provided by the component.
67
- *
68
- * @default defaultRenderOption
69
- */
70
- renderOption?: RenderOptionFunction;
71
- /**
72
- * The function called to render the selected option.
73
- *
74
- * The `option` argument passed to the function is an object which contains the following:
75
- *
76
- * * `data: object` (data object carried over from the corresponding option originally passed into the component)
77
- * * `disabled: boolean`
78
- * * `id: string`
79
- * * `label: string`
80
- * * `value: string`
81
- *
82
- * If you omit the `renderSelected` prop, each option will be rendered using a `defaultRenderSelected` function provided by the component.
83
- *
84
- * @default defaultRenderSelected
85
- */
86
- renderSelected?: RenderSelectedFunction;
87
- /**
88
- * The value of the Select.
89
- */
90
- value?: string;
91
- }
92
- /**
93
- * @deprecated ⚠️ `SelectBaseProps` in Preview has been deprecated and will be removed in a future major version. Please use [`Select` in Main](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--docs) instead.
94
- */
95
- export interface SelectBaseProps extends CoreSelectBaseProps, StyledType {
96
- /**
97
- * The ref to be forwarded to the underlying button element. Use this to imperatively manipulate the button.
98
- */
99
- forwardedButtonRef?: React.Ref<HTMLButtonElement>;
100
- /**
101
- * The local ref to the underlying button element. Can be used in situations where RefObject is required (such as the Popper Menu).
102
- */
103
- localButtonRef?: React.RefObject<HTMLButtonElement>;
104
- /**
105
- * The index of the focused option in the SelectBase.
106
- * @default 0
107
- */
108
- focusedOptionIndex?: number;
109
- /**
110
- * The ref to the underlying (hidden) text input element. Use this to imperatively manipulate the input.
111
- */
112
- inputRef?: React.Ref<HTMLInputElement>;
113
- /**
114
- * The placement of the SelectBase menu relative to its corresponding SelectButton.
115
- * @default 'bottom'
116
- */
117
- menuPlacement?: MenuPlacement;
118
- /**
119
- * The ref to the underlying menu element. Use this to imperatively manipulate the menu.
120
- */
121
- menuRef?: React.RefObject<HTMLUListElement>;
122
- /**
123
- * The visibility state of the SelectBase menu.
124
- * @default 'closed'
125
- */
126
- menuVisibility?: MenuVisibility;
127
- /**
128
- * The function called when a key is pressed down while the SelectBase button or menu has focus.
129
- */
130
- onKeyDown?: (event: React.KeyboardEvent<HTMLElement>) => void;
131
- /**
132
- * The function called when the menu is closed.
133
- */
134
- onClose?: () => void;
135
- /**
136
- * The function called when an option in the SelectBase is selected via a click or a keyboard shortcut. The `index` passed to the callback function represents the index of the option which was selected.
137
- */
138
- onOptionSelection?: (index: number) => void;
139
- /**
140
- * The options of the SelectBase. `options` is an array of objects, each object adhering to the `NormalizedOption` interface:
141
- *
142
- * * `value: string` (required, analagous to the `value` attribute of an `<option>`)
143
- * * `disabled: boolean` (required)
144
- * * `id: string` (required)
145
- * * `label: string` (required, analagous to the text content of an `<option>`)
146
- */
147
- options: NormalizedOption[];
148
- /**
149
- * If true, automatically flip the SelectBase menu to keep it visible if necessary (e.g., if the the menu would otherwise display below the visible area of the viewport).
150
- * @default true
151
- */
152
- shouldMenuAutoFlip?: boolean;
153
- /**
154
- * If true, focus the SelectBase menu when it's shown. Set to false if you don't want to focus the menu automatically (for visual testing purposes, for example).
155
- * @default true
156
- */
157
- shouldMenuAutoFocus?: boolean;
158
- }
159
- export declare const buttonBorderWidth = 1;
160
- /**
161
- * @deprecated ⚠️ `SelectBase` in Preview has been deprecated and will be removed in a future major version. Please use [`Select` in Main](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--docs) instead.
162
- */
163
- export declare const SelectBase: ({ "aria-labelledby": ariaLabelledBy, "aria-required": ariaRequired, as, forwardedButtonRef, localButtonRef, disabled, error, focusedOptionIndex, grow, inputRef, menuPlacement, menuRef, menuVisibility, onChange, onKeyDown, onBlur, onClose, onOptionSelection, options, renderOption, renderSelected, required, shouldMenuAutoFlip, shouldMenuAutoFocus, value, ...elemProps }: SelectBaseProps) => import("react/jsx-runtime").JSX.Element;
164
- export {};
165
- //# sourceMappingURL=SelectBase.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SelectBase.d.ts","sourceRoot":"","sources":["../../../../select/lib/SelectBase.tsx"],"names":[],"mappings":"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"}