playbook_ui 14.21.2 → 14.22.0.pre.rc.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.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +12 -3
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_close_on_select.jsx +42 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_close_on_select.md +1 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/index.js +2 -1
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownOption.tsx +14 -10
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownTrigger.tsx +26 -15
- data/dist/chunks/{_typeahead-BlPRej0F.js → _typeahead-CoOpeYom.js} +2 -2
- data/dist/chunks/{_weekday_stacked-CzxoxxCR.js → _weekday_stacked-B_jpa2Rz.js} +2 -2
- data/dist/chunks/lazysizes-B7xYodB-.js +1 -0
- data/dist/chunks/lib-D7Va7yqa.js +29 -0
- data/dist/chunks/{pb_form_validation-DyvJ8iPe.js → pb_form_validation-DSkdRDMf.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-doc.js +1 -1
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +9 -7
- data/dist/chunks/lazysizes-DHz07jlL.js +0 -1
- data/dist/chunks/lib-D4vXIZF5.js +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3237dbe64cf5d35651426b51605fc0a29d2774ace25902df2d835d3ba397cf45
|
4
|
+
data.tar.gz: 17dffcc35b1c8dc359a5f2e8496122e888f0981a8694642cf4b6f9b80db47095
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a17f0e817d78b24d5ba66cc346f107818a57cc657134501c1062adaee813936d1a22f86dbd6ba7fc57aeb72a6bd41a3d44b11a42e4df5e3aa996c4a557e594b
|
7
|
+
data.tar.gz: fd82408a056f7a0fdcfeff8c9d909f07eee2a76ad9a0ecb4de81ac333eee51a5d29262f7a331737390b29c497c85dcb303b96119eeeda81e6c406910d77b66a7
|
@@ -25,6 +25,7 @@ type DropdownProps = {
|
|
25
25
|
blankSelection?: string;
|
26
26
|
children?: React.ReactChild[] | React.ReactChild | React.ReactElement[];
|
27
27
|
className?: string;
|
28
|
+
closeOnSelection?: boolean;
|
28
29
|
formPillProps?: GenericObject;
|
29
30
|
dark?: boolean;
|
30
31
|
data?: { [key: string]: string };
|
@@ -55,6 +56,7 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
55
56
|
blankSelection = '',
|
56
57
|
children,
|
57
58
|
className,
|
59
|
+
closeOnSelection = true,
|
58
60
|
dark = false,
|
59
61
|
data = {},
|
60
62
|
defaultValue = {},
|
@@ -152,7 +154,7 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
152
154
|
if (!multiSelect) return optionsWithBlankSelection;
|
153
155
|
return optionsWithBlankSelection.filter((option: GenericObject) => !selectedArray.some((sel) => sel.label === option.label));
|
154
156
|
}, [optionsWithBlankSelection, selectedArray, multiSelect]);
|
155
|
-
|
157
|
+
|
156
158
|
const filteredOptions = useMemo(() => {
|
157
159
|
return availableOptions.filter((opt: GenericObject) =>
|
158
160
|
String(opt.label).toLowerCase().includes(filterItem.toLowerCase())
|
@@ -192,12 +194,18 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
192
194
|
return next;
|
193
195
|
});
|
194
196
|
setFilterItem("");
|
195
|
-
|
197
|
+
// Only close dropdown if closeOnSelection is true
|
198
|
+
if (closeOnSelection) {
|
199
|
+
setIsDropDownClosed(true);
|
200
|
+
}
|
196
201
|
} else {
|
197
202
|
setSelected(clickedItem);
|
198
203
|
setFilterItem("");
|
199
|
-
setIsDropDownClosed(true);
|
200
204
|
onSelect && onSelect(clickedItem);
|
205
|
+
// Only close dropdown if closeOnSelection is true
|
206
|
+
if (closeOnSelection) {
|
207
|
+
setIsDropDownClosed(true);
|
208
|
+
}
|
201
209
|
}
|
202
210
|
};
|
203
211
|
|
@@ -252,6 +260,7 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
252
260
|
<DropdownContext.Provider
|
253
261
|
value={{
|
254
262
|
autocomplete,
|
263
|
+
closeOnSelection,
|
255
264
|
dropdownContainerRef,
|
256
265
|
filteredOptions,
|
257
266
|
filterItem,
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import Dropdown from '../../pb_dropdown/_dropdown'
|
3
|
+
|
4
|
+
const DropdownCloseOnSelect = (props) => {
|
5
|
+
|
6
|
+
const options = [
|
7
|
+
{
|
8
|
+
label: "United States",
|
9
|
+
value: "United States",
|
10
|
+
},
|
11
|
+
{
|
12
|
+
label: "Canada",
|
13
|
+
value: "Canada",
|
14
|
+
},
|
15
|
+
{
|
16
|
+
label: "Pakistan",
|
17
|
+
value: "Pakistan",
|
18
|
+
}
|
19
|
+
];
|
20
|
+
|
21
|
+
|
22
|
+
return (
|
23
|
+
<div>
|
24
|
+
<Dropdown
|
25
|
+
closeOnSelection={false}
|
26
|
+
label="Default"
|
27
|
+
options={options}
|
28
|
+
{...props}
|
29
|
+
/>
|
30
|
+
<br />
|
31
|
+
<Dropdown
|
32
|
+
closeOnSelection={false}
|
33
|
+
label="Multi Select"
|
34
|
+
multiSelect
|
35
|
+
options={options}
|
36
|
+
{...props}
|
37
|
+
/>
|
38
|
+
</div>
|
39
|
+
)
|
40
|
+
}
|
41
|
+
|
42
|
+
export default DropdownCloseOnSelect
|
@@ -0,0 +1 @@
|
|
1
|
+
By default, the dropdown menu will close when a selection is made. You can prevent this behavior by using the `closeOnSelection` prop, which will leave the menu open after a selection is made when set to 'false'.
|
@@ -19,4 +19,5 @@ export { default as DropdownMultiSelect } from './_dropdown_multi_select.jsx'
|
|
19
19
|
export { default as DropdownMultiSelectDisplay } from './_dropdown_multi_select_display.jsx'
|
20
20
|
export { default as DropdownMultiSelectWithAutocomplete } from './_dropdown_multi_select_with_autocomplete.jsx'
|
21
21
|
export { default as DropdownMultiSelectWithDefault } from './_dropdown_multi_select_with_default.jsx'
|
22
|
-
export { default as DropdownMultiSelectWithCustomOptions } from './_dropdown_multi_select_with_custom_options.jsx'
|
22
|
+
export { default as DropdownMultiSelectWithCustomOptions } from './_dropdown_multi_select_with_custom_options.jsx'
|
23
|
+
export { default as DropdownCloseOnSelect } from './_dropdown_close_on_select.jsx'
|
@@ -25,7 +25,7 @@ type DropdownOptionProps = {
|
|
25
25
|
key?: string | number;
|
26
26
|
option?: GenericObject;
|
27
27
|
padding?: string;
|
28
|
-
}
|
28
|
+
} & GlobalProps;
|
29
29
|
|
30
30
|
const DropdownOption = (props: DropdownOptionProps) => {
|
31
31
|
const {
|
@@ -56,16 +56,17 @@ const DropdownOption = (props: DropdownOptionProps) => {
|
|
56
56
|
|
57
57
|
// When multiSelect, then if an option is selected, remove from dropdown
|
58
58
|
const isSelected = Array.isArray(selected)
|
59
|
-
|
60
|
-
|
59
|
+
? selected.some((item) => item.label === option?.label)
|
60
|
+
: (selected as GenericObject)?.label === option?.label;
|
61
61
|
|
62
|
-
|
63
62
|
if (!isItemMatchingFilter(option) || (multiSelect && isSelected)) {
|
64
63
|
return null;
|
65
64
|
}
|
65
|
+
|
66
66
|
const isFocused =
|
67
67
|
focusedOptionIndex >= 0 &&
|
68
68
|
filteredOptions[focusedOptionIndex].label === option?.label;
|
69
|
+
|
69
70
|
const focusedClass = isFocused && "focused";
|
70
71
|
|
71
72
|
const selectedClass = isSelected ? "selected" : "list";
|
@@ -91,7 +92,10 @@ const DropdownOption = (props: DropdownOptionProps) => {
|
|
91
92
|
className={classes}
|
92
93
|
id={id}
|
93
94
|
key={key}
|
94
|
-
onClick=
|
95
|
+
onClick={(e) => {
|
96
|
+
e.stopPropagation();
|
97
|
+
handleOptionClick(option);
|
98
|
+
}}
|
95
99
|
>
|
96
100
|
<ListItem
|
97
101
|
cursor="pointer"
|
@@ -100,12 +104,12 @@ const DropdownOption = (props: DropdownOptionProps) => {
|
|
100
104
|
key={option?.label}
|
101
105
|
padding="none"
|
102
106
|
>
|
103
|
-
|
107
|
+
{children ?
|
104
108
|
<div className="dropdown_option_wrapper">{children}</div> :
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
+
<Body dark={dark}
|
110
|
+
text={option?.label}
|
111
|
+
/>
|
112
|
+
}
|
109
113
|
</ListItem>
|
110
114
|
</div>
|
111
115
|
);
|
@@ -44,6 +44,7 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
|
|
44
44
|
|
45
45
|
const {
|
46
46
|
autocomplete,
|
47
|
+
closeOnSelection,
|
47
48
|
filterItem,
|
48
49
|
handleBackspace,
|
49
50
|
handleChange,
|
@@ -54,6 +55,7 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
|
|
54
55
|
isInputFocused,
|
55
56
|
multiSelect,
|
56
57
|
selected,
|
58
|
+
setIsDropDownClosed,
|
57
59
|
setIsInputFocused,
|
58
60
|
toggleDropdown,
|
59
61
|
} = useContext(DropdownContext);
|
@@ -103,11 +105,26 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
|
|
103
105
|
? placeholder
|
104
106
|
: "Select...";
|
105
107
|
|
108
|
+
// Click handler that respects closeOnSelection
|
109
|
+
const handleInputClick = (e: React.MouseEvent) => {
|
110
|
+
e.stopPropagation(); // keep the wrapper's handler from firing
|
111
|
+
if (isDropDownClosed) {
|
112
|
+
// Always open if closed
|
113
|
+
setIsDropDownClosed(false);
|
114
|
+
} else if (!closeOnSelection) {
|
115
|
+
// Keep open if closeOnSelection is false
|
116
|
+
return;
|
117
|
+
} else {
|
118
|
+
// Default behavior - toggle
|
119
|
+
toggleDropdown();
|
120
|
+
}
|
121
|
+
};
|
122
|
+
|
106
123
|
return (
|
107
|
-
<div {...ariaProps}
|
108
|
-
{...dataProps}
|
124
|
+
<div {...ariaProps}
|
125
|
+
{...dataProps}
|
109
126
|
{...htmlProps}
|
110
|
-
className={classes}
|
127
|
+
className={classes}
|
111
128
|
id={id}
|
112
129
|
>
|
113
130
|
{
|
@@ -145,7 +162,7 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
|
|
145
162
|
{customDisplay ? (
|
146
163
|
<Flex align="center">
|
147
164
|
{customDisplay}
|
148
|
-
<Body dark={dark}
|
165
|
+
<Body dark={dark}
|
149
166
|
paddingLeft={`${joinedLabels ? "xs" : "none"}`}
|
150
167
|
>
|
151
168
|
{customDisplayPlaceholder}
|
@@ -164,10 +181,7 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
|
|
164
181
|
<input
|
165
182
|
className="dropdown_input"
|
166
183
|
onChange={handleChange}
|
167
|
-
onClick={
|
168
|
-
e.stopPropagation();// keep the wrapper’s handler from firing
|
169
|
-
toggleDropdown();
|
170
|
-
}}
|
184
|
+
onClick={handleInputClick}
|
171
185
|
onFocus={() => setIsInputFocused(true)}
|
172
186
|
onKeyDown={(e) => {
|
173
187
|
handleKeyDown(e);
|
@@ -186,8 +200,8 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
|
|
186
200
|
)}
|
187
201
|
</>
|
188
202
|
) : (
|
189
|
-
<Body dark={dark}
|
190
|
-
text={defaultDisplayPlaceholder}
|
203
|
+
<Body dark={dark}
|
204
|
+
text={defaultDisplayPlaceholder}
|
191
205
|
/>
|
192
206
|
)
|
193
207
|
)}
|
@@ -195,10 +209,7 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
|
|
195
209
|
<input
|
196
210
|
className="dropdown_input"
|
197
211
|
onChange={handleChange}
|
198
|
-
onClick={
|
199
|
-
e.stopPropagation();// keep the wrapper’s handler from firing
|
200
|
-
toggleDropdown();
|
201
|
-
}}
|
212
|
+
onClick={handleInputClick}
|
202
213
|
onFocus={() => setIsInputFocused(true)}
|
203
214
|
onKeyDown={handleKeyDown}
|
204
215
|
placeholder={
|
@@ -223,7 +234,7 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
|
|
223
234
|
onClick: (e: Event) => {e.stopPropagation();handleWrapperClick()}
|
224
235
|
}}
|
225
236
|
key={`${isDropDownClosed ? "chevron-down" : "chevron-up"}`}
|
226
|
-
>
|
237
|
+
>
|
227
238
|
{
|
228
239
|
selectedArray.length > 0 && (
|
229
240
|
<div onClick={(e)=>{e.stopPropagation();handleBackspace()}}>
|