@patternfly/react-templates 1.1.0-prerelease.39 → 1.1.0-prerelease.40
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 +4 -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/TypeaheadSelect.d.ts +7 -3
- package/dist/esm/components/Select/TypeaheadSelect.d.ts.map +1 -1
- package/dist/esm/components/Select/TypeaheadSelect.js +66 -58
- package/dist/esm/components/Select/TypeaheadSelect.js.map +1 -1
- package/dist/js/components/Select/TypeaheadSelect.d.ts +7 -3
- package/dist/js/components/Select/TypeaheadSelect.d.ts.map +1 -1
- package/dist/js/components/Select/TypeaheadSelect.js +66 -58
- package/dist/js/components/Select/TypeaheadSelect.js.map +1 -1
- package/dist/umd/assets/{output-DtM3geql.css → output-Cfyy993h.css} +3797 -3797
- package/dist/umd/react-templates.min.js +1 -1
- package/package.json +2 -2
- package/src/components/Select/TypeaheadSelect.tsx +69 -61
- package/src/components/Select/__tests__/TypeaheadSelect.test.tsx +36 -72
- package/src/components/Select/__tests__/__snapshots__/TypeaheadSelect.test.tsx.snap +3 -3
- package/src/components/Select/examples/SelectTemplates.md +3 -0
- package/src/components/Select/examples/TypeaheadSelectDemo.tsx +9 -7
|
@@ -30,6 +30,9 @@ import { SimpleSelect, CheckboxSelect, TypeaheadSelect, MultiTypeaheadSelect } f
|
|
|
30
30
|
|
|
31
31
|
### Typeahead
|
|
32
32
|
|
|
33
|
+
Typeahead is a select variant that replaces the typical button toggle for opening the select menu with a text input and button toggle combo. As a user enters characters into the text input, the menu options will be filtered to match.
|
|
34
|
+
|
|
35
|
+
Selection can be given by either the `selected` property or by setting `isSelected` on the option that is currently selected.
|
|
33
36
|
```ts file="TypeaheadSelectDemo.tsx"
|
|
34
37
|
|
|
35
38
|
```
|
|
@@ -18,9 +18,9 @@ export const SelectTypeaheadDemo: React.FunctionComponent = () => {
|
|
|
18
18
|
const [isCreatable, setIsCreatable] = React.useState<boolean>(false);
|
|
19
19
|
const [isCreateOptionOnTop, setIsCreateOptionOnTop] = React.useState<boolean>(false);
|
|
20
20
|
|
|
21
|
-
const
|
|
22
|
-
() => options.map((o) => ({ ...o
|
|
23
|
-
[options
|
|
21
|
+
const selectOptions = React.useMemo<TypeaheadSelectOption[]>(
|
|
22
|
+
() => options.map((o) => ({ ...o })).sort((a, b) => a.content.localeCompare(b.content)),
|
|
23
|
+
[options]
|
|
24
24
|
);
|
|
25
25
|
|
|
26
26
|
React.useEffect(() => {
|
|
@@ -30,16 +30,18 @@ export const SelectTypeaheadDemo: React.FunctionComponent = () => {
|
|
|
30
30
|
return (
|
|
31
31
|
<>
|
|
32
32
|
<TypeaheadSelect
|
|
33
|
-
|
|
33
|
+
selectOptions={selectOptions}
|
|
34
34
|
placeholder="Select a state"
|
|
35
35
|
noOptionsFoundMessage={(filter) => `No state was found for "${filter}"`}
|
|
36
36
|
onClearSelection={() => setSelected(undefined)}
|
|
37
|
-
onSelect={(_ev,
|
|
37
|
+
onSelect={(_ev, selectedValue) => {
|
|
38
|
+
const selection = String(selectedValue);
|
|
38
39
|
if (!options.find((o) => o.value === selection)) {
|
|
39
|
-
setOptions([...options, { content:
|
|
40
|
+
setOptions([...options, { content: selection, value: selection }]);
|
|
40
41
|
}
|
|
41
|
-
setSelected(
|
|
42
|
+
setSelected((prev) => (prev !== selection ? selection : undefined));
|
|
42
43
|
}}
|
|
44
|
+
selected={selected}
|
|
43
45
|
isCreatable={isCreatable}
|
|
44
46
|
isCreateOptionOnTop={isCreateOptionOnTop}
|
|
45
47
|
/>
|