Skip to content

Commit 354f4f9

Browse files
authored
feat(MultiTypeaheadSelect): make labels removable and customizable (#11774)
* feat(MultiTypeaheadSelect): make labels removable and customizable * docs(Select): remove duplicate paragraphs * test: update jest snapshot
1 parent 6da1d9d commit 354f4f9

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

packages/react-core/src/components/Select/examples/Select.md

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ By default, the menu toggle will display a badge to indicate the number of items
7878
```
7979

8080
### Typeahead
81-
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.
82-
83-
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.
84-
85-
To make a typeahead, pass `variant=typeahead` into the `<MenuToggle>` component and link an `onClick` function to the `<TextInputGroupMain>` component.
8681

8782
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.
8883

@@ -93,13 +88,6 @@ To make a typeahead, pass `variant=typeahead` into the `<MenuToggle>` component
9388
```
9489

9590
### Typeahead with create option
96-
If a user enters a value into a typeahead select menu that does not exist, you can allow them to create an option of that value.
97-
98-
If a user enters a value into a typeahead select menu that does not exist, you can allow them to create an option of that value.
99-
100-
To enable the creation ability, pass a predetermined `value` into a `<SelectOption>` component. You can use the `placeholder` property to change the default text shown in the text input.
101-
102-
The following example outlines the code implementation required to create a working typeahead menu that allows for creation.
10391

10492
If a user enters a value into a typeahead select menu that does not exist, you can allow them to create an option of that value.
10593

@@ -111,14 +99,9 @@ The following example outlines the code implementation required to create a work
11199

112100
```
113101

114-
### Multiple typeahead with chips
115-
A multiple typeahead can be used to allow users to select multiple options from a list. Additionally, you can render a chip group to be placed in the select toggle.
116-
117-
A multiple typeahead can be used to allow users to select multiple options from a list. Additionally, you can render a chip group to be placed in the select toggle.
118-
119-
When more items than the allowed limit are selected, overflowing items will be hidden under a "more" button. The following example hides items after more than 3 are selected. To show hidden items, select the “more” button. Select "show less" to hide extra items again.
102+
### Multiple typeahead with labels
120103

121-
A multiple typeahead can be used to allow users to select multiple options from a list. Additionally, you can render a chip group to be placed in the select toggle.
104+
A multiple typeahead can be used to allow users to select multiple options from a list. Additionally, you can render a label group to be placed in the select toggle.
122105

123106
When more items than the allowed limit are selected, overflowing items will be hidden under a "more" button. The following example hides items after more than 3 are selected. To show hidden items, select the “more” button. Select "show less" to hide extra items again.
124107

@@ -127,20 +110,14 @@ When more items than the allowed limit are selected, overflowing items will be h
127110
```
128111

129112
### Multiple typeahead with create option
130-
If the text that is entered into a typeahead doesn't match a menu item, users can choose to create a new option that matches the text input. You can also combine this create functionality with a chip group to display created items as chips."
131113

132-
If the text that is entered into a typeahead doesn't match a menu item, users can choose to create a new option that matches the text input. You can also combine this create functionality with a chip group to display created items as chips."
133-
134-
If the text that is entered into a typeahead doesn't match a menu item, users can choose to create a new option that matches the text input. You can also combine this create functionality with a chip group to display created items as chips."
114+
If the text that is entered into a typeahead doesn't match a menu item, users can choose to create a new option that matches the text input. You can also combine this create functionality with a label group to display created items as labels.
135115

136116
```ts file="./SelectMultiTypeaheadCreatable.tsx"
137117

138118
```
139119

140120
### Multiple typeahead with checkboxes
141-
By default, a multiple typeahead select allows you to select multiple menu items, placing a checkmark beside selected items. Like basic checkbox select menus, you can add checkboxes to your menu items. This approach may be more accurate and comprehensive for more complex menu scenarios like filtering.
142-
143-
By default, a multiple typeahead select allows you to select multiple menu items, placing a checkmark beside selected items. Like basic checkbox select menus, you can add checkboxes to your menu items. This approach may be more accurate and comprehensive for more complex menu scenarios like filtering.
144121

145122
By default, a multiple typeahead select allows you to select multiple menu items, placing a checkmark beside selected items. Like basic checkbox select menus, you can add checkboxes to your menu items. This approach may be more accurate and comprehensive for more complex menu scenarios like filtering.
146123

packages/react-templates/src/components/Select/MultiTypeaheadSelect.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { forwardRef, useEffect, useRef, useState } from 'react';
22
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';
44
import { MenuToggle, MenuToggleElement, MenuToggleProps } from '@patternfly/react-core/dist/esm/components/MenuToggle';
55
import {
66
Select,
@@ -51,6 +51,8 @@ export interface MultiTypeaheadSelectProps extends Omit<SelectProps, 'toggle' |
5151
toggleWidth?: string;
5252
/** Additional props passed to the toggle. */
5353
toggleProps?: MenuToggleProps;
54+
/** Additional props passed to each label of the selected option. */
55+
labelProps?: LabelProps;
5456
}
5557

5658
export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSelectProps> = ({
@@ -65,6 +67,7 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
6567
isDisabled,
6668
toggleWidth,
6769
toggleProps,
70+
labelProps,
6871
...props
6972
}: MultiTypeaheadSelectProps) => {
7073
const [isOpen, setIsOpen] = useState(false);
@@ -302,10 +305,11 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
302305
<Label
303306
key={index}
304307
datatest-id={`${selection}-chip`}
305-
onClick={(ev) => {
308+
onClose={(ev) => {
306309
ev.stopPropagation();
307310
clearOption(ev, selection);
308311
}}
312+
{...labelProps}
309313
>
310314
{initialOptions.find((o) => o.value === selection)?.content}
311315
</Label>

packages/react-templates/src/components/Select/__tests__/__snapshots__/MultiTypeaheadSelect.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ exports[`MultiTypeaheadSelect Matches snapshot 1`] = `
3434
<button
3535
aria-label="Clear input value"
3636
class="pf-v6-c-button pf-m-plain"
37-
data-ouia-component-id="OUIA-Generated-Button-plain-18"
37+
data-ouia-component-id="OUIA-Generated-Button-plain-21"
3838
data-ouia-component-type="PF6/Button"
3939
data-ouia-safe="true"
4040
type="button"

0 commit comments

Comments
 (0)