@linzjs/step-ag-grid 32.7.1 → 33.0.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 (58) hide show
  1. package/dist/src/components/gridFilter/GridFilterColumnsMultiSelect.d.ts +6 -25
  2. package/dist/step-ag-grid.cjs +117 -186
  3. package/dist/step-ag-grid.cjs.map +1 -1
  4. package/dist/step-ag-grid.esm.js +117 -186
  5. package/dist/step-ag-grid.esm.js.map +1 -1
  6. package/package.json +17 -17
  7. package/src/components/Grid.tsx +8 -10
  8. package/src/components/gridFilter/GridFilterColumnsMultiSelect.tsx +110 -199
  9. package/src/components/gridHook/useGridRangeSelection.ts +8 -6
  10. package/src/react-menu3/components/ControlledMenu.tsx +5 -3
  11. package/src/react-menu3/components/MenuList.tsx +6 -3
  12. package/src/react-menu3/hooks/useItems.ts +1 -1
  13. package/src/stories/components/ActionButton.stories.tsx +12 -11
  14. package/src/stories/decorators/withOpenInPanelDecorator.tsx +35 -0
  15. package/src/stories/grid/GridCopy.stories.tsx +38 -35
  16. package/src/stories/grid/GridDragRow.stories.tsx +41 -36
  17. package/src/stories/grid/GridFilterButtons.stories.tsx +25 -19
  18. package/src/stories/grid/GridFilterColumnsMultiSelect.stories.tsx +42 -37
  19. package/src/stories/grid/GridInlineText.stories.tsx +42 -35
  20. package/src/stories/grid/GridNoRowsOverlay.stories.tsx +28 -23
  21. package/src/stories/grid/GridNonEditableRow.stories.tsx +30 -24
  22. package/src/stories/grid/GridPinnedRow.stories.tsx +37 -31
  23. package/src/stories/grid/GridPopoutContextMenu.stories.tsx +29 -24
  24. package/src/stories/grid/GridPopoutEditBoolean.stories.tsx +89 -82
  25. package/src/stories/grid/GridPopoutEditGeneric.stories.tsx +27 -22
  26. package/src/stories/grid/GridPopoutEditGenericTextArea.stories.tsx +29 -24
  27. package/src/stories/grid/GridPopoverEditBearing.stories.tsx +30 -25
  28. package/src/stories/grid/GridPopoverEditDropDown.stories.tsx +29 -24
  29. package/src/stories/grid/GridPopoverEditMultiSelect.stories.tsx +29 -24
  30. package/src/stories/grid/GridPopoverEditMultiSelectGrid.stories.tsx +28 -24
  31. package/src/stories/grid/GridReadOnly.stories.tsx +56 -52
  32. package/src/stories/grid/GridSorting.stories.tsx +81 -79
  33. package/src/stories/grid/GridViewList.stories.tsx +31 -26
  34. package/src/stories/grid/GridViewSelectableList.stories.tsx +31 -26
  35. package/src/stories/grid/gridAutosize/GridAutoSize.stories.tsx +41 -37
  36. package/src/stories/grid/gridAutosize/GridFitSize.stories.tsx +40 -36
  37. package/src/stories/grid/gridAutosize/GridFitSizeFlex.stories.tsx +40 -36
  38. package/src/stories/grid/gridAutosize/ShowPanelResizingAgGrid/ShowPanelResizingStepAgGrid.tsx +14 -6
  39. package/src/stories/grid/gridFormInteraction/GridFormDropDownInteraction.stories.tsx +74 -74
  40. package/src/stories/grid/gridFormInteraction/GridFormEditBearingCorrectionInteraction.stories.tsx +59 -59
  41. package/src/stories/grid/gridFormInteraction/GridFormEditBearingInteraction.stories.tsx +58 -58
  42. package/src/stories/grid/gridFormInteraction/GridFormMultiSelectGridInteraction.stories.tsx +62 -62
  43. package/src/stories/grid/gridFormInteraction/GridFormMultiSelectInteraction.stories.tsx +118 -118
  44. package/src/stories/grid/gridFormInteraction/GridFormPopoverMenuInteraction.stories.tsx +107 -105
  45. package/src/stories/grid/gridFormInteraction/GridFormTextAreaInteraction.stories.tsx +72 -64
  46. package/src/stories/grid/gridFormInteraction/GridFormTextInputInteraction.stories.tsx +82 -73
  47. package/src/stories/grid/gridFormStatic/GridFormDropDown.stories.tsx +12 -13
  48. package/src/stories/grid/gridFormStatic/GridFormEditBearing.stories.tsx +12 -13
  49. package/src/stories/grid/gridFormStatic/GridFormEditBearingCorrection.stories.tsx +11 -13
  50. package/src/stories/grid/gridFormStatic/GridFormMessage.stories.tsx +11 -13
  51. package/src/stories/grid/gridFormStatic/GridFormMultiSelect.stories.tsx +11 -13
  52. package/src/stories/grid/gridFormStatic/GridFormPopoverMenu.stories.tsx +11 -13
  53. package/src/stories/grid/gridFormStatic/GridFormTextArea.stories.tsx +11 -13
  54. package/src/stories/grid/gridFormStatic/GridFormTextInput.stories.tsx +11 -13
  55. package/src/stories/grid/interactions/GridKeyboardInteractions.stories.tsx +110 -107
  56. package/src/stories/react-menu/ReactMenu.stories.tsx +70 -73
  57. package/src/styles/GridLoadableCell.scss +1 -1
  58. package/src/utils/useSharedInterval.ts +3 -3
@@ -1,8 +1,4 @@
1
- import '../../../react-menu3/styles/index.scss';
2
- import '../../../styles/index.scss';
3
- import '@linzjs/lui/dist/scss/base.scss';
4
-
5
- import { StoryFn } from '@storybook/react-vite';
1
+ import { Meta, StoryFn, StoryObj } from '@storybook/react-vite';
6
2
  import { GridPopoverContext } from '../../../contexts/GridPopoverContext';
7
3
  import { useRef } from 'react';
8
4
  import { expect, fn, userEvent, within } from 'storybook/test';
@@ -14,12 +10,6 @@ import {
14
10
  GridPopoverEditBearingEditorParams,
15
11
  } from '../../..';
16
12
 
17
- export default {
18
- title: 'GridForm / Interactions',
19
- component: GridFormEditBearing,
20
- args: {},
21
- };
22
-
23
13
  const updateValue = fn();
24
14
 
25
15
  const Template: StoryFn<typeof GridFormEditBearing> = (props: GridFormEditBearingProps<any>) => {
@@ -51,51 +41,61 @@ const Template: StoryFn<typeof GridFormEditBearing> = (props: GridFormEditBearin
51
41
  );
52
42
  };
53
43
 
54
- export const GridFormEditBearingInteractions_: typeof Template = Template.bind({});
55
- GridFormEditBearingInteractions_.play = async ({ canvasElement }) => {
56
- const canvas = within(canvasElement);
57
-
58
- expect(await canvas.findByText('Press enter or tab to save')).toBeInTheDocument();
59
-
60
- const inputField = canvas.getByPlaceholderText('Enter bearing');
61
-
62
- // Test formatting null
63
- expect(await canvas.findByText('–')).toBeInTheDocument();
64
-
65
- // Test formatting a bearing
66
- expect(inputField).toBeInTheDocument();
67
- await userEvent.type(inputField, '1.2345');
68
- expect(await canvas.findByText('1° 23\' 45"')).toBeInTheDocument();
69
-
70
- // Test enter to save
71
- updateValue.mockClear();
72
- await userEvent.type(inputField, '{Enter}');
73
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), 0); // 0 = Enter
74
-
75
- // Test tab to save
76
- updateValue.mockClear();
77
- await userEvent.tab();
78
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), 1); // 1 = Tab
79
-
80
- // Test shift+tab to save
81
- updateValue.mockClear();
82
- await userEvent.tab({ shift: true });
83
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), -1); // -1 = Shift + tab
84
-
85
- // Test escape not to save
86
- updateValue.mockClear();
87
- await userEvent.type(inputField, '{Escape}');
88
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), 0);
89
-
90
- // Test invalid value doesn't save
91
- updateValue.mockClear();
92
- await userEvent.type(inputField, 'xxx');
93
- expect(await canvas.findByText('?')).toBeInTheDocument();
94
- expect(canvas.getByText('Bearing must be a number in D.MMSSS format')).toBeInTheDocument();
95
- await userEvent.type(inputField, '{Enter}');
96
- expect(updateValue).not.toHaveBeenCalled();
97
- await userEvent.tab();
98
- expect(updateValue).not.toHaveBeenCalled();
99
- await userEvent.tab({ shift: true });
100
- expect(updateValue).not.toHaveBeenCalled();
44
+ const meta: Meta<typeof Template> = {
45
+ title: 'GridForm / Interactions',
46
+ component: Template,
47
+ args: {},
48
+ };
49
+ export default meta;
50
+
51
+ type Story = StoryObj<typeof meta>;
52
+
53
+ export const GridFormEditBearingInteractions_: Story = {
54
+ play: async ({ canvasElement }) => {
55
+ const canvas = within(canvasElement);
56
+
57
+ await expect(await canvas.findByText('Press enter or tab to save')).toBeInTheDocument();
58
+
59
+ const inputField = canvas.getByPlaceholderText('Enter bearing');
60
+
61
+ // Test formatting null
62
+ await expect(await canvas.findByText('–')).toBeInTheDocument();
63
+
64
+ // Test formatting a bearing
65
+ await expect(inputField).toBeInTheDocument();
66
+ await userEvent.type(inputField, '1.2345');
67
+ await expect(await canvas.findByText('1° 23\' 45"')).toBeInTheDocument();
68
+
69
+ // Test enter to save
70
+ updateValue.mockClear();
71
+ await userEvent.type(inputField, '{Enter}');
72
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), 0); // 0 = Enter
73
+
74
+ // Test tab to save
75
+ updateValue.mockClear();
76
+ await userEvent.tab();
77
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), 1); // 1 = Tab
78
+
79
+ // Test shift+tab to save
80
+ updateValue.mockClear();
81
+ await userEvent.tab({ shift: true });
82
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), -1); // -1 = Shift + tab
83
+
84
+ // Test escape not to save
85
+ updateValue.mockClear();
86
+ await userEvent.type(inputField, '{Escape}');
87
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), 0);
88
+
89
+ // Test invalid value doesn't save
90
+ updateValue.mockClear();
91
+ await userEvent.type(inputField, 'xxx');
92
+ await expect(await canvas.findByText('?')).toBeInTheDocument();
93
+ await expect(canvas.getByText('Bearing must be a number in D.MMSSS format')).toBeInTheDocument();
94
+ await userEvent.type(inputField, '{Enter}');
95
+ await expect(updateValue).not.toHaveBeenCalled();
96
+ await userEvent.tab();
97
+ await expect(updateValue).not.toHaveBeenCalled();
98
+ await userEvent.tab({ shift: true });
99
+ await expect(updateValue).not.toHaveBeenCalled();
100
+ },
101
101
  };
@@ -1,8 +1,4 @@
1
- import '../../../react-menu3/styles/index.scss';
2
- import '../../../styles/index.scss';
3
- import '@linzjs/lui/dist/scss/base.scss';
4
-
5
- import { StoryFn } from '@storybook/react-vite';
1
+ import { Meta, StoryFn, StoryObj } from '@storybook/react-vite';
6
2
  import { GridPopoverContext } from '../../../contexts/GridPopoverContext';
7
3
  import { useRef } from 'react';
8
4
  import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
@@ -14,12 +10,6 @@ import {
14
10
  MultiSelectGridOption,
15
11
  } from '../../..';
16
12
 
17
- export default {
18
- title: 'GridForm / Interactions',
19
- component: GridFormMultiSelectGrid,
20
- args: {},
21
- };
22
-
23
13
  const updateValue = fn((saveFn: (selectedRows: any[]) => Promise<boolean>, _tabDirection: 1 | 0 | -1) => saveFn([]));
24
14
 
25
15
  // eslint-disable-next-line @typescript-eslint/require-await
@@ -70,55 +60,65 @@ const Template: StoryFn<typeof GridFormMultiSelectGrid> = (props: GridFormMultiS
70
60
  );
71
61
  };
72
62
 
73
- export const GridFormMultiSelectGridInteractions_: typeof Template = Template.bind({});
74
- GridFormMultiSelectGridInteractions_.play = async ({ canvasElement }) => {
75
- updateValue.mockClear();
76
- onSave.mockClear();
77
- onSelectFilter.mockClear();
78
-
79
- const canvas = within(canvasElement);
80
-
81
- const getOption = (name: RegExp | string) => canvas.findByRole('menuitem', { name });
82
-
83
- // Check enabled menu handles click
84
- const zeroMenuOption = await getOption(/Zero/);
85
- expect(zeroMenuOption).toBeInTheDocument();
86
-
87
- await userEvent.click(zeroMenuOption);
88
- await userEvent.keyboard('{Tab}');
89
- expect(updateValue).toHaveBeenCalled();
90
- await waitFor(() => expect(onSave).toHaveBeenCalledWith({ selectedRows: [], addValues: [0], removeValues: [] }));
91
-
92
- const check = (label: string) => {
93
- const activeCell = canvasElement.ownerDocument.activeElement as HTMLElement | null;
94
- expect(activeCell?.innerText).toBe(label);
95
- };
96
-
97
- // Test left/right arrow
98
- await userEvent.keyboard('{ArrowRight}');
99
- check('Three');
100
- await userEvent.keyboard('{ArrowRight}');
101
- check('Zero');
102
- await userEvent.keyboard('{ArrowLeft}');
103
- check('Three');
104
- await userEvent.keyboard('{ArrowLeft}');
105
- check('Zero');
106
-
107
- // Test tab to save
108
- updateValue.mockClear();
109
- onSave.mockClear();
110
- await userEvent.tab();
111
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), 1); // 1 = Tab
112
- expect(onSave).toHaveBeenCalledWith({
113
- selectedRows: [],
114
- addValues: [0],
115
- removeValues: [],
116
- });
117
-
118
- // Test shift+tab to save
119
- updateValue.mockClear();
120
- onSave.mockClear();
121
- await userEvent.tab({ shift: true });
122
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), -1); // -1 = Shift + tab
123
- expect(onSave).toHaveBeenCalled();
63
+ const meta: Meta<typeof Template> = {
64
+ title: 'GridForm / Interactions',
65
+ component: Template,
66
+ args: {},
67
+ };
68
+ export default meta;
69
+
70
+ type Story = StoryObj<typeof meta>;
71
+
72
+ export const GridFormMultiSelectGridInteractions_: Story = {
73
+ play: async ({ canvasElement }) => {
74
+ updateValue.mockClear();
75
+ onSave.mockClear();
76
+ onSelectFilter.mockClear();
77
+
78
+ const canvas = within(canvasElement);
79
+
80
+ const getOption = (name: RegExp | string) => canvas.findByRole('menuitem', { name });
81
+
82
+ // Check enabled menu handles click
83
+ const zeroMenuOption = await getOption(/Zero/);
84
+ await expect(zeroMenuOption).toBeInTheDocument();
85
+
86
+ await userEvent.click(zeroMenuOption);
87
+ await userEvent.keyboard('{Tab}');
88
+ await expect(updateValue).toHaveBeenCalled();
89
+ await waitFor(() => expect(onSave).toHaveBeenCalledWith({ selectedRows: [], addValues: [0], removeValues: [] }));
90
+
91
+ const check = async (label: string) => {
92
+ const activeCell = canvasElement.ownerDocument.activeElement as HTMLElement | null;
93
+ await expect(activeCell?.innerText).toBe(label);
94
+ };
95
+
96
+ // Test left/right arrow
97
+ await userEvent.keyboard('{ArrowRight}');
98
+ await check('Three');
99
+ await userEvent.keyboard('{ArrowRight}');
100
+ await check('Zero');
101
+ await userEvent.keyboard('{ArrowLeft}');
102
+ await check('Three');
103
+ await userEvent.keyboard('{ArrowLeft}');
104
+ await check('Zero');
105
+
106
+ // Test tab to save
107
+ updateValue.mockClear();
108
+ onSave.mockClear();
109
+ await userEvent.tab();
110
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), 1); // 1 = Tab
111
+ await expect(onSave).toHaveBeenCalledWith({
112
+ selectedRows: [],
113
+ addValues: [0],
114
+ removeValues: [],
115
+ });
116
+
117
+ // Test shift+tab to save
118
+ updateValue.mockClear();
119
+ onSave.mockClear();
120
+ await userEvent.tab({ shift: true });
121
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), -1); // -1 = Shift + tab
122
+ await expect(onSave).toHaveBeenCalled();
123
+ },
124
124
  };
@@ -1,8 +1,4 @@
1
- import '../../../react-menu3/styles/index.scss';
2
- import '../../../styles/index.scss';
3
- import '@linzjs/lui/dist/scss/base.scss';
4
-
5
- import { StoryFn } from '@storybook/react-vite';
1
+ import { Meta, StoryFn, StoryObj } from '@storybook/react-vite';
6
2
  import { GridPopoverContext } from '../../../contexts/GridPopoverContext';
7
3
  import { useRef } from 'react';
8
4
  import { expect, fn, userEvent, within } from 'storybook/test';
@@ -16,12 +12,6 @@ import {
16
12
  wait,
17
13
  } from '../../..';
18
14
 
19
- export default {
20
- title: 'GridForm / Interactions',
21
- component: GridFormMultiSelect,
22
- args: {},
23
- };
24
-
25
15
  const updateValue = fn((saveFn: (selectedRows: any[]) => Promise<boolean>, _tabDirection: 1 | 0 | -1) => saveFn([]));
26
16
 
27
17
  const onSave = fn();
@@ -76,111 +66,121 @@ const Template: StoryFn<typeof GridFormMultiSelect> = (props: GridFormMultiSelec
76
66
  );
77
67
  };
78
68
 
79
- export const GridFormMultiSelectInteractions_: typeof Template = Template.bind({});
80
- GridFormMultiSelectInteractions_.play = async ({ canvasElement }) => {
81
- updateValue.mockClear();
82
- onSave.mockClear();
83
- onSelectFilter.mockClear();
84
-
85
- const canvas = within(canvasElement);
86
-
87
- const getOption = (name: RegExp | string) => canvas.findByRole('menuitem', { name });
88
-
89
- // Check enabled menu handles click
90
- const zeroMenuOption = await getOption(/Zero/);
91
- expect(zeroMenuOption).toBeInTheDocument();
92
-
93
- await userEvent.click(zeroMenuOption);
94
- await userEvent.keyboard('{Tab}');
95
- expect(updateValue).toHaveBeenCalled();
96
- expect(onSave).toHaveBeenCalledWith({ selectedOptions: [options[0]], selectedRows: [] });
97
-
98
- // Check sub menu works
99
- const subTextInput = await getOption(/Sub component/);
100
- expect(subTextInput).toBeInTheDocument();
101
-
102
- expect(canvas.queryByPlaceholderText('Text input')).not.toBeInTheDocument();
103
-
104
- await userEvent.click(subTextInput);
105
- const textInput = await canvas.findByPlaceholderText('Text input');
106
- expect(textInput).toBeInTheDocument();
107
- expect(await canvas.findByText('Must not be empty')).toBeInTheDocument();
108
-
109
- // textInput should be autofocus
110
- await userEvent.type(textInput, 'Hello');
111
- expect(await canvas.findByText('Press enter or tab to save')).toBeInTheDocument();
112
-
113
- // Test tab to save
114
- updateValue.mockClear();
115
- onSave.mockClear();
116
- await userEvent.tab();
117
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), 1); // 1 = Tab
118
- expect(onSave).toHaveBeenCalledWith({
119
- selectedRows: [],
120
- selectedOptions: [
121
- { label: 'Zero', value: 0, checked: true },
122
- { label: 'Sub component', value: 2, checked: true, subValue: 'Hello', subComponent: expect.anything() },
123
- ],
124
- });
125
-
126
- // Test shift+tab to save
127
- updateValue.mockClear();
128
- onSave.mockClear();
129
- await userEvent.tab({ shift: true });
130
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), -1); // -1 = Shift + tab
131
- expect(onSave).toHaveBeenCalled();
132
-
133
- // Test escape to not save
134
- updateValue.mockClear();
135
- onSave.mockClear();
136
- await userEvent.type(textInput, '{Escape}');
137
- // expect(updateValue).not.toHaveBeenCalled();
138
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), 0);
139
- expect(onSave).not.toHaveBeenCalled();
140
-
141
- // Test invalid value doesn't save
142
- updateValue.mockClear();
143
- onSave.mockClear();
144
- await userEvent.clear(textInput);
145
- await userEvent.type(textInput, '{Enter}');
146
- expect(updateValue).not.toHaveBeenCalled();
147
- expect(onSave).not.toHaveBeenCalled();
148
-
149
- // Test filter
150
- const filterText = await canvas.findByPlaceholderText('Filter...');
151
- await userEvent.type(filterText, 'o');
152
- await wait(500);
153
- expect(canvas.queryByText('One')).toBeInTheDocument();
154
- expect(canvas.queryByText('Other')).toBeInTheDocument();
155
- await userEvent.type(filterText, 'n');
156
- expect(canvas.queryByText('One')).toBeInTheDocument();
157
- expect(canvas.queryByText('Zero')).not.toBeInTheDocument();
158
- expect(canvas.queryByText('Sub component')).not.toBeInTheDocument();
159
- expect(canvas.queryByText('Other')).not.toBeInTheDocument();
160
-
161
- await userEvent.type(filterText, 'x');
162
- expect(canvas.queryByText('One')).not.toBeInTheDocument();
163
- expect(canvas.queryByText('No Options')).toBeInTheDocument();
164
-
165
- // Check enter works to add custom free-text
166
- await userEvent.type(filterText, '{Enter}');
167
- expect(onSelectFilter).toHaveBeenCalledWith({
168
- filter: 'onx',
169
- options: [
170
- {
171
- ...options[0],
172
- checked: true,
173
- },
174
- {
175
- ...options[1],
176
- },
177
- {
178
- ...options[2],
179
- checked: true,
180
- },
181
- {
182
- ...options[3],
183
- },
184
- ],
185
- });
69
+ const meta: Meta<typeof Template> = {
70
+ title: 'GridForm / Interactions',
71
+ component: Template,
72
+ args: {},
73
+ };
74
+ export default meta;
75
+
76
+ type Story = StoryObj<typeof meta>;
77
+
78
+ export const GridFormMultiSelectInteractions_: Story = {
79
+ play: async ({ canvasElement }) => {
80
+ updateValue.mockClear();
81
+ onSave.mockClear();
82
+ onSelectFilter.mockClear();
83
+
84
+ const canvas = within(canvasElement);
85
+
86
+ const getOption = (name: RegExp | string) => canvas.findByRole('menuitem', { name });
87
+
88
+ // Check enabled menu handles click
89
+ const zeroMenuOption = await getOption(/Zero/);
90
+ await expect(zeroMenuOption).toBeInTheDocument();
91
+
92
+ await userEvent.click(zeroMenuOption);
93
+ await userEvent.keyboard('{Tab}');
94
+ await expect(updateValue).toHaveBeenCalled();
95
+ await expect(onSave).toHaveBeenCalledWith({ selectedOptions: [options[0]], selectedRows: [] });
96
+
97
+ // Check sub menu works
98
+ const subTextInput = await getOption(/Sub component/);
99
+ await expect(subTextInput).toBeInTheDocument();
100
+
101
+ await expect(canvas.queryByPlaceholderText('Text input')).not.toBeInTheDocument();
102
+
103
+ await userEvent.click(subTextInput);
104
+ const textInput = await canvas.findByPlaceholderText('Text input');
105
+ await expect(textInput).toBeInTheDocument();
106
+ await expect(await canvas.findByText('Must not be empty')).toBeInTheDocument();
107
+
108
+ // textInput should be autofocus
109
+ await userEvent.type(textInput, 'Hello');
110
+ await expect(await canvas.findByText('Press enter or tab to save')).toBeInTheDocument();
111
+
112
+ // Test tab to save
113
+ updateValue.mockClear();
114
+ onSave.mockClear();
115
+ await userEvent.tab();
116
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), 1); // 1 = Tab
117
+ await expect(onSave).toHaveBeenCalledWith({
118
+ selectedRows: [],
119
+ selectedOptions: [
120
+ { label: 'Zero', value: 0, checked: true },
121
+ { label: 'Sub component', value: 2, checked: true, subValue: 'Hello', subComponent: expect.anything() },
122
+ ],
123
+ });
124
+
125
+ // Test shift+tab to save
126
+ updateValue.mockClear();
127
+ onSave.mockClear();
128
+ await userEvent.tab({ shift: true });
129
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), -1); // -1 = Shift + tab
130
+ await expect(onSave).toHaveBeenCalled();
131
+
132
+ // Test escape to not save
133
+ updateValue.mockClear();
134
+ onSave.mockClear();
135
+ await userEvent.type(textInput, '{Escape}');
136
+ // expect(updateValue).not.toHaveBeenCalled();
137
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), 0);
138
+ await expect(onSave).not.toHaveBeenCalled();
139
+
140
+ // Test invalid value doesn't save
141
+ updateValue.mockClear();
142
+ onSave.mockClear();
143
+ await userEvent.clear(textInput);
144
+ await userEvent.type(textInput, '{Enter}');
145
+ await expect(updateValue).not.toHaveBeenCalled();
146
+ await expect(onSave).not.toHaveBeenCalled();
147
+
148
+ // Test filter
149
+ const filterText = await canvas.findByPlaceholderText('Filter...');
150
+ await userEvent.type(filterText, 'o');
151
+ await wait(500);
152
+ await expect(canvas.queryByText('One')).toBeInTheDocument();
153
+ await expect(canvas.queryByText('Other')).toBeInTheDocument();
154
+ await userEvent.type(filterText, 'n');
155
+ await expect(canvas.queryByText('One')).toBeInTheDocument();
156
+ await expect(canvas.queryByText('Zero')).not.toBeInTheDocument();
157
+ await expect(canvas.queryByText('Sub component')).not.toBeInTheDocument();
158
+ await expect(canvas.queryByText('Other')).not.toBeInTheDocument();
159
+
160
+ await userEvent.type(filterText, 'x');
161
+ await expect(canvas.queryByText('One')).not.toBeInTheDocument();
162
+ await expect(canvas.queryByText('No Options')).toBeInTheDocument();
163
+
164
+ // Check enter works to add custom free-text
165
+ await userEvent.type(filterText, '{Enter}');
166
+ await expect(onSelectFilter).toHaveBeenCalledWith({
167
+ filter: 'onx',
168
+ options: [
169
+ {
170
+ ...options[0],
171
+ checked: true,
172
+ },
173
+ {
174
+ ...options[1],
175
+ },
176
+ {
177
+ ...options[2],
178
+ checked: true,
179
+ },
180
+ {
181
+ ...options[3],
182
+ },
183
+ ],
184
+ });
185
+ },
186
186
  };