@patternfly/react-templates 6.2.0-prerelease.9 → 6.2.1-prerelease.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 (67) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/components/package.json +1 -1
  3. package/dist/dynamic/components/Dropdown/package.json +1 -1
  4. package/dist/dynamic/components/Select/package.json +1 -1
  5. package/dist/esm/components/Dropdown/SimpleDropdown.d.ts +2 -2
  6. package/dist/esm/components/Dropdown/SimpleDropdown.d.ts.map +1 -1
  7. package/dist/esm/components/Dropdown/SimpleDropdown.js +9 -9
  8. package/dist/esm/components/Dropdown/SimpleDropdown.js.map +1 -1
  9. package/dist/esm/components/Select/CheckboxSelect.d.ts +2 -2
  10. package/dist/esm/components/Select/CheckboxSelect.d.ts.map +1 -1
  11. package/dist/esm/components/Select/CheckboxSelect.js +12 -14
  12. package/dist/esm/components/Select/CheckboxSelect.js.map +1 -1
  13. package/dist/esm/components/Select/MultiTypeaheadSelect.d.ts +6 -2
  14. package/dist/esm/components/Select/MultiTypeaheadSelect.d.ts.map +1 -1
  15. package/dist/esm/components/Select/MultiTypeaheadSelect.js +36 -33
  16. package/dist/esm/components/Select/MultiTypeaheadSelect.js.map +1 -1
  17. package/dist/esm/components/Select/SimpleSelect.d.ts +2 -2
  18. package/dist/esm/components/Select/SimpleSelect.d.ts.map +1 -1
  19. package/dist/esm/components/Select/SimpleSelect.js +11 -11
  20. package/dist/esm/components/Select/SimpleSelect.js.map +1 -1
  21. package/dist/esm/components/Select/TypeaheadSelect.d.ts +6 -2
  22. package/dist/esm/components/Select/TypeaheadSelect.d.ts.map +1 -1
  23. package/dist/esm/components/Select/TypeaheadSelect.js +31 -26
  24. package/dist/esm/components/Select/TypeaheadSelect.js.map +1 -1
  25. package/dist/js/components/Dropdown/SimpleDropdown.d.ts +2 -2
  26. package/dist/js/components/Dropdown/SimpleDropdown.d.ts.map +1 -1
  27. package/dist/js/components/Dropdown/SimpleDropdown.js +9 -9
  28. package/dist/js/components/Dropdown/SimpleDropdown.js.map +1 -1
  29. package/dist/js/components/Select/CheckboxSelect.d.ts +2 -2
  30. package/dist/js/components/Select/CheckboxSelect.d.ts.map +1 -1
  31. package/dist/js/components/Select/CheckboxSelect.js +12 -14
  32. package/dist/js/components/Select/CheckboxSelect.js.map +1 -1
  33. package/dist/js/components/Select/MultiTypeaheadSelect.d.ts +6 -2
  34. package/dist/js/components/Select/MultiTypeaheadSelect.d.ts.map +1 -1
  35. package/dist/js/components/Select/MultiTypeaheadSelect.js +36 -33
  36. package/dist/js/components/Select/MultiTypeaheadSelect.js.map +1 -1
  37. package/dist/js/components/Select/SimpleSelect.d.ts +2 -2
  38. package/dist/js/components/Select/SimpleSelect.d.ts.map +1 -1
  39. package/dist/js/components/Select/SimpleSelect.js +11 -11
  40. package/dist/js/components/Select/SimpleSelect.js.map +1 -1
  41. package/dist/js/components/Select/TypeaheadSelect.d.ts +6 -2
  42. package/dist/js/components/Select/TypeaheadSelect.d.ts.map +1 -1
  43. package/dist/js/components/Select/TypeaheadSelect.js +31 -26
  44. package/dist/js/components/Select/TypeaheadSelect.js.map +1 -1
  45. package/dist/umd/assets/{output-CM-RSskk.css → output-C9lOeaK1.css} +292 -167
  46. package/dist/umd/react-templates.min.js +1 -1
  47. package/package.json +6 -6
  48. package/src/components/Dropdown/SimpleDropdown.tsx +3 -3
  49. package/src/components/Dropdown/__tests__/SimpleDropdown.test.tsx +0 -1
  50. package/src/components/Dropdown/examples/DropdownTemplates.md +1 -0
  51. package/src/components/Dropdown/examples/SimpleDropdownExample.tsx +4 -4
  52. package/src/components/Select/CheckboxSelect.tsx +5 -5
  53. package/src/components/Select/MultiTypeaheadSelect.tsx +26 -15
  54. package/src/components/Select/SimpleSelect.tsx +5 -5
  55. package/src/components/Select/TypeaheadSelect.tsx +27 -15
  56. package/src/components/Select/__tests__/CheckboxSelect.test.tsx +0 -1
  57. package/src/components/Select/__tests__/CheckboxSelectSnapshots.test.tsx +0 -1
  58. package/src/components/Select/__tests__/MultiTypeaheadSelect.test.tsx +19 -1
  59. package/src/components/Select/__tests__/SimpleSelect.test.tsx +0 -1
  60. package/src/components/Select/__tests__/TypeaheadSelect.test.tsx +19 -1
  61. package/src/components/Select/__tests__/__snapshots__/MultiTypeaheadSelect.test.tsx.snap +2 -3
  62. package/src/components/Select/__tests__/__snapshots__/TypeaheadSelect.test.tsx.snap +2 -3
  63. package/src/components/Select/examples/CheckboxSelectDemo.tsx +3 -3
  64. package/src/components/Select/examples/MultiTypeaheadSelectDemo.tsx +3 -3
  65. package/src/components/Select/examples/SelectTemplates.md +1 -0
  66. package/src/components/Select/examples/SimpleSelectDemo.tsx +6 -6
  67. package/src/components/Select/examples/TypeaheadSelectDemo.tsx +7 -7
@@ -1,10 +1,10 @@
1
- import React from 'react';
1
+ import { Fragment, useState } from 'react';
2
2
  import { Checkbox, Flex, FlexItem } from '@patternfly/react-core';
3
3
  import { SimpleDropdown, SimpleDropdownItem } from '@patternfly/react-templates';
4
4
  import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
5
5
 
6
6
  export const SimpleDropdownExample: React.FunctionComponent = () => {
7
- const [isDisabled, setIsDisabled] = React.useState(false);
7
+ const [isDisabled, setIsDisabled] = useState(false);
8
8
 
9
9
  const items: SimpleDropdownItem[] = [
10
10
  // eslint-disable-next-line no-console
@@ -18,7 +18,7 @@ export const SimpleDropdownExample: React.FunctionComponent = () => {
18
18
  ];
19
19
 
20
20
  return (
21
- <React.Fragment>
21
+ <Fragment>
22
22
  <Checkbox
23
23
  id="simple-example-disabled-toggle"
24
24
  label="Disable simple dropdown toggles"
@@ -48,6 +48,6 @@ export const SimpleDropdownExample: React.FunctionComponent = () => {
48
48
  />
49
49
  </FlexItem>
50
50
  </Flex>
51
- </React.Fragment>
51
+ </Fragment>
52
52
  );
53
53
  };
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { forwardRef, useEffect, useState } from 'react';
2
2
  import { Badge } from '@patternfly/react-core/dist/esm/components/Badge';
3
3
  import { MenuToggle, MenuToggleElement, MenuToggleProps } from '@patternfly/react-core/dist/esm/components/MenuToggle';
4
4
  import {
@@ -46,10 +46,10 @@ const CheckboxSelectBase: React.FunctionComponent<CheckboxSelectProps> = ({
46
46
  toggleProps,
47
47
  ...props
48
48
  }: CheckboxSelectProps) => {
49
- const [isOpen, setIsOpen] = React.useState(false);
50
- const [selected, setSelected] = React.useState<string[]>([]);
49
+ const [isOpen, setIsOpen] = useState(false);
50
+ const [selected, setSelected] = useState<string[]>([]);
51
51
 
52
- React.useEffect(() => {
52
+ useEffect(() => {
53
53
  const selectedOptions = initialOptions?.filter((option) => option.selected);
54
54
  setSelected(selectedOptions?.map((selectedOption) => String(selectedOption.value)) ?? []);
55
55
  }, [initialOptions]);
@@ -122,6 +122,6 @@ const CheckboxSelectBase: React.FunctionComponent<CheckboxSelectProps> = ({
122
122
  );
123
123
  };
124
124
 
125
- export const CheckboxSelect = React.forwardRef((props: CheckboxSelectProps, ref: React.Ref<any>) => (
125
+ export const CheckboxSelect = forwardRef((props: CheckboxSelectProps, ref: React.Ref<any>) => (
126
126
  <CheckboxSelectBase {...props} innerRef={ref} />
127
127
  ));
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { forwardRef, useEffect, useRef, useState } from 'react';
2
2
  import { Button } from '@patternfly/react-core/dist/esm/components/Button';
3
3
  import { Label, LabelGroup } from '@patternfly/react-core/dist/esm/components/Label';
4
4
  import { MenuToggle, MenuToggleElement, MenuToggleProps } from '@patternfly/react-core/dist/esm/components/MenuToggle';
@@ -37,6 +37,10 @@ export interface MultiTypeaheadSelectProps extends Omit<SelectProps, 'toggle' |
37
37
  onToggle?: (nextIsOpen: boolean) => void;
38
38
  /** Callback triggered when the text in the input field changes. */
39
39
  onInputChange?: (newValue: string) => void;
40
+ /** Custom callback triggered when the input field has focus and a keyboard event is triggered.
41
+ * This will override the default keydown behavior for the input field.
42
+ */
43
+ onInputKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
40
44
  /** Placeholder text for the select input. */
41
45
  placeholder?: string;
42
46
  /** Message to display when no options match the filter. */
@@ -55,6 +59,7 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
55
59
  onSelectionChange,
56
60
  onToggle,
57
61
  onInputChange,
62
+ onInputKeyDown: onInputKeyDownProp,
58
63
  placeholder = 'Select an option',
59
64
  noOptionsFoundMessage = (filter) => `No results found for "${filter}"`,
60
65
  isDisabled,
@@ -62,15 +67,15 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
62
67
  toggleProps,
63
68
  ...props
64
69
  }: MultiTypeaheadSelectProps) => {
65
- const [isOpen, setIsOpen] = React.useState(false);
66
- const [selected, setSelected] = React.useState<(string | number)[]>(
70
+ const [isOpen, setIsOpen] = useState(false);
71
+ const [selected, setSelected] = useState<(string | number)[]>(
67
72
  (initialOptions?.filter((o) => o.selected) ?? []).map((o) => o.value)
68
73
  );
69
- const [inputValue, setInputValue] = React.useState<string>();
70
- const [selectOptions, setSelectOptions] = React.useState<MultiTypeaheadSelectOption[]>(initialOptions);
71
- const [focusedItemIndex, setFocusedItemIndex] = React.useState<number | null>(null);
72
- const [activeItemId, setActiveItemId] = React.useState<string | null>(null);
73
- const textInputRef = React.useRef<HTMLInputElement>();
74
+ const [inputValue, setInputValue] = useState<string>();
75
+ const [selectOptions, setSelectOptions] = useState<MultiTypeaheadSelectOption[]>(initialOptions);
76
+ const [focusedItemIndex, setFocusedItemIndex] = useState<number | null>(null);
77
+ const [activeItemId, setActiveItemId] = useState<string | null>(null);
78
+ const textInputRef = useRef<HTMLInputElement>(undefined);
74
79
 
75
80
  const NO_RESULTS = 'no results';
76
81
 
@@ -79,7 +84,7 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
79
84
  setIsOpen(true);
80
85
  };
81
86
 
82
- React.useEffect(() => {
87
+ useEffect(() => {
83
88
  let newSelectOptions: MultiTypeaheadSelectOption[] = initialOptions;
84
89
 
85
90
  // Filter menu items based on the text input value when one exists
@@ -108,10 +113,7 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
108
113
  // eslint-disable-next-line react-hooks/exhaustive-deps
109
114
  }, [inputValue, initialOptions]);
110
115
 
111
- React.useEffect(
112
- () => setSelected((initialOptions?.filter((o) => o.selected) ?? []).map((o) => o.value)),
113
- [initialOptions]
114
- );
116
+ useEffect(() => setSelected((initialOptions?.filter((o) => o.selected) ?? []).map((o) => o.value)), [initialOptions]);
115
117
 
116
118
  const setActiveAndFocusedItem = (itemIndex: number) => {
117
119
  setFocusedItemIndex(itemIndex);
@@ -219,11 +221,12 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
219
221
  setActiveAndFocusedItem(indexToFocus);
220
222
  };
221
223
 
222
- const onInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
224
+ const defaultOnInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
223
225
  const focusedItem = focusedItemIndex !== null ? selectOptions[focusedItemIndex] : null;
224
226
 
225
227
  switch (event.key) {
226
228
  case 'Enter':
229
+ event.preventDefault();
227
230
  if (isOpen && focusedItem && focusedItem.value !== NO_RESULTS && !focusedItem.isAriaDisabled) {
228
231
  selectOption(event, focusedItem?.value);
229
232
  }
@@ -242,6 +245,14 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
242
245
  }
243
246
  };
244
247
 
248
+ const onInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
249
+ if (onInputKeyDownProp) {
250
+ onInputKeyDownProp(event);
251
+ } else {
252
+ defaultOnInputKeyDown(event);
253
+ }
254
+ };
255
+
245
256
  const onToggleClick = () => {
246
257
  onToggle && onToggle(!isOpen);
247
258
  setIsOpen(!isOpen);
@@ -340,7 +351,7 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
340
351
 
341
352
  MultiTypeaheadSelectBase.displayName = 'MultiTypeaheadSelectBase';
342
353
 
343
- export const MultiTypeaheadSelect = React.forwardRef((props: MultiTypeaheadSelectProps, ref: React.Ref<any>) => (
354
+ export const MultiTypeaheadSelect = forwardRef((props: MultiTypeaheadSelectProps, ref: React.Ref<any>) => (
344
355
  <MultiTypeaheadSelectBase {...props} innerRef={ref} />
345
356
  ));
346
357
 
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { forwardRef, useEffect, useState } from 'react';
2
2
  import {
3
3
  Select,
4
4
  SelectList,
@@ -48,10 +48,10 @@ const SimpleSelectBase: React.FunctionComponent<SimpleSelectProps> = ({
48
48
  placeholder = 'Select a value',
49
49
  ...props
50
50
  }: SimpleSelectProps) => {
51
- const [isOpen, setIsOpen] = React.useState(false);
52
- const [selected, setSelected] = React.useState<SimpleSelectOption | undefined>();
51
+ const [isOpen, setIsOpen] = useState(false);
52
+ const [selected, setSelected] = useState<SimpleSelectOption | undefined>();
53
53
 
54
- React.useEffect(() => {
54
+ useEffect(() => {
55
55
  const selectedOption = initialOptions?.find((option) => option.selected);
56
56
  setSelected(selectedOption);
57
57
  }, [initialOptions]);
@@ -114,7 +114,7 @@ const SimpleSelectBase: React.FunctionComponent<SimpleSelectProps> = ({
114
114
  );
115
115
  };
116
116
 
117
- export const SimpleSelect = React.forwardRef((props: SimpleSelectProps, ref: React.Ref<any>) => (
117
+ export const SimpleSelect = forwardRef((props: SimpleSelectProps, ref: React.Ref<any>) => (
118
118
  <SimpleSelectBase {...props} innerRef={ref} />
119
119
  ));
120
120
 
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { forwardRef, useEffect, useRef, useState } from 'react';
2
2
  import { Button } from '@patternfly/react-core/dist/esm/components/Button';
3
3
  import { MenuToggle, MenuToggleElement, MenuToggleProps } from '@patternfly/react-core/dist/esm/components/MenuToggle';
4
4
  import {
@@ -36,6 +36,10 @@ export interface TypeaheadSelectProps extends Omit<SelectProps, 'toggle' | 'onSe
36
36
  onToggle?: (nextIsOpen: boolean) => void;
37
37
  /** Callback triggered when the text in the input field changes. */
38
38
  onInputChange?: (newValue: string) => void;
39
+ /** Custom callback triggered when the input field has focus and a keyboard event is triggered.
40
+ * This will override the default keydown behavior for the input field.
41
+ */
42
+ onInputKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
39
43
  /** Callback triggered when the clear button is selected */
40
44
  onClearSelection?: () => void;
41
45
  /** Placeholder text for the select input. */
@@ -67,6 +71,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
67
71
  onSelect,
68
72
  onToggle,
69
73
  onInputChange,
74
+ onInputKeyDown: onInputKeyDownProp,
70
75
  onClearSelection,
71
76
  placeholder = 'Select an option',
72
77
  noOptionsAvailableMessage = 'No options are available',
@@ -79,20 +84,18 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
79
84
  toggleProps,
80
85
  ...props
81
86
  }: TypeaheadSelectProps) => {
82
- const [isOpen, setIsOpen] = React.useState(false);
83
- const [selected, setSelected] = React.useState<string>(String(initialOptions.find((o) => o.selected)?.content ?? ''));
84
- const [inputValue, setInputValue] = React.useState<string>(
85
- String(initialOptions.find((o) => o.selected)?.content ?? '')
86
- );
87
- const [filterValue, setFilterValue] = React.useState<string>('');
88
- const [selectOptions, setSelectOptions] = React.useState<TypeaheadSelectOption[]>(initialOptions);
89
- const [focusedItemIndex, setFocusedItemIndex] = React.useState<number | null>(null);
90
- const [activeItemId, setActiveItemId] = React.useState<string | null>(null);
91
- const textInputRef = React.useRef<HTMLInputElement>();
87
+ const [isOpen, setIsOpen] = useState(false);
88
+ const [selected, setSelected] = useState<string>(String(initialOptions.find((o) => o.selected)?.content ?? ''));
89
+ const [inputValue, setInputValue] = useState<string>(String(initialOptions.find((o) => o.selected)?.content ?? ''));
90
+ const [filterValue, setFilterValue] = useState<string>('');
91
+ const [selectOptions, setSelectOptions] = useState<TypeaheadSelectOption[]>(initialOptions);
92
+ const [focusedItemIndex, setFocusedItemIndex] = useState<number | null>(null);
93
+ const [activeItemId, setActiveItemId] = useState<string | null>(null);
94
+ const textInputRef = useRef<HTMLInputElement>(undefined);
92
95
 
93
96
  const NO_RESULTS = 'no results';
94
97
 
95
- React.useEffect(() => {
98
+ useEffect(() => {
96
99
  let newSelectOptions: TypeaheadSelectOption[] = initialOptions;
97
100
 
98
101
  // Filter menu items based on the text input value when one exists
@@ -153,7 +156,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
153
156
  noOptionsAvailableMessage
154
157
  ]);
155
158
 
156
- React.useEffect(() => {
159
+ useEffect(() => {
157
160
  // If the selected option changed and the current input value is the previously selected item, update the displayed value.
158
161
  const selectedOption = initialOptions.find((o) => o.selected);
159
162
  if (inputValue === selected && selectedOption?.value !== selected) {
@@ -273,11 +276,12 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
273
276
  setActiveAndFocusedItem(indexToFocus);
274
277
  };
275
278
 
276
- const onInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
279
+ const defaultOnInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
277
280
  const focusedItem = focusedItemIndex !== null ? selectOptions[focusedItemIndex] : null;
278
281
 
279
282
  switch (event.key) {
280
283
  case 'Enter':
284
+ event.preventDefault();
281
285
  if (isOpen && focusedItem && focusedItem.value !== NO_RESULTS && !focusedItem.isAriaDisabled) {
282
286
  selectOption(event, focusedItem);
283
287
  }
@@ -293,6 +297,14 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
293
297
  }
294
298
  };
295
299
 
300
+ const onInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
301
+ if (onInputKeyDownProp) {
302
+ onInputKeyDownProp(event);
303
+ } else {
304
+ defaultOnInputKeyDown(event);
305
+ }
306
+ };
307
+
296
308
  const onToggleClick = () => {
297
309
  onToggle && onToggle(!isOpen);
298
310
  setIsOpen(!isOpen);
@@ -376,7 +388,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
376
388
  };
377
389
  TypeaheadSelectBase.displayName = 'TypeaheadSelectBase';
378
390
 
379
- export const TypeaheadSelect = React.forwardRef((props: TypeaheadSelectProps, ref: React.Ref<any>) => (
391
+ export const TypeaheadSelect = forwardRef((props: TypeaheadSelectProps, ref: React.Ref<any>) => (
380
392
  <TypeaheadSelectBase {...props} innerRef={ref} />
381
393
  ));
382
394
 
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
1
  import { render, screen, waitForElementToBeRemoved } from '@testing-library/react';
3
2
  import userEvent from '@testing-library/user-event';
4
3
  import { CheckboxSelect } from '../CheckboxSelect';
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
1
  import { render, screen } from '@testing-library/react';
3
2
  import userEvent from '@testing-library/user-event';
4
3
  import { CheckboxSelect } from '../CheckboxSelect';
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
1
  import { render, screen, waitForElementToBeRemoved } from '@testing-library/react';
3
2
  import userEvent from '@testing-library/user-event';
4
3
  import { MultiTypeaheadSelect } from '../MultiTypeaheadSelect';
@@ -395,6 +394,25 @@ describe('MultiTypeaheadSelect', () => {
395
394
  expect(onInputChangeMock).toHaveBeenCalledWith('1');
396
395
  });
397
396
 
397
+ it('calls the onInputKeyDown callback only when keydown event occurs', async () => {
398
+ const initialOptions = [
399
+ { content: 'Option 1', value: 'option1' },
400
+ { content: 'Option 2', value: 'option2' },
401
+ { content: 'Option 3', value: 'option3' }
402
+ ];
403
+
404
+ const user = userEvent.setup();
405
+ const onInputKeyDownMock = jest.fn();
406
+
407
+ render(<MultiTypeaheadSelect initialOptions={initialOptions} onInputKeyDown={onInputKeyDownMock} />);
408
+
409
+ const input = screen.getByRole('combobox');
410
+ await user.click(input);
411
+ expect(onInputKeyDownMock).not.toHaveBeenCalled();
412
+ await user.keyboard('{Enter}');
413
+ expect(onInputKeyDownMock).toHaveBeenCalledTimes(1);
414
+ });
415
+
398
416
  it('Matches snapshot', async () => {
399
417
  const initialOptions = [
400
418
  { content: 'Option 1', value: 'option1' },
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
1
  import { render, screen, waitForElementToBeRemoved } from '@testing-library/react';
3
2
  import userEvent from '@testing-library/user-event';
4
3
  import { SimpleSelect } from '../SimpleSelect';
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
1
  import { render, screen, waitForElementToBeRemoved } from '@testing-library/react';
3
2
  import userEvent from '@testing-library/user-event';
4
3
  import { TypeaheadSelect } from '../TypeaheadSelect';
@@ -390,6 +389,25 @@ test('typing in input triggers onInputChange callback', async () => {
390
389
  expect(onInputChangeMock).toHaveBeenCalledWith('1');
391
390
  });
392
391
 
392
+ it('calls the onInputKeyDown callback only when keydown event occurs', async () => {
393
+ const initialOptions = [
394
+ { content: 'Option 1', value: 'option1' },
395
+ { content: 'Option 2', value: 'option2' },
396
+ { content: 'Option 3', value: 'option3' }
397
+ ];
398
+
399
+ const user = userEvent.setup();
400
+ const onInputKeyDownMock = jest.fn();
401
+
402
+ render(<TypeaheadSelect initialOptions={initialOptions} onInputKeyDown={onInputKeyDownMock} />);
403
+
404
+ const input = screen.getByRole('combobox');
405
+ await user.click(input);
406
+ expect(onInputKeyDownMock).not.toHaveBeenCalled();
407
+ await user.keyboard('{Enter}');
408
+ expect(onInputKeyDownMock).toHaveBeenCalledTimes(1);
409
+ });
410
+
393
411
  test('Matches snapshot', async () => {
394
412
  const initialOptions = [
395
413
  { content: 'Option 1', value: 'option1' },
@@ -32,10 +32,9 @@ exports[`MultiTypeaheadSelect Matches snapshot 1`] = `
32
32
  style="display: none;"
33
33
  >
34
34
  <button
35
- aria-disabled="false"
36
35
  aria-label="Clear input value"
37
36
  class="pf-v6-c-button pf-m-plain"
38
- data-ouia-component-id="OUIA-Generated-Button-plain-17"
37
+ data-ouia-component-id="OUIA-Generated-Button-plain-18"
39
38
  data-ouia-component-type="PF6/Button"
40
39
  data-ouia-safe="true"
41
40
  type="button"
@@ -64,7 +63,7 @@ exports[`MultiTypeaheadSelect Matches snapshot 1`] = `
64
63
  aria-expanded="true"
65
64
  aria-label="Multi select Typeahead menu toggle"
66
65
  class="pf-v6-c-menu-toggle__button"
67
- data-ouia-component-id="OUIA-Generated-MenuToggle-typeahead-17"
66
+ data-ouia-component-id="OUIA-Generated-MenuToggle-typeahead-18"
68
67
  data-ouia-component-type="PF6/MenuToggle"
69
68
  data-ouia-safe="true"
70
69
  tabindex="-1"
@@ -32,10 +32,9 @@ exports[`Matches snapshot 1`] = `
32
32
  style="display: none;"
33
33
  >
34
34
  <button
35
- aria-disabled="false"
36
35
  aria-label="Clear input value"
37
36
  class="pf-v6-c-button pf-m-plain"
38
- data-ouia-component-id="OUIA-Generated-Button-plain-17"
37
+ data-ouia-component-id="OUIA-Generated-Button-plain-18"
39
38
  data-ouia-component-type="PF6/Button"
40
39
  data-ouia-safe="true"
41
40
  type="button"
@@ -64,7 +63,7 @@ exports[`Matches snapshot 1`] = `
64
63
  aria-expanded="true"
65
64
  aria-label="Typeahead menu toggle"
66
65
  class="pf-v6-c-menu-toggle__button"
67
- data-ouia-component-id="OUIA-Generated-MenuToggle-typeahead-17"
66
+ data-ouia-component-id="OUIA-Generated-MenuToggle-typeahead-18"
68
67
  data-ouia-component-type="PF6/MenuToggle"
69
68
  data-ouia-safe="true"
70
69
  tabindex="-1"
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { useMemo, useState } from 'react';
2
2
  import { CheckboxSelect, CheckboxSelectOption } from '@patternfly/react-templates';
3
3
 
4
4
  const Options: { content: string; value: string; description?: string; isDisabled?: boolean }[] = [
@@ -9,9 +9,9 @@ const Options: { content: string; value: string; description?: string; isDisable
9
9
  ];
10
10
 
11
11
  export const SelectBasic: React.FunctionComponent = () => {
12
- const [selected, setSelected] = React.useState<string[]>(['option-2']);
12
+ const [selected, setSelected] = useState<string[]>(['option-2']);
13
13
 
14
- const initialOptions = React.useMemo<CheckboxSelectOption[]>(
14
+ const initialOptions = useMemo<CheckboxSelectOption[]>(
15
15
  () => Options.map((o) => ({ ...o, selected: selected.includes(o.value) })),
16
16
  [selected]
17
17
  );
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { useMemo, useState } from 'react';
2
2
  import { MultiTypeaheadSelect, MultiTypeaheadSelectOption } from '@patternfly/react-templates';
3
3
 
4
4
  const Options = [
@@ -17,9 +17,9 @@ const Options = [
17
17
  type SelectionsType = (string | number)[];
18
18
 
19
19
  export const MultiSelectTypeaheadDemo: React.FunctionComponent = () => {
20
- const [selected, setSelected] = React.useState<SelectionsType>(['option5']);
20
+ const [selected, setSelected] = useState<SelectionsType>(['option5']);
21
21
 
22
- const initialOptions = React.useMemo<MultiTypeaheadSelectOption[]>(
22
+ const initialOptions = useMemo<MultiTypeaheadSelectOption[]>(
23
23
  () => Options.map((o) => ({ ...o, selected: selected.includes(o.value) })),
24
24
  [selected]
25
25
  );
@@ -11,6 +11,7 @@ Note: Templates live in their own package at [@patternfly/react-templates](https
11
11
 
12
12
  For custom use cases, please see the select component suite from [@patternfly/react-core](https://www.npmjs.com/package/@patternfly/react-core).
13
13
 
14
+ import { Fragment, useEffect, useMemo, useState } from 'react';
14
15
  import { Checkbox } from '@patternfly/react-core';
15
16
  import { SimpleSelect, CheckboxSelect, TypeaheadSelect, MultiTypeaheadSelect } from '@patternfly/react-templates';
16
17
 
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { Fragment, useMemo, useState } from 'react';
2
2
  import { Checkbox } from '@patternfly/react-core';
3
3
  import { SimpleSelect, SimpleSelectOption } from '@patternfly/react-templates';
4
4
 
@@ -9,16 +9,16 @@ const Options: SimpleSelectOption[] = [
9
9
  ];
10
10
 
11
11
  export const SelectSimpleDemo: React.FunctionComponent = () => {
12
- const [isDisabled, setIsDisabled] = React.useState<boolean>(false);
13
- const [selected, setSelected] = React.useState<string | undefined>('Option1');
12
+ const [isDisabled, setIsDisabled] = useState<boolean>(false);
13
+ const [selected, setSelected] = useState<string | undefined>('Option1');
14
14
 
15
- const initialOptions = React.useMemo<SimpleSelectOption[]>(
15
+ const initialOptions = useMemo<SimpleSelectOption[]>(
16
16
  () => Options.map((o) => ({ ...o, selected: o.value === selected })),
17
17
  [selected]
18
18
  );
19
19
 
20
20
  return (
21
- <React.Fragment>
21
+ <Fragment>
22
22
  <Checkbox
23
23
  id="toggle-disabled"
24
24
  label="isDisabled"
@@ -31,6 +31,6 @@ export const SelectSimpleDemo: React.FunctionComponent = () => {
31
31
  isDisabled={isDisabled}
32
32
  onSelect={(_ev, selection) => setSelected(String(selection))}
33
33
  />
34
- </React.Fragment>
34
+ </Fragment>
35
35
  );
36
36
  };
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { useEffect, useMemo, useState } from 'react';
2
2
  import { TypeaheadSelect, TypeaheadSelectOption } from '@patternfly/react-templates';
3
3
  import { Checkbox } from '@patternfly/react-core';
4
4
 
@@ -13,17 +13,17 @@ const Options = [
13
13
 
14
14
  /* eslint-disable no-console */
15
15
  export const SelectTypeaheadDemo: React.FunctionComponent = () => {
16
- const [selected, setSelected] = React.useState<string | undefined>();
17
- const [options, setOptions] = React.useState(Options);
18
- const [isCreatable, setIsCreatable] = React.useState<boolean>(false);
19
- const [isCreateOptionOnTop, setIsCreateOptionOnTop] = React.useState<boolean>(false);
16
+ const [selected, setSelected] = useState<string | undefined>();
17
+ const [options, setOptions] = useState(Options);
18
+ const [isCreatable, setIsCreatable] = useState<boolean>(false);
19
+ const [isCreateOptionOnTop, setIsCreateOptionOnTop] = useState<boolean>(false);
20
20
 
21
- const initialOptions = React.useMemo<TypeaheadSelectOption[]>(
21
+ const initialOptions = useMemo<TypeaheadSelectOption[]>(
22
22
  () => options.map((o) => ({ ...o, selected: o.value === selected })),
23
23
  [options, selected]
24
24
  );
25
25
 
26
- React.useEffect(() => {
26
+ useEffect(() => {
27
27
  console.log(`Selected: ${selected || 'none'}`);
28
28
  }, [selected]);
29
29