playbook_ui 14.15.0.pre.rc.3 → 14.15.0.pre.rc.4
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_overlay/_overlay.scss +13 -0
- data/app/pb_kits/playbook/pb_overlay/_overlay.tsx +7 -1
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_hide_scroll_bar.html.erb +11 -0
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_hide_scroll_bar.jsx +37 -0
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_hide_scroll_bar_rails.md +1 -0
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_hide_scroll_bar_react.md +1 -0
- data/app/pb_kits/playbook/pb_overlay/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_overlay/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_overlay/overlay.rb +7 -1
- data/app/pb_kits/playbook/pb_overlay/overlay.test.jsx +12 -0
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.tsx +34 -1
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_dynamic_options.html.erb +45 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_dynamic_options.md +5 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_dynamic_options_pure_rails.html.erb +33 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_dynamic_options_pure_rails.md +3 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_typeahead/index.ts +61 -8
- data/app/pb_kits/playbook/pb_typeahead/typeahead.rb +13 -1
- data/dist/chunks/{_typeahead-BGTMEmj7.js → _typeahead-NXKDTf__.js} +2 -2
- data/dist/chunks/{_weekday_stacked-De2TduOp.js → _weekday_stacked-DtCYkCXM.js} +2 -2
- data/dist/chunks/{lib-Fr78pbpF.js → lib-Dmay5Z6U.js} +1 -1
- data/dist/chunks/{pb_form_validation-CN51bfsD.js → pb_form_validation-DdP7BnVX.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/dist/playbook.css +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +14 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a671aef2ddd39a78ec98fcb4073566d8d8c07c887e206ef6e83c6bea4bbeae07
|
4
|
+
data.tar.gz: 79a8b005d92dfb2a80c0908349254e76a931f8e366abccbdd079bcf3b57725bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e1497589d4831e05816145ea26dd5f174b94d035cdfd46ec112f973ad6ffa860821535adced274c664a81dcd356b14876a11f5162a6bb6d1a0a2fda12038799
|
7
|
+
data.tar.gz: 985f3701953d47a71657c909d63303cfe60413b0a374bafc96f611fbb477b4262ab4b5011c16c31e124ca05581a66af587c7d6d15b5e99997f2efd2cd43d5ad0
|
@@ -69,4 +69,17 @@ $overlay_colors: (
|
|
69
69
|
pointer-events: none;
|
70
70
|
z-index: 1;
|
71
71
|
}
|
72
|
+
|
73
|
+
&.overlay-hide-scrollbar {
|
74
|
+
& [class*="overflow_x_auto"],
|
75
|
+
& [class*="overflow_y_auto"],
|
76
|
+
& [class*="overflow_auto"] {
|
77
|
+
&::-webkit-scrollbar {
|
78
|
+
display: none !important;
|
79
|
+
}
|
80
|
+
|
81
|
+
-ms-overflow-style: none !important;
|
82
|
+
scrollbar-width: none !important;
|
83
|
+
}
|
84
|
+
}
|
72
85
|
}
|
@@ -11,6 +11,7 @@ export type OverlayChildrenProps = {
|
|
11
11
|
dynamic?: boolean,
|
12
12
|
position: string,
|
13
13
|
size: string,
|
14
|
+
scrollBarNone?: boolean,
|
14
15
|
}
|
15
16
|
|
16
17
|
type OverlayProps = {
|
@@ -23,6 +24,8 @@ type OverlayProps = {
|
|
23
24
|
htmlOptions?: { [key: string]: string | number | boolean | (() => void) },
|
24
25
|
id?: string,
|
25
26
|
layout: { [key: string]: string },
|
27
|
+
scrollBarNone?: boolean,
|
28
|
+
|
26
29
|
}
|
27
30
|
|
28
31
|
const Overlay = (props: OverlayProps) => {
|
@@ -36,11 +39,12 @@ const Overlay = (props: OverlayProps) => {
|
|
36
39
|
htmlOptions = {},
|
37
40
|
id,
|
38
41
|
layout = { "bottom": "full" },
|
42
|
+
scrollBarNone = false,
|
39
43
|
} = props
|
40
44
|
|
41
45
|
const ariaProps = buildAriaProps(aria)
|
42
46
|
const dataProps = buildDataProps(data)
|
43
|
-
const classes = classnames(buildCss('pb_overlay'), globalProps(props), className)
|
47
|
+
const classes = classnames(buildCss('pb_overlay'), { 'overlay-hide-scrollbar': scrollBarNone }, globalProps(props), className )
|
44
48
|
const htmlProps = buildHtmlProps(htmlOptions)
|
45
49
|
const dynamicInlineProps = globalInlineProps(props)
|
46
50
|
|
@@ -68,12 +72,14 @@ const Overlay = (props: OverlayProps) => {
|
|
68
72
|
children,
|
69
73
|
color,
|
70
74
|
position: getPosition(),
|
75
|
+
scrollBarNone,
|
71
76
|
size: getSize()
|
72
77
|
}) : OverlayToken({
|
73
78
|
children,
|
74
79
|
color,
|
75
80
|
dynamic: dynamic,
|
76
81
|
position: getPosition(),
|
82
|
+
scrollBarNone,
|
77
83
|
size: getSize()
|
78
84
|
})
|
79
85
|
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= pb_rails("overlay", props: { layout: { "x": "xl" }, color: "card_light", scroll_bar_none: true }) do %>
|
2
|
+
<%= pb_rails("flex", props: { column_gap: "lg", orientation: "row", overflow_x: "auto" }) do %>
|
3
|
+
<% 15.times do %>
|
4
|
+
<%= pb_rails("flex/flex_item") do %>
|
5
|
+
<%= pb_rails("card") do %>
|
6
|
+
Card content
|
7
|
+
<% end %>
|
8
|
+
<% end %>
|
9
|
+
<% end %>
|
10
|
+
<% end %>
|
11
|
+
<% end %>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import {
|
3
|
+
Overlay,
|
4
|
+
Card,
|
5
|
+
Flex,
|
6
|
+
FlexItem,
|
7
|
+
} from 'playbook-ui'
|
8
|
+
|
9
|
+
const InlineCardsExample = () => {
|
10
|
+
return (
|
11
|
+
<Flex
|
12
|
+
columnGap="lg"
|
13
|
+
orientation="row"
|
14
|
+
overflowX="auto"
|
15
|
+
>
|
16
|
+
{Array.from({ length: 15 }, (_, index) => (
|
17
|
+
<FlexItem key={index}>
|
18
|
+
<Card>{"Card Content"}</Card>
|
19
|
+
</FlexItem>
|
20
|
+
))}
|
21
|
+
</Flex>
|
22
|
+
)
|
23
|
+
}
|
24
|
+
|
25
|
+
const OverlayHideScrollBar = () => (
|
26
|
+
<>
|
27
|
+
<Overlay
|
28
|
+
color="card_light"
|
29
|
+
layout={{"x": "xl"}}
|
30
|
+
scrollBarNone
|
31
|
+
>
|
32
|
+
<InlineCardsExample />
|
33
|
+
</Overlay>
|
34
|
+
</>
|
35
|
+
)
|
36
|
+
|
37
|
+
export default OverlayHideScrollBar
|
@@ -0,0 +1 @@
|
|
1
|
+
Pass the `scroll_bar_none` prop to hide the scrollbar from view. This is particularly helpful for small containers where the scrollbar may occupy too much space.
|
@@ -0,0 +1 @@
|
|
1
|
+
Pass the `scrollBarNone` prop to hide the scrollbar from view. This is particularly helpful for small containers where the scrollbar may occupy too much space.
|
@@ -4,9 +4,11 @@ examples:
|
|
4
4
|
- overlay_multi_directional: Multi-directional
|
5
5
|
- overlay_vertical_dynamic_multi_directional: Vertical Dynamic Multi-directional
|
6
6
|
- overlay_toggle: Toggle
|
7
|
+
- overlay_hide_scroll_bar: Hide Scroll Bar
|
7
8
|
|
8
9
|
rails:
|
9
10
|
- overlay_default: Default
|
10
11
|
- overlay_multi_directional: Multi-directional
|
11
12
|
- overlay_vertical_dynamic_multi_directional: Vertical Dynamic Multi-directional
|
12
13
|
- overlay_toggle: Toggle
|
14
|
+
- overlay_hide_scroll_bar: Hide Scroll Bar
|
@@ -2,3 +2,4 @@ export { default as OverlayDefault } from './_overlay_default.jsx'
|
|
2
2
|
export { default as OverlayMultiDirectional } from './_overlay_multi_directional.jsx'
|
3
3
|
export { default as OverlayToggle } from './_overlay_toggle.jsx'
|
4
4
|
export { default as OverlayVerticalDynamicMultiDirectional } from './_overlay_vertical_dynamic_multi_directional.jsx'
|
5
|
+
export { default as OverlayHideScrollBar } from './_overlay_hide_scroll_bar.jsx'
|
@@ -10,9 +10,11 @@ module Playbook
|
|
10
10
|
default: { "bottom": "full" }
|
11
11
|
prop :dynamic, type: Playbook::Props::Boolean,
|
12
12
|
default: false
|
13
|
+
prop :scroll_bar_none, type: Playbook::Props::Boolean,
|
14
|
+
default: false
|
13
15
|
|
14
16
|
def classname
|
15
|
-
generate_classname("pb_overlay")
|
17
|
+
generate_classname("pb_overlay", hide_scroll_bar_class)
|
16
18
|
end
|
17
19
|
|
18
20
|
def position
|
@@ -114,6 +116,10 @@ module Playbook
|
|
114
116
|
data.merge!("data-overlay-dynamic" => true) if dynamic
|
115
117
|
data
|
116
118
|
end
|
119
|
+
|
120
|
+
def hide_scroll_bar_class
|
121
|
+
scroll_bar_none ? " overlay-hide-scrollbar" : ""
|
122
|
+
end
|
117
123
|
end
|
118
124
|
end
|
119
125
|
end
|
@@ -64,3 +64,15 @@ test('should render children', () => {
|
|
64
64
|
const kit = screen.getByTestId(testId)
|
65
65
|
expect(kit).toHaveTextContent(props.children)
|
66
66
|
})
|
67
|
+
|
68
|
+
test('should add overlay-hide-scrollbar class when scrollBarNone is true', () => {
|
69
|
+
const props = {
|
70
|
+
children,
|
71
|
+
data: { testid: testId },
|
72
|
+
scrollBarNone: true
|
73
|
+
}
|
74
|
+
|
75
|
+
render(<Overlay {...props} />)
|
76
|
+
const kit = screen.getByTestId(testId)
|
77
|
+
expect(kit).toHaveClass('overlay-hide-scrollbar')
|
78
|
+
})
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import React from 'react'
|
1
|
+
import React, { useState, useEffect} from 'react'
|
2
2
|
import Select from 'react-select'
|
3
3
|
import AsyncSelect from 'react-select/async'
|
4
4
|
import CreateableSelect from 'react-select/creatable'
|
@@ -45,8 +45,12 @@ type TypeaheadProps = {
|
|
45
45
|
getOptionLabel?: string | (() => string),
|
46
46
|
getOptionValue?: string | (() => string),
|
47
47
|
name?: string,
|
48
|
+
options?: Array<{ label: string; value?: string }>,
|
48
49
|
marginBottom?: "none" | "xxs" | "xs" | "sm" | "md" | "lg" | "xl",
|
49
50
|
pillColor?: "primary" | "neutral" | "success" | "warning" | "error" | "info" | "data_1" | "data_2" | "data_3" | "data_4" | "data_5" | "data_6" | "data_7" | "data_8" | "windows" | "siding" | "roofing" | "doors" | "gutters" | "solar" | "insulation" | "accessories",
|
51
|
+
optionsByContext?: Record<string, Array<{ label: string; value?: string }>>
|
52
|
+
searchContextSelector?: string,
|
53
|
+
clearOnContextChange?: boolean,
|
50
54
|
} & GlobalProps
|
51
55
|
|
52
56
|
export type SelectValueType = {
|
@@ -81,6 +85,9 @@ const Typeahead = ({
|
|
81
85
|
loadOptions = noop,
|
82
86
|
marginBottom = "sm",
|
83
87
|
pillColor,
|
88
|
+
optionsByContext = {},
|
89
|
+
searchContextSelector,
|
90
|
+
clearOnContextChange = false,
|
84
91
|
...props
|
85
92
|
}: TypeaheadProps) => {
|
86
93
|
const selectProps = {
|
@@ -115,6 +122,32 @@ const Typeahead = ({
|
|
115
122
|
...props,
|
116
123
|
}
|
117
124
|
|
125
|
+
const [contextValue, setContextValue] = useState("")
|
126
|
+
|
127
|
+
useEffect(() => {
|
128
|
+
if (searchContextSelector) {
|
129
|
+
const searchContextElement = document.getElementById(searchContextSelector)
|
130
|
+
|
131
|
+
setContextValue((searchContextElement as HTMLInputElement)?.value)
|
132
|
+
const handleContextChange = (e: Event) => {
|
133
|
+
const target = e.target as HTMLInputElement;
|
134
|
+
setContextValue(target.value);
|
135
|
+
if (clearOnContextChange) document.dispatchEvent(new CustomEvent(`pb-typeahead-kit-${selectProps.id}:clear`))
|
136
|
+
}
|
137
|
+
|
138
|
+
if (searchContextElement) searchContextElement.addEventListener('change', handleContextChange)
|
139
|
+
|
140
|
+
return () => {
|
141
|
+
if (searchContextElement) searchContextElement.removeEventListener('change', handleContextChange)
|
142
|
+
}
|
143
|
+
}
|
144
|
+
}, [searchContextSelector])
|
145
|
+
|
146
|
+
const contextArray = optionsByContext[contextValue]
|
147
|
+
if (Array.isArray(contextArray) && contextArray.length > 0) {
|
148
|
+
selectProps.options = contextArray
|
149
|
+
}
|
150
|
+
|
118
151
|
const Tag = (
|
119
152
|
createable
|
120
153
|
? (async ? AsyncCreateableSelect : CreateableSelect)
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<%= pb_rails("select", props: {
|
2
|
+
id:"color_context_2",
|
3
|
+
label: "Choose a Color",
|
4
|
+
name: "color_name",
|
5
|
+
options: [
|
6
|
+
{ value: "red", value_text: "Red" },
|
7
|
+
{ value: "blue", value_text: "Blue" },
|
8
|
+
{ value: "green", value_text: "Green" }
|
9
|
+
],
|
10
|
+
}) %>
|
11
|
+
|
12
|
+
<%= pb_rails("typeahead", props: {
|
13
|
+
label: "Pick a Shade",
|
14
|
+
is_multi: false,
|
15
|
+
search_context_selector: "color_context_2",
|
16
|
+
options_by_context: {
|
17
|
+
"red": [
|
18
|
+
{ label: "Scarlet", value: "scarlet" },
|
19
|
+
{ label: "Mahogany", value: "mahogany" },
|
20
|
+
{ label: "Crimson", value: "crimson" }
|
21
|
+
],
|
22
|
+
"blue": [
|
23
|
+
{ label: "Sky Blue", value: "sky" },
|
24
|
+
{ label: "Cerulean", value: "cerulean" },
|
25
|
+
{ label: "Navy", value: "navy" }
|
26
|
+
],
|
27
|
+
"green": [
|
28
|
+
{ label: "Emerald", value: "emerald" },
|
29
|
+
{ label: "Mint", value: "mint" },
|
30
|
+
{ label: "Olive", value: "olive" }
|
31
|
+
]
|
32
|
+
},
|
33
|
+
id: "typeahead-dynamic-options",
|
34
|
+
}) %>
|
35
|
+
|
36
|
+
|
37
|
+
<%= javascript_tag defer: "defer" do %>
|
38
|
+
document.addEventListener("pb-typeahead-kit-typeahead-dynamic-options-result-option-select", function(event) {
|
39
|
+
console.log('Single Option selected')
|
40
|
+
console.dir(event.detail)
|
41
|
+
})
|
42
|
+
document.addEventListener("pb-typeahead-kit-typeahead-dynamic-options-result-clear", function() {
|
43
|
+
console.log('All options cleared')
|
44
|
+
})
|
45
|
+
<% end %>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
You can also set up a typeahead to render options dynamically based on input from a select. To achieve this:
|
2
|
+
- The typeahead must have a unique `id`
|
3
|
+
- Use the `search_context_selector` prop on the typeahead. The value here must match the id of the select so the Typeahead knows where to read the current "context" from.
|
4
|
+
- Use `options_by_context` to pass in a hash whose keys match the possible values of your “context” select. Each key maps to an array of { label, value } objects. The typeahead automatically displays only the subset of options matching the current context.
|
5
|
+
- Additionally, the optional `clear_on_context_change` prop controls whether the typeahead clears or not when a change happens in the linked select. This prop is set to true by default so that whenever a selection is made in the select, the Typeahead automatically clears its current input/selection.
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<%= pb_rails("select", props: {
|
2
|
+
id:"color_context",
|
3
|
+
label: "Choose a Color",
|
4
|
+
name: "color_name_2",
|
5
|
+
options: [
|
6
|
+
{ value: "red", value_text: "Red" },
|
7
|
+
{ value: "blue", value_text: "Blue" },
|
8
|
+
{ value: "green", value_text: "Green" }
|
9
|
+
],
|
10
|
+
}) %>
|
11
|
+
|
12
|
+
<%= pb_rails("typeahead", props: {
|
13
|
+
label: "Pick a Shade",
|
14
|
+
search_context_selector: "color_context",
|
15
|
+
options_by_context: {
|
16
|
+
"red": [
|
17
|
+
{ label: "Scarlet", value: "scarlet" },
|
18
|
+
{ label: "Mahogany", value: "mahogany" },
|
19
|
+
{ label: "Crimson", value: "crimson" }
|
20
|
+
],
|
21
|
+
"blue": [
|
22
|
+
{ label: "Sky Blue", value: "sky" },
|
23
|
+
{ label: "Cerulean", value: "cerulean" },
|
24
|
+
{ label: "Navy", value: "navy" }
|
25
|
+
],
|
26
|
+
"green": [
|
27
|
+
{ label: "Emerald", value: "emerald" },
|
28
|
+
{ label: "Mint", value: "mint" },
|
29
|
+
{ label: "Olive", value: "olive" }
|
30
|
+
]
|
31
|
+
},
|
32
|
+
search_term_minimum_length: 0,
|
33
|
+
}) %>
|
@@ -0,0 +1,3 @@
|
|
1
|
+
The dynamic rendering of options for the typeahead can also be achieved with a pure Rails implementation (not react rendered). For this implementation, use all the props as above with the following additions:
|
2
|
+
|
3
|
+
- `search_term_minimum_length`: this sets the minimum input in the typeahead needed to display the dropdown. This is set to 3 by default. Set it to 0 for the dropdown to always display when the typeahead is interacted with.
|
@@ -12,6 +12,8 @@ examples:
|
|
12
12
|
- typeahead_margin_bottom: Margin Bottom
|
13
13
|
- typeahead_with_pills_color: With Pills (Custom Color)
|
14
14
|
- typeahead_truncated_text: Truncated Text
|
15
|
+
- typeahead_dynamic_options: Dynamic Options
|
16
|
+
- typeahead_dynamic_options_pure_rails: Dynamic Options (Pure Rails)
|
15
17
|
|
16
18
|
react:
|
17
19
|
- typeahead_default: Default
|
@@ -20,6 +20,34 @@ export default class PbTypeahead extends PbEnhancedElement {
|
|
20
20
|
this.searchInput.addEventListener('focus', () => this.debouncedSearch())
|
21
21
|
this.searchInput.addEventListener('input', () => this.debouncedSearch())
|
22
22
|
this.resultsElement.addEventListener('click', (event: MouseEvent) => this.optionSelected(event))
|
23
|
+
|
24
|
+
if (this.clearOnContextChange && this.searchContextElement) {
|
25
|
+
this.searchContextElement.addEventListener('change', () => {
|
26
|
+
this.searchInputClear()
|
27
|
+
this.resultsCacheClear()
|
28
|
+
this.clearResults()
|
29
|
+
})
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
get optionsByContext() {
|
34
|
+
return (this.element as HTMLElement).dataset.pbTypeaheadKitOptionsByContext
|
35
|
+
? JSON.parse((this.element as HTMLElement).dataset.pbTypeaheadKitOptionsByContext)
|
36
|
+
: null
|
37
|
+
}
|
38
|
+
|
39
|
+
get searchContextElement() {
|
40
|
+
const selector = (this.element as HTMLElement).dataset.pbTypeaheadKitSearchContextSelector
|
41
|
+
if (!selector) return null
|
42
|
+
|
43
|
+
const found = this.element.parentNode?.querySelector(`#${selector}`)
|
44
|
+
|| this.element.closest(selector)
|
45
|
+
|
46
|
+
return found || null
|
47
|
+
}
|
48
|
+
|
49
|
+
get clearOnContextChange() {
|
50
|
+
return (this.element as HTMLElement).dataset.pbTypeaheadKitClearOnContextChange === 'true'
|
23
51
|
}
|
24
52
|
|
25
53
|
handleKeydown(event: KeyboardEvent) {
|
@@ -40,14 +68,32 @@ export default class PbTypeahead extends PbEnhancedElement {
|
|
40
68
|
|
41
69
|
const searchTerm = this.searchTerm
|
42
70
|
const searchContext = this.searchContext
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
71
|
+
|
72
|
+
if (this.optionsByContext && Object.keys(this.optionsByContext).length > 0) {
|
73
|
+
const contextArray = this.optionsByContext[searchContext] || []
|
74
|
+
|
75
|
+
const filteredResults = contextArray.filter((obj: { label: string, value: string }) => {
|
76
|
+
return obj.label
|
77
|
+
&& obj.label.toLowerCase().includes(searchTerm.toLowerCase())
|
78
|
+
})
|
79
|
+
|
80
|
+
const optionFragments = filteredResults.map((obj: { label: string, value: string }) => {
|
81
|
+
const singleOption = document.createDocumentFragment()
|
82
|
+
singleOption.appendChild(document.createTextNode(obj.label))
|
83
|
+
return singleOption
|
84
|
+
})
|
85
|
+
|
86
|
+
this.resultsCacheUpdate(searchTerm, searchContext, optionFragments)
|
87
|
+
} else {
|
88
|
+
const search = {
|
89
|
+
searchingFor: searchTerm,
|
90
|
+
searchingContext: searchContext,
|
91
|
+
setResults: (results: Array<DocumentFragment>) => {
|
92
|
+
this.resultsCacheUpdate(searchTerm, searchContext, results)
|
93
|
+
},
|
94
|
+
}
|
95
|
+
this.element.dispatchEvent(new CustomEvent('pb-typeahead-kit-search', { bubbles: true, detail: search }))
|
49
96
|
}
|
50
|
-
this.element.dispatchEvent(new CustomEvent('pb-typeahead-kit-search', { bubbles: true, detail: search }))
|
51
97
|
}
|
52
98
|
|
53
99
|
resultsCacheUpdate(searchTerm: string, searchContext: string, results: Array<DocumentFragment>) {
|
@@ -87,11 +133,15 @@ export default class PbTypeahead extends PbEnhancedElement {
|
|
87
133
|
const resultOption = (event.target as Element).closest('[data-result-option-item]')
|
88
134
|
if (!resultOption) return
|
89
135
|
|
136
|
+
const selectedText = resultOption.textContent.trim()
|
137
|
+
|
90
138
|
this._validSelection = true
|
91
139
|
this.removeValidationError()
|
92
140
|
|
141
|
+
if (this.searchContextElement) this.searchInput.value = selectedText
|
142
|
+
|
93
143
|
this.resultsCacheClear()
|
94
|
-
this.searchInputClear()
|
144
|
+
if (!this.searchContextElement) this.searchInputClear()
|
95
145
|
this.clearResults()
|
96
146
|
|
97
147
|
this.element.dispatchEvent(new CustomEvent('pb-typeahead-kit-result-option-selected', { bubbles: true, detail: { selected: resultOption, typeahead: this } }))
|
@@ -173,6 +223,9 @@ export default class PbTypeahead extends PbEnhancedElement {
|
|
173
223
|
this.element.parentNode.querySelector(selector) ||
|
174
224
|
this.element.closest(selector)
|
175
225
|
) as HTMLInputElement).value
|
226
|
+
else if (this.searchContextElement) {
|
227
|
+
return (this.searchContextElement as HTMLInputElement).value
|
228
|
+
}
|
176
229
|
|
177
230
|
return null
|
178
231
|
}
|
@@ -44,6 +44,12 @@ module Playbook
|
|
44
44
|
default: false
|
45
45
|
prop :validation, type: Playbook::Props::HashProp,
|
46
46
|
default: {}
|
47
|
+
prop :clear_on_context_change, type: Playbook::Props::Boolean,
|
48
|
+
default: true
|
49
|
+
prop :options_by_context, type: Playbook::Props::HashProp,
|
50
|
+
default: {}
|
51
|
+
prop :search_context_selector, type: Playbook::Props::String,
|
52
|
+
default: nil
|
47
53
|
|
48
54
|
def classname
|
49
55
|
default_margin_bottom = margin_bottom.present? ? "" : " mb_sm"
|
@@ -58,7 +64,10 @@ module Playbook
|
|
58
64
|
Hash(values[:data]).merge(
|
59
65
|
pb_typeahead_kit: true,
|
60
66
|
pb_typeahead_kit_search_term_minimum_length: search_term_minimum_length,
|
61
|
-
pb_typeahead_kit_search_debounce_timeout: search_debounce_timeout
|
67
|
+
pb_typeahead_kit_search_debounce_timeout: search_debounce_timeout,
|
68
|
+
pb_typeahead_kit_clear_on_context_change: clear_on_context_change,
|
69
|
+
pb_typeahead_kit_search_context_selector: search_context_selector,
|
70
|
+
pb_typeahead_kit_options_by_context: options_by_context.to_json
|
62
71
|
)
|
63
72
|
end
|
64
73
|
|
@@ -85,6 +94,9 @@ module Playbook
|
|
85
94
|
placeholder: placeholder,
|
86
95
|
plusIcon: plus_icon,
|
87
96
|
truncate: truncate,
|
97
|
+
searchContextSelector: search_context_selector,
|
98
|
+
optionsByContext: options_by_context,
|
99
|
+
clearOnContextChange: clear_on_context_change,
|
88
100
|
}
|
89
101
|
|
90
102
|
base_options[:getOptionLabel] = get_option_label if get_option_label.present?
|