@patternfly/react-templates 6.3.0-prerelease.3 → 6.3.0-prerelease.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +116 -0
- package/components/package.json +1 -1
- package/dist/dynamic/components/Dropdown/package.json +1 -1
- package/dist/dynamic/components/Select/package.json +1 -1
- package/dist/esm/components/Select/MultiTypeaheadSelect.d.ts +5 -0
- package/dist/esm/components/Select/MultiTypeaheadSelect.d.ts.map +1 -1
- package/dist/esm/components/Select/MultiTypeaheadSelect.js +7 -6
- package/dist/esm/components/Select/MultiTypeaheadSelect.js.map +1 -1
- package/dist/js/components/Select/MultiTypeaheadSelect.d.ts +5 -0
- package/dist/js/components/Select/MultiTypeaheadSelect.d.ts.map +1 -1
- package/dist/js/components/Select/MultiTypeaheadSelect.js +7 -6
- package/dist/js/components/Select/MultiTypeaheadSelect.js.map +1 -1
- package/dist/umd/assets/{output-C-1JlgVC.css → output-CW-sUZIq.css} +2463 -2231
- package/dist/umd/react-templates.min.js +1 -1
- package/package.json +6 -6
- package/src/components/Select/MultiTypeaheadSelect.tsx +14 -6
- package/src/components/Select/__tests__/MultiTypeaheadSelect.test.tsx +31 -1
- package/src/components/Select/__tests__/__snapshots__/MultiTypeaheadSelect.test.tsx.snap +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { forwardRef, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { Button } from '@patternfly/react-core/dist/esm/components/Button';
|
|
3
|
-
import { Label, LabelGroup } from '@patternfly/react-core/dist/esm/components/Label';
|
|
3
|
+
import { Label, LabelGroup, LabelProps } from '@patternfly/react-core/dist/esm/components/Label';
|
|
4
4
|
import { MenuToggle, MenuToggleElement, MenuToggleProps } from '@patternfly/react-core/dist/esm/components/MenuToggle';
|
|
5
5
|
import {
|
|
6
6
|
Select,
|
|
@@ -51,6 +51,10 @@ export interface MultiTypeaheadSelectProps extends Omit<SelectProps, 'toggle' |
|
|
|
51
51
|
toggleWidth?: string;
|
|
52
52
|
/** Additional props passed to the toggle. */
|
|
53
53
|
toggleProps?: MenuToggleProps;
|
|
54
|
+
/** Additional props passed to each label of the selected option. */
|
|
55
|
+
labelProps?: LabelProps;
|
|
56
|
+
/** Initial value of the typeahead text input. */
|
|
57
|
+
initialInputValue?: string;
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSelectProps> = ({
|
|
@@ -65,13 +69,15 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
65
69
|
isDisabled,
|
|
66
70
|
toggleWidth,
|
|
67
71
|
toggleProps,
|
|
72
|
+
labelProps,
|
|
73
|
+
initialInputValue,
|
|
68
74
|
...props
|
|
69
75
|
}: MultiTypeaheadSelectProps) => {
|
|
70
76
|
const [isOpen, setIsOpen] = useState(false);
|
|
71
77
|
const [selected, setSelected] = useState<(string | number)[]>(
|
|
72
78
|
(initialOptions?.filter((o) => o.selected) ?? []).map((o) => o.value)
|
|
73
79
|
);
|
|
74
|
-
const [inputValue, setInputValue] = useState<string>();
|
|
80
|
+
const [inputValue, setInputValue] = useState<string>(initialInputValue);
|
|
75
81
|
const [selectOptions, setSelectOptions] = useState<MultiTypeaheadSelectOption[]>(initialOptions);
|
|
76
82
|
const [focusedItemIndex, setFocusedItemIndex] = useState<number | null>(null);
|
|
77
83
|
const [activeItemId, setActiveItemId] = useState<string | null>(null);
|
|
@@ -104,9 +110,6 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
104
110
|
}
|
|
105
111
|
];
|
|
106
112
|
}
|
|
107
|
-
|
|
108
|
-
// Open the menu when the input value changes and the new value is not empty
|
|
109
|
-
openMenu();
|
|
110
113
|
}
|
|
111
114
|
|
|
112
115
|
setSelectOptions(newSelectOptions);
|
|
@@ -170,6 +173,10 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
170
173
|
setInputValue(value);
|
|
171
174
|
onInputChange && onInputChange(value);
|
|
172
175
|
|
|
176
|
+
if (value && !isOpen) {
|
|
177
|
+
openMenu();
|
|
178
|
+
}
|
|
179
|
+
|
|
173
180
|
resetActiveAndFocusedItem();
|
|
174
181
|
};
|
|
175
182
|
|
|
@@ -302,10 +309,11 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
302
309
|
<Label
|
|
303
310
|
key={index}
|
|
304
311
|
datatest-id={`${selection}-chip`}
|
|
305
|
-
|
|
312
|
+
onClose={(ev) => {
|
|
306
313
|
ev.stopPropagation();
|
|
307
314
|
clearOption(ev, selection);
|
|
308
315
|
}}
|
|
316
|
+
{...labelProps}
|
|
309
317
|
>
|
|
310
318
|
{initialOptions.find((o) => o.value === selection)?.content}
|
|
311
319
|
</Label>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { render, screen, waitForElementToBeRemoved } from '@testing-library/react';
|
|
1
|
+
import { render, screen, waitForElementToBeRemoved, within } from '@testing-library/react';
|
|
2
2
|
import userEvent from '@testing-library/user-event';
|
|
3
3
|
import { MultiTypeaheadSelect } from '../MultiTypeaheadSelect';
|
|
4
4
|
import styles from '@patternfly/react-styles/css/components/Menu/menu';
|
|
@@ -413,6 +413,36 @@ describe('MultiTypeaheadSelect', () => {
|
|
|
413
413
|
expect(onInputKeyDownMock).toHaveBeenCalledTimes(1);
|
|
414
414
|
});
|
|
415
415
|
|
|
416
|
+
it('text input is empty by default', async () => {
|
|
417
|
+
render(<MultiTypeaheadSelect initialOptions={[]} />);
|
|
418
|
+
|
|
419
|
+
const input = screen.getByRole('combobox');
|
|
420
|
+
expect(input).toHaveValue('');
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
it('initialInputValue prop sets the default text input value', async () => {
|
|
424
|
+
const initialOptions = [
|
|
425
|
+
{ content: 'Option 1', value: 'option1' },
|
|
426
|
+
{ content: 'Option 2', value: 'option2' },
|
|
427
|
+
{ content: 'Option 3', value: 'option3' }
|
|
428
|
+
];
|
|
429
|
+
|
|
430
|
+
const user = userEvent.setup();
|
|
431
|
+
|
|
432
|
+
render(<MultiTypeaheadSelect initialInputValue={'Option 1'} initialOptions={initialOptions} />);
|
|
433
|
+
|
|
434
|
+
const input = screen.getByRole('combobox');
|
|
435
|
+
expect(input).toHaveValue('Option 1');
|
|
436
|
+
|
|
437
|
+
await user.click(input);
|
|
438
|
+
|
|
439
|
+
const menu = screen.getByRole('listbox');
|
|
440
|
+
const options = within(menu).getAllByRole('option');
|
|
441
|
+
|
|
442
|
+
expect(options).toHaveLength(1);
|
|
443
|
+
expect(options[0]).toHaveTextContent('Option 1');
|
|
444
|
+
});
|
|
445
|
+
|
|
416
446
|
it('Matches snapshot', async () => {
|
|
417
447
|
const initialOptions = [
|
|
418
448
|
{ content: 'Option 1', value: 'option1' },
|
|
@@ -34,7 +34,7 @@ exports[`MultiTypeaheadSelect Matches snapshot 1`] = `
|
|
|
34
34
|
<button
|
|
35
35
|
aria-label="Clear input value"
|
|
36
36
|
class="pf-v6-c-button pf-m-plain"
|
|
37
|
-
data-ouia-component-id="OUIA-Generated-Button-plain-
|
|
37
|
+
data-ouia-component-id="OUIA-Generated-Button-plain-23"
|
|
38
38
|
data-ouia-component-type="PF6/Button"
|
|
39
39
|
data-ouia-safe="true"
|
|
40
40
|
type="button"
|
|
@@ -63,7 +63,7 @@ exports[`MultiTypeaheadSelect Matches snapshot 1`] = `
|
|
|
63
63
|
aria-expanded="true"
|
|
64
64
|
aria-label="Multi select Typeahead menu toggle"
|
|
65
65
|
class="pf-v6-c-menu-toggle__button"
|
|
66
|
-
data-ouia-component-id="OUIA-Generated-MenuToggle-typeahead-
|
|
66
|
+
data-ouia-component-id="OUIA-Generated-MenuToggle-typeahead-20"
|
|
67
67
|
data-ouia-component-type="PF6/MenuToggle"
|
|
68
68
|
data-ouia-safe="true"
|
|
69
69
|
tabindex="-1"
|