@patternfly/react-templates 6.3.0-prerelease.9 → 6.3.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.
- package/CHANGELOG.md +112 -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 +2 -0
- package/dist/esm/components/Select/MultiTypeaheadSelect.d.ts.map +1 -1
- package/dist/esm/components/Select/MultiTypeaheadSelect.js +5 -4
- package/dist/esm/components/Select/MultiTypeaheadSelect.js.map +1 -1
- package/dist/js/components/Select/MultiTypeaheadSelect.d.ts +2 -0
- package/dist/js/components/Select/MultiTypeaheadSelect.d.ts.map +1 -1
- package/dist/js/components/Select/MultiTypeaheadSelect.js +5 -4
- package/dist/js/components/Select/MultiTypeaheadSelect.js.map +1 -1
- package/dist/umd/assets/{output-DAKlLmNG.css → output-D5LnGQsG.css} +2217 -1986
- package/dist/umd/react-templates.min.js +1 -1
- package/package.json +6 -6
- package/src/components/Select/MultiTypeaheadSelect.tsx +8 -4
- package/src/components/Select/__tests__/MultiTypeaheadSelect.test.tsx +31 -1
- package/src/components/Select/__tests__/__snapshots__/MultiTypeaheadSelect.test.tsx.snap +2 -2
|
@@ -53,6 +53,8 @@ export interface MultiTypeaheadSelectProps extends Omit<SelectProps, 'toggle' |
|
|
|
53
53
|
toggleProps?: MenuToggleProps;
|
|
54
54
|
/** Additional props passed to each label of the selected option. */
|
|
55
55
|
labelProps?: LabelProps;
|
|
56
|
+
/** Initial value of the typeahead text input. */
|
|
57
|
+
initialInputValue?: string;
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSelectProps> = ({
|
|
@@ -68,13 +70,14 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
68
70
|
toggleWidth,
|
|
69
71
|
toggleProps,
|
|
70
72
|
labelProps,
|
|
73
|
+
initialInputValue,
|
|
71
74
|
...props
|
|
72
75
|
}: MultiTypeaheadSelectProps) => {
|
|
73
76
|
const [isOpen, setIsOpen] = useState(false);
|
|
74
77
|
const [selected, setSelected] = useState<(string | number)[]>(
|
|
75
78
|
(initialOptions?.filter((o) => o.selected) ?? []).map((o) => o.value)
|
|
76
79
|
);
|
|
77
|
-
const [inputValue, setInputValue] = useState<string>();
|
|
80
|
+
const [inputValue, setInputValue] = useState<string>(initialInputValue);
|
|
78
81
|
const [selectOptions, setSelectOptions] = useState<MultiTypeaheadSelectOption[]>(initialOptions);
|
|
79
82
|
const [focusedItemIndex, setFocusedItemIndex] = useState<number | null>(null);
|
|
80
83
|
const [activeItemId, setActiveItemId] = useState<string | null>(null);
|
|
@@ -107,9 +110,6 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
107
110
|
}
|
|
108
111
|
];
|
|
109
112
|
}
|
|
110
|
-
|
|
111
|
-
// Open the menu when the input value changes and the new value is not empty
|
|
112
|
-
openMenu();
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
setSelectOptions(newSelectOptions);
|
|
@@ -173,6 +173,10 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
173
173
|
setInputValue(value);
|
|
174
174
|
onInputChange && onInputChange(value);
|
|
175
175
|
|
|
176
|
+
if (value && !isOpen) {
|
|
177
|
+
openMenu();
|
|
178
|
+
}
|
|
179
|
+
|
|
176
180
|
resetActiveAndFocusedItem();
|
|
177
181
|
};
|
|
178
182
|
|
|
@@ -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"
|