playbook_ui 16.2.0.pre.alpha.advancedtablecascadingcollapsereact14676 → 16.2.0.pre.alpha.faiconbuttonfix14520
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_advanced_table/Components/CustomCell.tsx +4 -17
- data/app/pb_kits/playbook/pb_advanced_table/Components/TableHeaderCell.tsx +1 -3
- data/app/pb_kits/playbook/pb_advanced_table/Hooks/useTableActions.ts +9 -21
- data/app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx +1 -25
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.tsx +1 -5
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.test.jsx +1 -74
- data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +0 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/index.js +1 -2
- data/app/pb_kits/playbook/pb_collapsible/index.js +4 -16
- data/app/pb_kits/playbook/pb_date_picker/_date_picker.tsx +1 -4
- data/app/pb_kits/playbook/pb_date_picker/date_picker.html.erb +2 -2
- data/app/pb_kits/playbook/pb_dialog/index.js +5 -45
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +0 -2
- data/app/pb_kits/playbook/pb_dropdown/dropdown.html.erb +2 -2
- data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +1 -1
- data/app/pb_kits/playbook/pb_dropdown/index.js +13 -68
- data/app/pb_kits/playbook/pb_dropdown/keyboard_accessibility.js +3 -19
- data/app/pb_kits/playbook/pb_enhanced_element/element_observer.ts +1 -1
- data/app/pb_kits/playbook/pb_enhanced_element/index.ts +1 -2
- data/app/pb_kits/playbook/pb_icon/icon.rb +19 -168
- data/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.tsx +0 -2
- data/app/pb_kits/playbook/pb_multi_level_select/docs/example.yml +0 -1
- data/app/pb_kits/playbook/pb_multi_level_select/docs/index.js +0 -1
- data/app/pb_kits/playbook/pb_pagination/_pagination.scss +1 -101
- data/app/pb_kits/playbook/pb_pagination/_pagination.test.jsx +1 -172
- data/app/pb_kits/playbook/pb_pagination/_pagination.tsx +15 -178
- data/app/pb_kits/playbook/pb_pagination/docs/_pagination_default.jsx +1 -1
- data/app/pb_kits/playbook/pb_passphrase/_passphrase.tsx +0 -4
- data/app/pb_kits/playbook/pb_rich_text_editor/_rich_text_editor.tsx +0 -2
- data/app/pb_kits/playbook/pb_select/_select.tsx +0 -2
- data/app/pb_kits/playbook/pb_select/select.html.erb +2 -2
- data/app/pb_kits/playbook/pb_star_rating/star_rating.html.erb +1 -1
- data/app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_interactive.tsx +0 -1
- data/app/pb_kits/playbook/pb_text_input/_text_input.tsx +0 -2
- data/app/pb_kits/playbook/pb_text_input/text_input.html.erb +2 -2
- data/app/pb_kits/playbook/pb_textarea/_textarea.tsx +21 -43
- data/app/pb_kits/playbook/pb_textarea/docs/example.yml +0 -1
- data/app/pb_kits/playbook/pb_textarea/docs/index.js +8 -9
- data/app/pb_kits/playbook/pb_textarea/textarea.html.erb +4 -4
- data/app/pb_kits/playbook/pb_textarea/textarea.rb +2 -6
- data/app/pb_kits/playbook/pb_textarea/textarea.test.js +1 -134
- data/app/pb_kits/playbook/pb_time_picker/_time_picker.tsx +0 -6
- data/app/pb_kits/playbook/pb_time_picker/time_picker.test.jsx +2 -2
- data/app/pb_kits/playbook/pb_tooltip/index.js +15 -60
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.test.jsx +1 -1
- data/dist/chunks/{_pb_line_graph-BGY7jEks.js → _pb_line_graph-BSLb5VXP.js} +1 -1
- data/dist/chunks/{_typeahead-QhswHQnq.js → _typeahead-DXIBDeMj.js} +1 -1
- data/dist/chunks/{globalProps-CK2YuA9O.js → globalProps-DyTB8IdV.js} +1 -1
- data/dist/chunks/{lib-DspaUdlc.js → lib-9wz3x5jl.js} +1 -1
- data/dist/chunks/vendor.js +5 -5
- data/dist/menu.yml +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/forms/builder/checkbox_field.rb +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +6 -12
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_cascade_collapse.jsx +0 -50
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_cascade_collapse.md +0 -1
- data/app/pb_kits/playbook/pb_kit_registry/index.ts +0 -180
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_react_reset_key.jsx +0 -100
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_react_reset_key.md +0 -1
- data/app/pb_kits/playbook/pb_textarea/docs/_textarea_input_options.jsx +0 -68
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3ab15b5936d85e9fe352d2293813967937694dc61e985fafb0ec9d21d6df752d
|
|
4
|
+
data.tar.gz: 6bab9ca4069487ba52e762667f86f663a2a27c3c300c537a073996c9016cea49
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 14144c41830ccabcc9cb3a7572e6197cd970ca4300b28aa2d4285ff06bae722b261f8613e50b38424caa67d801a9928a00abff1acb3bf2ebeef7355f9bf14f8a
|
|
7
|
+
data.tar.gz: d6d1f2dc9c37b53d0211b5bccbd0cd2af1594c9cdf2b20eb907814ec40be28edcfc677bb0a2c27ecbb36d728c06aff220529a52d42d1b60152d60e9ab4400281
|
|
@@ -11,7 +11,6 @@ import Icon from "../../pb_icon/_icon"
|
|
|
11
11
|
import Checkbox from "../../pb_checkbox/_checkbox"
|
|
12
12
|
|
|
13
13
|
import AdvancedTableContext from "../Context/AdvancedTableContext"
|
|
14
|
-
import { getDescendantRowIds } from "../Utilities/ExpansionControlHelpers"
|
|
15
14
|
|
|
16
15
|
interface CustomCellProps {
|
|
17
16
|
getValue?: Getter<string>
|
|
@@ -32,25 +31,13 @@ export const CustomCell = ({
|
|
|
32
31
|
selectableRows,
|
|
33
32
|
customStyle = {},
|
|
34
33
|
}: CustomCellProps & GlobalProps) => {
|
|
35
|
-
const { setExpanded, expanded, expandedControl, inlineRowLoading, hasAnySubRows
|
|
34
|
+
const { setExpanded, expanded, expandedControl, inlineRowLoading, hasAnySubRows } = useContext(AdvancedTableContext);
|
|
36
35
|
|
|
37
36
|
const handleOnExpand = (row: Row<GenericObject>) => {
|
|
38
37
|
onRowToggleClick && onRowToggleClick(row);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (!expandedControl) {
|
|
43
|
-
setExpanded({ ...expanded, [row.id]: true });
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
if (cascadeCollapse) {
|
|
47
|
-
const idsToRemove = new Set([row.id, ...getDescendantRowIds(row)]);
|
|
48
|
-
const nextExpanded = { ...expanded };
|
|
49
|
-
idsToRemove.forEach((id) => delete nextExpanded[id]);
|
|
50
|
-
setExpanded(nextExpanded);
|
|
51
|
-
} else if (!expandedControl) {
|
|
52
|
-
setExpanded({ ...expanded, [row.id]: false });
|
|
53
|
-
}
|
|
38
|
+
|
|
39
|
+
if (!expandedControl) {
|
|
40
|
+
setExpanded({ ...expanded, [row.id]: !row.getIsExpanded() });
|
|
54
41
|
}
|
|
55
42
|
};
|
|
56
43
|
|
|
@@ -63,7 +63,6 @@ export const TableHeaderCell = ({
|
|
|
63
63
|
stickyLeftColumn,
|
|
64
64
|
inlineRowLoading,
|
|
65
65
|
isActionBarVisible,
|
|
66
|
-
cascadeCollapse,
|
|
67
66
|
} = useContext(AdvancedTableContext);
|
|
68
67
|
|
|
69
68
|
type justifyTypes = "none" | "center" | "start" | "end" | "between" | "around" | "evenly"
|
|
@@ -183,8 +182,7 @@ const isToggleExpansionEnabled =
|
|
|
183
182
|
table.getRowModel(),
|
|
184
183
|
expanded,
|
|
185
184
|
undefined,
|
|
186
|
-
depth
|
|
187
|
-
cascadeCollapse
|
|
185
|
+
depth
|
|
188
186
|
)
|
|
189
187
|
setExpanded(updated)
|
|
190
188
|
}
|
|
@@ -12,7 +12,6 @@ interface UseTableActionsProps {
|
|
|
12
12
|
inlineRowLoading?: boolean;
|
|
13
13
|
localPagination?: { pageIndex: number; pageSize: number };
|
|
14
14
|
setLocalPagination?: (pagination: { pageIndex: number; pageSize: number }) => void;
|
|
15
|
-
cascadeCollapse?: boolean;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
export function useTableActions({
|
|
@@ -23,8 +22,7 @@ export function useTableActions({
|
|
|
23
22
|
onRowSelectionChange,
|
|
24
23
|
inlineRowLoading = false,
|
|
25
24
|
localPagination,
|
|
26
|
-
setLocalPagination
|
|
27
|
-
cascadeCollapse = false
|
|
25
|
+
setLocalPagination
|
|
28
26
|
}: UseTableActionsProps) {
|
|
29
27
|
|
|
30
28
|
// State to achieve 1 second delay before fetching more rows
|
|
@@ -34,25 +32,15 @@ export function useTableActions({
|
|
|
34
32
|
// Handle expand/collapse
|
|
35
33
|
const handleExpandOrCollapse = useCallback(async (row: Row<GenericObject>) => {
|
|
36
34
|
if (onToggleExpansionClick) onToggleExpansionClick(row)
|
|
35
|
+
const updatedExpandedState = await updateExpandAndCollapseState(
|
|
36
|
+
table.getRowModel(),
|
|
37
|
+
expanded,
|
|
38
|
+
row?.parentId,
|
|
39
|
+
undefined
|
|
40
|
+
)
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (cascadeCollapse && isHeaderCollapseAll) {
|
|
42
|
-
setExpanded({})
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const updatedExpandedState = await updateExpandAndCollapseState(
|
|
47
|
-
table.getRowModel(),
|
|
48
|
-
expanded,
|
|
49
|
-
row?.parentId,
|
|
50
|
-
undefined,
|
|
51
|
-
cascadeCollapse
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
setExpanded(updatedExpandedState)
|
|
55
|
-
}, [expanded, setExpanded, onToggleExpansionClick, table, cascadeCollapse]);
|
|
42
|
+
setExpanded(updatedExpandedState)
|
|
43
|
+
}, [expanded, setExpanded, onToggleExpansionClick, table]);
|
|
56
44
|
|
|
57
45
|
// Handle pagination
|
|
58
46
|
const onPageChange = useCallback((page: number) => {
|
|
@@ -11,21 +11,11 @@ const filterExpandableRows = (expandedState: Record<string, boolean>) => {
|
|
|
11
11
|
return expandedState
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export const getDescendantRowIds = (row: Row<GenericObject>): string[] => {
|
|
15
|
-
const ids: string[] = []
|
|
16
|
-
for (const sub of row.subRows || []) {
|
|
17
|
-
ids.push(sub.id)
|
|
18
|
-
ids.push(...getDescendantRowIds(sub))
|
|
19
|
-
}
|
|
20
|
-
return ids
|
|
21
|
-
}
|
|
22
|
-
|
|
23
14
|
export const updateExpandAndCollapseState = (
|
|
24
15
|
tableRows: RowModel<GenericObject>,
|
|
25
16
|
expanded: Record<string, boolean>,
|
|
26
17
|
targetParent?: string,
|
|
27
18
|
targetDepth?: number,
|
|
28
|
-
cascadeCollapse?: boolean,
|
|
29
19
|
) => {
|
|
30
20
|
const updateExpandedRows: Record<string, boolean> = {};
|
|
31
21
|
const rows = targetDepth !== undefined ? tableRows.flatRows : tableRows.rows;
|
|
@@ -61,22 +51,8 @@ export const updateExpandAndCollapseState = (
|
|
|
61
51
|
}
|
|
62
52
|
}
|
|
63
53
|
|
|
64
|
-
|
|
54
|
+
return filterExpandableRows({
|
|
65
55
|
...(expanded as ExpandedStateObject),
|
|
66
56
|
...updateExpandedRows,
|
|
67
57
|
});
|
|
68
|
-
|
|
69
|
-
if (cascadeCollapse && !isExpandAction) {
|
|
70
|
-
const idsToRemove = new Set<string>();
|
|
71
|
-
for (const row of rowsToToggle) {
|
|
72
|
-
const shouldUpdate =
|
|
73
|
-
targetDepth === undefined ? true : row.depth === targetDepth;
|
|
74
|
-
if (shouldUpdate) {
|
|
75
|
-
getDescendantRowIds(row).forEach((id) => idsToRemove.add(id));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
idsToRemove.forEach((id) => delete updatedExpandedState[id]);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return updatedExpandedState;
|
|
82
58
|
};
|
|
@@ -31,7 +31,6 @@ type FullscreenControls = {
|
|
|
31
31
|
type AdvancedTableProps = {
|
|
32
32
|
aria?: { [key: string]: string }
|
|
33
33
|
actions?: React.ReactNode[] | React.ReactNode
|
|
34
|
-
cascadeCollapse?: boolean
|
|
35
34
|
children?: React.ReactNode | React.ReactNode[]
|
|
36
35
|
className?: string
|
|
37
36
|
columnDefinitions: GenericObject[]
|
|
@@ -81,7 +80,6 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
|
81
80
|
const {
|
|
82
81
|
aria = {},
|
|
83
82
|
actions,
|
|
84
|
-
cascadeCollapse = false,
|
|
85
83
|
children,
|
|
86
84
|
className,
|
|
87
85
|
columnDefinitions,
|
|
@@ -175,8 +173,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
|
175
173
|
onRowSelectionChange,
|
|
176
174
|
inlineRowLoading,
|
|
177
175
|
localPagination,
|
|
178
|
-
setLocalPagination
|
|
179
|
-
cascadeCollapse
|
|
176
|
+
setLocalPagination
|
|
180
177
|
});
|
|
181
178
|
|
|
182
179
|
// Set table row count for loading state
|
|
@@ -342,7 +339,6 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
|
342
339
|
>
|
|
343
340
|
{renderFullscreenHeader()}
|
|
344
341
|
<AdvancedTableProvider
|
|
345
|
-
cascadeCollapse={cascadeCollapse}
|
|
346
342
|
columnDefinitions={columnDefinitions}
|
|
347
343
|
columnGroupBorderColor={columnGroupBorderColor}
|
|
348
344
|
columnVisibilityControl={columnVisibilityControl}
|
|
@@ -1015,77 +1015,4 @@ test("columnStyling.headerFontColor works as excpected", () => {
|
|
|
1015
1015
|
|
|
1016
1016
|
const firstEnrollmentHeader = screen.getAllByText("New Enrollments")[0].closest("th");
|
|
1017
1017
|
expect(firstEnrollmentHeader).toHaveStyle({ color: colors.white });
|
|
1018
|
-
});
|
|
1019
|
-
|
|
1020
|
-
test("cascadeCollapse=false (default) preserves existing behavior when parent is re-expanded", () => {
|
|
1021
|
-
render(
|
|
1022
|
-
<AdvancedTable
|
|
1023
|
-
columnDefinitions={columnDefinitions}
|
|
1024
|
-
data={{ testid: testId }}
|
|
1025
|
-
tableData={MOCK_DATA}
|
|
1026
|
-
/>
|
|
1027
|
-
)
|
|
1028
|
-
|
|
1029
|
-
const kit = screen.getByTestId(testId)
|
|
1030
|
-
const getParentExpandButton = () => kit.querySelector("tbody tr .gray-icon.expand-toggle-icon")
|
|
1031
|
-
const parentButton = getParentExpandButton()
|
|
1032
|
-
expect(parentButton).toBeInTheDocument()
|
|
1033
|
-
parentButton.click()
|
|
1034
|
-
let subRow = kit.querySelector(".pb-bg-row-white.depth-sub-row-1")
|
|
1035
|
-
expect(subRow).toBeInTheDocument()
|
|
1036
|
-
getParentExpandButton().click()
|
|
1037
|
-
subRow = kit.querySelector(".pb-bg-row-white.depth-sub-row-1")
|
|
1038
|
-
expect(subRow).not.toBeInTheDocument()
|
|
1039
|
-
getParentExpandButton().click()
|
|
1040
|
-
subRow = kit.querySelector(".pb-bg-row-white.depth-sub-row-1")
|
|
1041
|
-
expect(subRow).toBeInTheDocument()
|
|
1042
|
-
})
|
|
1043
|
-
|
|
1044
|
-
test("cascadeCollapse=true collapses all descendants when parent is collapsed", () => {
|
|
1045
|
-
render(
|
|
1046
|
-
<AdvancedTable
|
|
1047
|
-
cascadeCollapse
|
|
1048
|
-
columnDefinitions={columnDefinitions}
|
|
1049
|
-
data={{ testid: testId }}
|
|
1050
|
-
tableData={MOCK_DATA}
|
|
1051
|
-
/>
|
|
1052
|
-
)
|
|
1053
|
-
|
|
1054
|
-
const kit = screen.getByTestId(testId)
|
|
1055
|
-
const getParentExpandButton = () => kit.querySelector("tbody tr .gray-icon.expand-toggle-icon")
|
|
1056
|
-
const parentButton = getParentExpandButton()
|
|
1057
|
-
expect(parentButton).toBeInTheDocument()
|
|
1058
|
-
parentButton.click()
|
|
1059
|
-
expect(kit.querySelector(".depth-sub-row-1")).toBeInTheDocument()
|
|
1060
|
-
getParentExpandButton().click()
|
|
1061
|
-
expect(kit.querySelector(".depth-sub-row-1")).not.toBeInTheDocument()
|
|
1062
|
-
getParentExpandButton().click()
|
|
1063
|
-
expect(kit.querySelector(".depth-sub-row-1")).toBeInTheDocument()
|
|
1064
|
-
})
|
|
1065
|
-
|
|
1066
|
-
test("cascadeCollapse=true with header toggle all: collapse all then expand all shows only direct children", async () => {
|
|
1067
|
-
render(
|
|
1068
|
-
<AdvancedTable
|
|
1069
|
-
cascadeCollapse
|
|
1070
|
-
columnDefinitions={columnDefinitions}
|
|
1071
|
-
data={{ testid: testId }}
|
|
1072
|
-
tableData={MOCK_DATA}
|
|
1073
|
-
/>
|
|
1074
|
-
)
|
|
1075
|
-
|
|
1076
|
-
const kit = screen.getByTestId(testId)
|
|
1077
|
-
const toggleAllButton = kit.querySelector(".gray-icon.toggle-all-icon")
|
|
1078
|
-
expect(toggleAllButton).toBeInTheDocument()
|
|
1079
|
-
toggleAllButton.click()
|
|
1080
|
-
await waitFor(() => {
|
|
1081
|
-
expect(kit.querySelector(".depth-sub-row-1")).toBeInTheDocument()
|
|
1082
|
-
})
|
|
1083
|
-
toggleAllButton.click()
|
|
1084
|
-
await waitFor(() => {
|
|
1085
|
-
expect(kit.querySelector(".depth-sub-row-1")).not.toBeInTheDocument()
|
|
1086
|
-
})
|
|
1087
|
-
toggleAllButton.click()
|
|
1088
|
-
await waitFor(() => {
|
|
1089
|
-
expect(kit.querySelector(".depth-sub-row-1")).toBeInTheDocument()
|
|
1090
|
-
})
|
|
1091
|
-
})
|
|
1018
|
+
});
|
|
@@ -42,7 +42,6 @@ examples:
|
|
|
42
42
|
- advanced_table_expanded_control: Expanded Control
|
|
43
43
|
- advanced_table_expand_by_depth: Expand by Depth
|
|
44
44
|
- advanced_table_subrow_headers: SubRow Headers
|
|
45
|
-
- advanced_table_cascade_collapse: Cascade Collapse
|
|
46
45
|
- advanced_table_collapsible_trail: Collapsible Trail
|
|
47
46
|
- advanced_table_table_options: Table Options
|
|
48
47
|
- advanced_table_table_props: Table Props
|
|
@@ -48,5 +48,4 @@ export { default as AdvancedTablePaddingControl } from './_advanced_table_paddin
|
|
|
48
48
|
export { default as AdvancedTablePaddingControlPerRow } from './_advanced_table_padding_control_per_row.jsx'
|
|
49
49
|
export { default as AdvancedTableColumnStylingBackground } from './_advanced_table_column_styling_background.jsx'
|
|
50
50
|
export { default as AdvancedTableColumnStylingBackgroundMulti } from './_advanced_table_column_styling_background_multi.jsx'
|
|
51
|
-
export { default as AdvancedTableColumnStylingBackgroundCustom } from './_advanced_table_column_styling_background_custom.jsx'
|
|
52
|
-
export { default as AdvancedTableCascadeCollapse } from './_advanced_table_cascade_collapse.jsx'
|
|
51
|
+
export { default as AdvancedTableColumnStylingBackgroundCustom } from './_advanced_table_column_styling_background_custom.jsx'
|
|
@@ -11,11 +11,9 @@ export default class PbCollapsible extends PbEnhancedElement {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
connect() {
|
|
14
|
-
this.
|
|
14
|
+
this.element.addEventListener('click', () => {
|
|
15
15
|
this.toggleElement(this.target)
|
|
16
|
-
}
|
|
17
|
-
this.element.addEventListener('click', this.clickHandler)
|
|
18
|
-
|
|
16
|
+
})
|
|
19
17
|
// Check the initial state of the collapsible content and set the arrow accordingly
|
|
20
18
|
if (this.target.classList.contains('is-visible')) {
|
|
21
19
|
this.displayUpArrow()
|
|
@@ -23,19 +21,9 @@ export default class PbCollapsible extends PbEnhancedElement {
|
|
|
23
21
|
this.displayDownArrow()
|
|
24
22
|
}
|
|
25
23
|
// Listen for a custom event to toggle the collapsible
|
|
26
|
-
this.
|
|
24
|
+
document.addEventListener(`${this.target.id}`, () => {
|
|
27
25
|
this.toggleElement(this.target)
|
|
28
|
-
}
|
|
29
|
-
document.addEventListener(`${this.target.id}`, this.customEventHandler)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
disconnect() {
|
|
33
|
-
if (this.clickHandler) {
|
|
34
|
-
this.element.removeEventListener('click', this.clickHandler)
|
|
35
|
-
}
|
|
36
|
-
if (this.customEventHandler && this.target) {
|
|
37
|
-
document.removeEventListener(`${this.target.id}`, this.customEventHandler)
|
|
38
|
-
}
|
|
26
|
+
})
|
|
39
27
|
}
|
|
40
28
|
|
|
41
29
|
get target() {
|
|
@@ -221,14 +221,11 @@ const DatePicker = (props: DatePickerProps): React.ReactElement => {
|
|
|
221
221
|
{!hideLabel && (
|
|
222
222
|
<label htmlFor={pickerId}>
|
|
223
223
|
{requiredIndicator ? (
|
|
224
|
-
<Caption className="pb_date_picker_kit_label"
|
|
225
|
-
color="lighter"
|
|
226
|
-
>
|
|
224
|
+
<Caption className="pb_date_picker_kit_label">
|
|
227
225
|
{label} <span style={{ color: `${colors.error}` }}>*</span>
|
|
228
226
|
</Caption>
|
|
229
227
|
) : (
|
|
230
228
|
<Caption className="pb_date_picker_kit_label"
|
|
231
|
-
color="lighter"
|
|
232
229
|
text={label}
|
|
233
230
|
/>
|
|
234
231
|
)}
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
<% if !object.hide_label && object.label %>
|
|
8
8
|
<label for="<%= object.picker_id %>">
|
|
9
9
|
<% if object.required_indicator %>
|
|
10
|
-
<%= pb_rails("caption", props: { dark: object.dark, classname: "pb_date_picker_kit_label"
|
|
10
|
+
<%= pb_rails("caption", props: { dark: object.dark, classname: "pb_date_picker_kit_label" }) do %>
|
|
11
11
|
<%= object.label %><span style="color: #DA0014;"> *</span>
|
|
12
12
|
<% end %>
|
|
13
13
|
<% else %>
|
|
14
|
-
<%= pb_rails("caption", props: { text: object.label, dark: object.dark, classname: "pb_date_picker_kit_label"
|
|
14
|
+
<%= pb_rails("caption", props: { text: object.label, dark: object.dark, classname: "pb_date_picker_kit_label" }) %>
|
|
15
15
|
<% end %>
|
|
16
16
|
</label>
|
|
17
17
|
<% end %>
|
|
@@ -8,16 +8,8 @@ export default class PbDialog extends PbEnhancedElement {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
connect() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.dialogId = this.dialogElement?.id
|
|
14
|
-
this.managedTriggers = new Set()
|
|
15
|
-
|
|
16
|
-
this.domContentLoadedHandler = () => this.setupDialog()
|
|
17
|
-
this.turboFrameLoadHandler = () => this.setupDialog()
|
|
18
|
-
|
|
19
|
-
window.addEventListener("DOMContentLoaded", this.domContentLoadedHandler)
|
|
20
|
-
window.addEventListener("turbo:frame-load", this.turboFrameLoadHandler)
|
|
11
|
+
window.addEventListener("DOMContentLoaded", () => this.setupDialog())
|
|
12
|
+
window.addEventListener("turbo:frame-load", () => this.setupDialog())
|
|
21
13
|
|
|
22
14
|
// Code for custom_event_type setup (can take multiple events in a string separated by commas)
|
|
23
15
|
const customEventTypeString = this.element.dataset.customEventType
|
|
@@ -32,38 +24,11 @@ export default class PbDialog extends PbEnhancedElement {
|
|
|
32
24
|
}
|
|
33
25
|
|
|
34
26
|
disconnect() {
|
|
35
|
-
// Clean up window event listeners
|
|
36
|
-
if (this.domContentLoadedHandler) {
|
|
37
|
-
window.removeEventListener("DOMContentLoaded", this.domContentLoadedHandler)
|
|
38
|
-
}
|
|
39
|
-
if (this.turboFrameLoadHandler) {
|
|
40
|
-
window.removeEventListener("turbo:frame-load", this.turboFrameLoadHandler)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Clean up custom event listeners
|
|
44
27
|
if (this.customEventTypes && Array.isArray(this.customEventTypes)) {
|
|
45
28
|
this.customEventTypes.forEach(eventType => {
|
|
46
29
|
window.removeEventListener(eventType, this.handleCustomEvent)
|
|
47
30
|
})
|
|
48
31
|
}
|
|
49
|
-
|
|
50
|
-
// Clean up only the triggers that this instance managed
|
|
51
|
-
this.managedTriggers.forEach((trigger) => {
|
|
52
|
-
if (trigger._openDialogClickHandler) {
|
|
53
|
-
trigger.removeEventListener("click", trigger._openDialogClickHandler)
|
|
54
|
-
delete trigger._openDialogClickHandler
|
|
55
|
-
}
|
|
56
|
-
if (trigger._closeDialogClickHandler) {
|
|
57
|
-
trigger.removeEventListener("click", trigger._closeDialogClickHandler)
|
|
58
|
-
delete trigger._closeDialogClickHandler
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
// Clean up this dialog's outside click handler
|
|
63
|
-
if (this.dialogElement && this.dialogElement._outsideClickHandler) {
|
|
64
|
-
this.dialogElement.removeEventListener("mousedown", this.dialogElement._outsideClickHandler)
|
|
65
|
-
delete this.dialogElement._outsideClickHandler
|
|
66
|
-
}
|
|
67
32
|
}
|
|
68
33
|
|
|
69
34
|
handleCustomEvent = (event) => {
|
|
@@ -123,12 +88,9 @@ export default class PbDialog extends PbEnhancedElement {
|
|
|
123
88
|
}
|
|
124
89
|
|
|
125
90
|
setupDialog() {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const openTrigger = document.querySelectorAll(`[data-open-dialog="${this.dialogId}"]`);
|
|
130
|
-
const closeTrigger = document.querySelectorAll(`[data-close-dialog="${this.dialogId}"]`);
|
|
131
|
-
const dialogs = this.dialogElement ? [this.dialogElement] : []
|
|
91
|
+
const openTrigger = document.querySelectorAll("[data-open-dialog]");
|
|
92
|
+
const closeTrigger = document.querySelectorAll("[data-close-dialog]");
|
|
93
|
+
const dialogs = document.querySelectorAll(".pb_dialog_rails")
|
|
132
94
|
|
|
133
95
|
const loadingButton = document.querySelector('[data-disable-with="Loading"]');
|
|
134
96
|
if (loadingButton && !loadingButton.dataset.listenerAttached) {
|
|
@@ -164,7 +126,6 @@ export default class PbDialog extends PbEnhancedElement {
|
|
|
164
126
|
};
|
|
165
127
|
|
|
166
128
|
open.addEventListener("click", open._openDialogClickHandler)
|
|
167
|
-
this.managedTriggers.add(open)
|
|
168
129
|
});
|
|
169
130
|
|
|
170
131
|
closeTrigger.forEach((close) => {
|
|
@@ -178,7 +139,6 @@ export default class PbDialog extends PbEnhancedElement {
|
|
|
178
139
|
};
|
|
179
140
|
|
|
180
141
|
close.addEventListener("click", close._closeDialogClickHandler)
|
|
181
|
-
this.managedTriggers.add(close)
|
|
182
142
|
});
|
|
183
143
|
|
|
184
144
|
// Close dialog box on outside click
|
|
@@ -479,7 +479,6 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
|
479
479
|
{requiredIndicator ? (
|
|
480
480
|
<Caption
|
|
481
481
|
className="pb_dropdown_kit_label"
|
|
482
|
-
color="lighter"
|
|
483
482
|
dark={dark}
|
|
484
483
|
marginBottom="xs"
|
|
485
484
|
>
|
|
@@ -488,7 +487,6 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
|
488
487
|
) : (
|
|
489
488
|
<Caption
|
|
490
489
|
className="pb_dropdown_kit_label"
|
|
491
|
-
color="lighter"
|
|
492
490
|
dark={dark}
|
|
493
491
|
marginBottom="xs"
|
|
494
492
|
text={label}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
<% if object.label.present? %>
|
|
3
3
|
<label for="<%= object.select_id %>" data-dropdown="pb-dropdown-label">
|
|
4
4
|
<% if object.required_indicator %>
|
|
5
|
-
<%= pb_rails("caption", props: { margin_bottom: "xs", classname: "pb_dropdown_kit_label",
|
|
5
|
+
<%= pb_rails("caption", props: { margin_bottom: "xs", classname: "pb_dropdown_kit_label", dark: object.dark }) do %>
|
|
6
6
|
<%= object.label %><span style="color: #DA0014;"> *</span>
|
|
7
7
|
<% end %>
|
|
8
8
|
<% else %>
|
|
9
|
-
<%= pb_rails("caption", props: { text: object.label, margin_bottom: "xs", classname: "pb_dropdown_kit_label",
|
|
9
|
+
<%= pb_rails("caption", props: { text: object.label, margin_bottom: "xs", classname: "pb_dropdown_kit_label", dark: object.dark }) %>
|
|
10
10
|
<% end %>
|
|
11
11
|
</label>
|
|
12
12
|
<% end %>
|
|
@@ -212,7 +212,7 @@ test('generated label prop', () => {
|
|
|
212
212
|
)
|
|
213
213
|
|
|
214
214
|
const kit = screen.getByTestId(testId)
|
|
215
|
-
const label = kit.querySelector('.
|
|
215
|
+
const label = kit.querySelector('.pb_caption_kit_md')
|
|
216
216
|
expect(label).toHaveTextContent('Countries')
|
|
217
217
|
})
|
|
218
218
|
|
|
@@ -54,66 +54,14 @@ export default class PbDropdown extends PbEnhancedElement {
|
|
|
54
54
|
this.isClearable = this.element.dataset.pbDropdownClearable !== "false";
|
|
55
55
|
if (this.clearBtn) {
|
|
56
56
|
this.clearBtn.style.display = "none";
|
|
57
|
-
this.
|
|
57
|
+
this.clearBtn.addEventListener("click", (e) => {
|
|
58
58
|
e.stopPropagation();
|
|
59
59
|
this.clearSelection();
|
|
60
|
-
}
|
|
61
|
-
this.clearBtn.addEventListener("click", this.clearBtnHandler);
|
|
60
|
+
});
|
|
62
61
|
}
|
|
63
62
|
this.updateClearButton();
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
disconnect() {
|
|
67
|
-
// Clean up stored instance reference
|
|
68
|
-
if (this.element._pbDropdownInstance === this) {
|
|
69
|
-
delete this.element._pbDropdownInstance
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Clean up keyboard handler
|
|
73
|
-
if (this.keyboardHandler && typeof this.keyboardHandler.disconnect === 'function') {
|
|
74
|
-
this.keyboardHandler.disconnect()
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Clean up custom trigger click listener
|
|
78
|
-
if (this.customTriggerClickHandler) {
|
|
79
|
-
const customTrigger = this.element.querySelector(CUSTOM_DISPLAY_SELECTOR) || this.element
|
|
80
|
-
customTrigger.removeEventListener('click', this.customTriggerClickHandler)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Clean up target click listener
|
|
84
|
-
if (this.handleOptionClickBound) {
|
|
85
|
-
this.target.removeEventListener('click', this.handleOptionClickBound)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Clean up document click listener
|
|
89
|
-
if (this.handleDocumentClickBound) {
|
|
90
|
-
document.removeEventListener('click', this.handleDocumentClickBound, true)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Clean up search bar listener
|
|
94
|
-
if (this.searchBar && this.searchBarHandler) {
|
|
95
|
-
this.searchBar.removeEventListener('input', this.searchBarHandler)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Clean up search input listeners
|
|
99
|
-
if (this.searchInput) {
|
|
100
|
-
if (this.searchInputFocusHandler) {
|
|
101
|
-
const trigger = this.element.querySelector(TRIGGER_SELECTOR)
|
|
102
|
-
if (trigger) {
|
|
103
|
-
trigger.removeEventListener('click', this.searchInputFocusHandler)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (this.searchInputHandler) {
|
|
107
|
-
this.searchInput.removeEventListener('input', this.searchInputHandler)
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Clean up clear button listener
|
|
112
|
-
if (this.clearBtn && this.clearBtnHandler) {
|
|
113
|
-
this.clearBtn.removeEventListener('click', this.clearBtnHandler)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
65
|
updateClearButton() {
|
|
118
66
|
if (!this.clearBtn) return;
|
|
119
67
|
if (!this.isClearable) {
|
|
@@ -130,7 +78,7 @@ export default class PbDropdown extends PbEnhancedElement {
|
|
|
130
78
|
bindEventListeners() {
|
|
131
79
|
const customTrigger =
|
|
132
80
|
this.element.querySelector(CUSTOM_DISPLAY_SELECTOR) || this.element;
|
|
133
|
-
|
|
81
|
+
customTrigger.addEventListener("click", (e) => {
|
|
134
82
|
const label = e.target.closest(LABEL_SELECTOR);
|
|
135
83
|
if (label && label.htmlFor) {
|
|
136
84
|
const trigger = this.element.querySelector(
|
|
@@ -141,16 +89,12 @@ export default class PbDropdown extends PbEnhancedElement {
|
|
|
141
89
|
}
|
|
142
90
|
}
|
|
143
91
|
this.toggleElement(this.target);
|
|
144
|
-
}
|
|
145
|
-
customTrigger.addEventListener("click", this.customTriggerClickHandler);
|
|
92
|
+
});
|
|
146
93
|
|
|
147
|
-
this.
|
|
148
|
-
this.target.addEventListener("click", this.handleOptionClickBound);
|
|
149
|
-
|
|
150
|
-
this.handleDocumentClickBound = this.handleDocumentClick.bind(this)
|
|
94
|
+
this.target.addEventListener("click", this.handleOptionClick.bind(this));
|
|
151
95
|
document.addEventListener(
|
|
152
96
|
"click",
|
|
153
|
-
this.
|
|
97
|
+
this.handleDocumentClick.bind(this),
|
|
154
98
|
true,
|
|
155
99
|
);
|
|
156
100
|
}
|
|
@@ -159,8 +103,9 @@ export default class PbDropdown extends PbEnhancedElement {
|
|
|
159
103
|
this.searchBar = this.element.querySelector(SEARCH_BAR_SELECTOR);
|
|
160
104
|
if (!this.searchBar) return;
|
|
161
105
|
|
|
162
|
-
this.
|
|
163
|
-
|
|
106
|
+
this.searchBar.addEventListener("input", (e) =>
|
|
107
|
+
this.handleSearch(e.target.value),
|
|
108
|
+
);
|
|
164
109
|
}
|
|
165
110
|
|
|
166
111
|
bindSearchInput() {
|
|
@@ -168,14 +113,14 @@ export default class PbDropdown extends PbEnhancedElement {
|
|
|
168
113
|
if (!this.searchInput) return;
|
|
169
114
|
|
|
170
115
|
// Focus the input when anyone clicks the wrapper
|
|
171
|
-
this.searchInputFocusHandler = () => this.searchInput.focus()
|
|
172
116
|
this.element
|
|
173
117
|
.querySelector(TRIGGER_SELECTOR)
|
|
174
|
-
?.addEventListener(
|
|
118
|
+
?.addEventListener("click", () => this.searchInput.focus());
|
|
175
119
|
|
|
176
120
|
// Live filter
|
|
177
|
-
this.
|
|
178
|
-
|
|
121
|
+
this.searchInput.addEventListener("input", (e) =>
|
|
122
|
+
this.handleSearch(e.target.value),
|
|
123
|
+
);
|
|
179
124
|
}
|
|
180
125
|
|
|
181
126
|
adjustDropdownHeight() {
|
|
@@ -12,35 +12,19 @@ export class PbDropdownKeyboard {
|
|
|
12
12
|
this.searchInput = this.dropdownElement.querySelector(
|
|
13
13
|
SEARCH_INPUT_SELECTOR
|
|
14
14
|
);
|
|
15
|
-
// Store bound handlers for cleanup
|
|
16
|
-
this.handleKeyDownBound = this.handleKeyDown.bind(this);
|
|
17
|
-
this.handleSearchInputBound = () => this.openDropdownIfClosed();
|
|
18
15
|
this.init();
|
|
19
16
|
}
|
|
20
17
|
|
|
21
18
|
init() {
|
|
22
19
|
this.dropdownElement.addEventListener(
|
|
23
20
|
"keydown",
|
|
24
|
-
this.
|
|
21
|
+
this.handleKeyDown.bind(this)
|
|
25
22
|
);
|
|
26
23
|
if (this.searchInput) {
|
|
27
|
-
this.searchInput.addEventListener("input",
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
disconnect() {
|
|
32
|
-
// Remove keydown listener
|
|
33
|
-
if (this.dropdownElement && this.handleKeyDownBound) {
|
|
34
|
-
this.dropdownElement.removeEventListener(
|
|
35
|
-
"keydown",
|
|
36
|
-
this.handleKeyDownBound
|
|
24
|
+
this.searchInput.addEventListener("input", () =>
|
|
25
|
+
this.openDropdownIfClosed()
|
|
37
26
|
);
|
|
38
27
|
}
|
|
39
|
-
|
|
40
|
-
// Remove search input listener
|
|
41
|
-
if (this.searchInput && this.handleSearchInputBound) {
|
|
42
|
-
this.searchInput.removeEventListener("input", this.handleSearchInputBound);
|
|
43
|
-
}
|
|
44
28
|
}
|
|
45
29
|
|
|
46
30
|
getVisibleOptions() {
|