@cfpb/cfpb-design-system 4.2.4 → 4.3.1
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 +186 -1
- package/dist/components/cfpb-buttons/index.css +1 -1
- package/dist/components/cfpb-buttons/index.css.map +2 -2
- package/dist/components/cfpb-buttons/index.js +1 -1
- package/dist/components/cfpb-buttons/index.js.map +1 -1
- package/dist/components/cfpb-expandables/index.css +1 -1
- package/dist/components/cfpb-expandables/index.css.map +2 -2
- package/dist/components/cfpb-expandables/index.js +1 -1
- package/dist/components/cfpb-expandables/index.js.map +4 -4
- package/dist/components/cfpb-forms/index.css +1 -1
- package/dist/components/cfpb-forms/index.css.map +2 -2
- package/dist/components/cfpb-forms/index.js +1 -1
- package/dist/components/cfpb-forms/index.js.map +2 -2
- package/dist/components/cfpb-icons/index.css +1 -1
- package/dist/components/cfpb-icons/index.css.map +2 -2
- package/dist/components/cfpb-icons/index.js +1 -1
- package/dist/components/cfpb-icons/index.js.map +1 -1
- package/dist/components/cfpb-layout/index.css +1 -1
- package/dist/components/cfpb-layout/index.css.map +2 -2
- package/dist/components/cfpb-layout/index.js +1 -1
- package/dist/components/cfpb-layout/index.js.map +1 -1
- package/dist/components/cfpb-notifications/index.css +1 -1
- package/dist/components/cfpb-notifications/index.css.map +2 -2
- package/dist/components/cfpb-notifications/index.js +1 -1
- package/dist/components/cfpb-notifications/index.js.map +1 -1
- package/dist/components/cfpb-pagination/index.css +1 -1
- package/dist/components/cfpb-pagination/index.css.map +2 -2
- package/dist/components/cfpb-pagination/index.js +1 -1
- package/dist/components/cfpb-pagination/index.js.map +1 -1
- package/dist/components/cfpb-tables/index.css +1 -1
- package/dist/components/cfpb-tables/index.css.map +2 -2
- package/dist/components/cfpb-tables/index.js +1 -1
- package/dist/components/cfpb-tables/index.js.map +1 -1
- package/dist/components/cfpb-tooltips/index.css +1 -1
- package/dist/components/cfpb-tooltips/index.css.map +2 -2
- package/dist/components/cfpb-tooltips/index.js +1 -1
- package/dist/components/cfpb-tooltips/index.js.map +1 -1
- package/dist/components/cfpb-typography/index.css +1 -1
- package/dist/components/cfpb-typography/index.css.map +2 -2
- package/dist/components/cfpb-typography/index.js +1 -1
- package/dist/components/cfpb-typography/index.js.map +1 -1
- package/dist/elements/abstracts/index.js +2 -0
- package/dist/elements/abstracts/index.js.map +7 -0
- package/dist/elements/base/index.css +3 -0
- package/dist/elements/base/index.css.map +7 -0
- package/dist/elements/base/index.js +2 -0
- package/dist/elements/base/index.js.map +7 -0
- package/dist/elements/cfpb-button/index.js +4 -4
- package/dist/elements/cfpb-button/index.js.map +3 -3
- package/dist/elements/cfpb-checkbox-icon/index.js +29 -0
- package/dist/elements/{cfpb-checkbox → cfpb-checkbox-icon}/index.js.map +4 -4
- package/dist/elements/cfpb-expandable/index.css +2 -0
- package/dist/elements/cfpb-expandable/index.css.map +7 -0
- package/dist/elements/cfpb-expandable/index.js +33 -0
- package/dist/elements/cfpb-expandable/index.js.map +7 -0
- package/dist/elements/cfpb-file-upload/index.js +4 -4
- package/dist/elements/cfpb-file-upload/index.js.map +3 -3
- package/dist/elements/cfpb-form-alert/index.js +32 -0
- package/dist/elements/cfpb-form-alert/index.js.map +7 -0
- package/dist/elements/cfpb-form-choice/index.js +12 -3
- package/dist/elements/cfpb-form-choice/index.js.map +4 -4
- package/dist/elements/cfpb-form-search/index.js +41 -0
- package/dist/elements/cfpb-form-search/index.js.map +7 -0
- package/dist/elements/cfpb-form-search-input/index.js +41 -0
- package/dist/elements/cfpb-form-search-input/index.js.map +7 -0
- package/dist/elements/cfpb-icon-text/index.js +3 -3
- package/dist/elements/cfpb-icon-text/index.js.map +3 -3
- package/dist/elements/cfpb-label/index.js +3 -3
- package/dist/elements/cfpb-label/index.js.map +2 -2
- package/dist/elements/cfpb-list/index.js +39 -0
- package/dist/elements/cfpb-list/index.js.map +7 -0
- package/dist/elements/cfpb-list-item/index.js +39 -0
- package/dist/elements/cfpb-list-item/index.js.map +7 -0
- package/dist/elements/cfpb-multiselect/index.js +13 -4
- package/dist/elements/cfpb-multiselect/index.js.map +4 -4
- package/dist/elements/cfpb-pagination/index.js +3 -3
- package/dist/elements/cfpb-pagination/index.js.map +2 -2
- package/dist/elements/cfpb-select/index.css +2 -0
- package/dist/elements/cfpb-select/index.css.map +7 -0
- package/dist/elements/cfpb-select/index.js +42 -0
- package/dist/elements/cfpb-select/index.js.map +7 -0
- package/dist/elements/cfpb-select-list/index.js +39 -0
- package/dist/elements/cfpb-select-list/index.js.map +7 -0
- package/dist/elements/cfpb-tag-filter/index.js +3 -3
- package/dist/elements/cfpb-tag-filter/index.js.map +3 -3
- package/dist/elements/cfpb-tag-group/index.js +3 -3
- package/dist/elements/cfpb-tag-group/index.js.map +4 -4
- package/dist/elements/cfpb-tag-topic/index.js +4 -4
- package/dist/elements/cfpb-tag-topic/index.js.map +2 -2
- package/dist/elements/index.css +2 -0
- package/dist/elements/index.css.map +7 -0
- package/dist/elements/index.js +7 -6
- package/dist/elements/index.js.map +4 -4
- package/dist/index.css +1 -1
- package/dist/index.css.map +3 -3
- package/dist/index.js +7 -6
- package/dist/index.js.map +4 -4
- package/dist/utilities/index.css +1 -1
- package/dist/utilities/index.css.map +2 -2
- package/dist/utilities/index.js +1 -1
- package/dist/utilities/index.js.map +4 -4
- package/package.json +1 -1
- package/src/components/cfpb-buttons/button-group.scss +1 -1
- package/src/components/cfpb-buttons/button-link.scss +10 -54
- package/src/components/cfpb-buttons/button.scss +3 -3
- package/src/components/cfpb-buttons/vars.scss +1 -1
- package/src/components/cfpb-expandables/expandable-group.scss +1 -1
- package/src/components/cfpb-expandables/expandable.js +3 -0
- package/src/components/cfpb-expandables/expandable.scss +1 -1
- package/src/components/cfpb-expandables/summary.scss +1 -1
- package/src/components/cfpb-forms/form-alert.scss +1 -1
- package/src/components/cfpb-forms/form-field.scss +6 -6
- package/src/components/cfpb-forms/form.scss +1 -1
- package/src/components/cfpb-forms/label.scss +2 -2
- package/src/components/cfpb-forms/multiselect.js +1 -1
- package/src/components/cfpb-forms/multiselect.scss +1 -1
- package/src/components/cfpb-forms/range.scss +7 -7
- package/src/components/cfpb-forms/search-input.scss +1 -1
- package/src/components/cfpb-forms/select.scss +1 -1
- package/src/components/cfpb-forms/tag.scss +1 -1
- package/src/components/cfpb-forms/text-input.scss +1 -1
- package/src/components/cfpb-icons/icon.scss +1 -1
- package/src/components/cfpb-layout/card-group.scss +1 -1
- package/src/components/cfpb-layout/card.scss +1 -1
- package/src/components/cfpb-layout/email-signup.scss +1 -1
- package/src/components/cfpb-layout/featured-content-module.scss +1 -1
- package/src/components/cfpb-layout/hero.scss +1 -1
- package/src/components/cfpb-layout/layout.scss +9 -9
- package/src/components/cfpb-layout/well.scss +1 -1
- package/src/components/cfpb-notifications/banner.scss +1 -1
- package/src/components/cfpb-notifications/notification.scss +1 -1
- package/src/components/cfpb-pagination/pagination.scss +1 -1
- package/src/components/cfpb-tables/table.scss +1 -1
- package/src/components/cfpb-tooltips/tooltip.scss +1 -1
- package/src/components/cfpb-typography/date.scss +1 -1
- package/src/components/cfpb-typography/list.scss +1 -1
- package/src/components/cfpb-typography/meta-header.scss +1 -1
- package/src/components/cfpb-typography/mixins.scss +1 -1
- package/src/components/cfpb-typography/pull-quote.scss +1 -1
- package/src/components/cfpb-typography/slug-header.scss +1 -1
- package/src/components/cfpb-typography/tagline.scss +1 -1
- package/src/elements/abstracts/custom-props.css +123 -0
- package/src/{abstracts → elements/abstracts}/grid-mixins.scss +2 -1
- package/src/{abstracts → elements/abstracts}/heading-mixins.scss +1 -0
- package/src/{abstracts → elements/abstracts}/index.scss +1 -0
- package/src/{abstracts → elements/abstracts}/media-queries.scss +1 -1
- package/src/elements/abstracts/sizing-vars.scss +66 -0
- package/src/elements/abstracts/vars.css +79 -0
- package/src/{base → elements/base}/base.scss +14 -14
- package/src/elements/cfpb-button/cfpb-button-group.scss +12 -0
- package/src/elements/cfpb-button/cfpb-button-link.scss +103 -0
- package/src/elements/cfpb-button/cfpb-button.component.scss +11 -4
- package/src/elements/cfpb-button/cfpb-button.scss +218 -0
- package/src/elements/cfpb-button/index.js +44 -30
- package/src/elements/cfpb-button/vars.css +30 -0
- package/src/elements/cfpb-checkbox-icon/cfpb-checkbox-icon.component.scss +88 -0
- package/src/elements/cfpb-checkbox-icon/index.js +104 -0
- package/src/elements/cfpb-expandable/cfpb-expandable.component.scss +218 -0
- package/src/elements/cfpb-expandable/index.js +127 -0
- package/src/elements/cfpb-file-upload/cfpb-file-upload.component.scss +2 -2
- package/src/elements/cfpb-file-upload/index.js +25 -27
- package/src/elements/cfpb-form-alert/cfpb-form-alert.component.scss +36 -0
- package/src/elements/cfpb-form-alert/index.js +55 -0
- package/src/elements/cfpb-form-choice/cfpb-form-choice.component.scss +42 -81
- package/src/elements/cfpb-form-choice/index.js +58 -18
- package/src/elements/cfpb-form-search/cfpb-form-search.component.scss +54 -0
- package/src/elements/cfpb-form-search/index.js +194 -0
- package/src/elements/cfpb-form-search-input/cfpb-form-search-input.component.scss +217 -0
- package/src/elements/cfpb-form-search-input/index.js +140 -0
- package/src/elements/cfpb-icon-text/cfpb-icon-text.component.scss +33 -39
- package/src/elements/cfpb-icon-text/index.js +32 -104
- package/src/elements/cfpb-label/cfpb-label.component.scss +2 -2
- package/src/elements/cfpb-label/index.js +6 -9
- package/src/elements/cfpb-list/cfpb-list.component.scss +34 -0
- package/src/elements/cfpb-list/index.js +379 -0
- package/src/elements/cfpb-list/index.spec.js +214 -0
- package/src/elements/cfpb-list-item/cfpb-list-item.component.scss +69 -0
- package/src/elements/cfpb-list-item/index.js +215 -0
- package/src/elements/cfpb-pagination/cfpb-pagination.component.scss +2 -7
- package/src/elements/cfpb-pagination/index.js +6 -8
- package/src/elements/cfpb-select/cfpb-select.component.scss +241 -0
- package/src/elements/cfpb-select/index.js +371 -0
- package/src/elements/cfpb-select/multiple-select-event-proxy.js +88 -0
- package/src/elements/cfpb-select/single-select-event-proxy.js +47 -0
- package/src/elements/cfpb-tag-filter/cfpb-tag-filter.component.scss +6 -3
- package/src/elements/cfpb-tag-filter/index.js +15 -7
- package/src/elements/cfpb-tag-group/cfpb-tag-group.component.scss +2 -2
- package/src/elements/cfpb-tag-group/index.js +53 -6
- package/src/elements/cfpb-tag-topic/cfpb-tag-topic.component.scss +2 -2
- package/src/elements/cfpb-tag-topic/index.js +5 -7
- package/src/elements/cfpb-utilities/parse-child-data.js +50 -0
- package/src/elements/cfpb-utilities/parse-child-data.spec.js +56 -0
- package/src/elements/cfpb-utilities/search-service.js +46 -0
- package/src/elements/cfpb-utilities/search-service.spec.js +138 -0
- package/src/elements/cfpb-utilities/transition/transition.scss +98 -0
- package/src/elements/index.js +7 -1
- package/src/index.js +2 -2
- package/src/index.scss +14 -2
- package/src/tokens/abstracts/custom-props.json +1642 -0
- package/src/tokens/abstracts/vars.json +1319 -0
- package/src/tokens/cfpb-button/vars.json +436 -0
- package/src/utilities/breakpoint-state.js +1 -1
- package/src/utilities/transition/max-height-transition.js +74 -0
- package/src/utilities/utilities.scss +1 -1
- package/dist/elements/cfpb-checkbox/index.js +0 -29
- package/src/abstracts/custom-props.scss +0 -175
- package/src/abstracts/vars.scss +0 -184
- package/src/elements/cfpb-multiselect/cfpb-multiselect.component.scss +0 -225
- package/src/elements/cfpb-multiselect/index.js +0 -444
- package/src/elements/cfpb-multiselect/multiselect-model.js +0 -288
- package/src/elements/cfpb-multiselect/multiselect-model.spec.js +0 -236
- /package/src/{abstracts → elements/abstracts}/index.js +0 -0
- /package/src/{abstracts → elements/abstracts}/vars-breakpoints.js +0 -0
- /package/src/{abstracts → elements/abstracts}/vars-breakpoints.scss +0 -0
- /package/src/{base → elements/base}/font.scss +0 -0
- /package/src/{base → elements/base}/index.js +0 -0
- /package/src/{base → elements/base}/index.scss +0 -0
- /package/src/{base → elements/base}/normalize.scss +0 -0
|
@@ -1,444 +0,0 @@
|
|
|
1
|
-
import { html, LitElement, css, unsafeCSS } from 'lit';
|
|
2
|
-
import styles from './cfpb-multiselect.component.scss';
|
|
3
|
-
import { MultiselectModel } from './multiselect-model.js';
|
|
4
|
-
import { CfpbFormChoice } from '../cfpb-form-choice';
|
|
5
|
-
import { CfpbLabel } from '../cfpb-label';
|
|
6
|
-
|
|
7
|
-
// Constants for direction.
|
|
8
|
-
const DIR_PREV = 'prev';
|
|
9
|
-
const DIR_NEXT = 'next';
|
|
10
|
-
|
|
11
|
-
// Constants for key binding.
|
|
12
|
-
const KEY_RETURN = 'Enter';
|
|
13
|
-
const KEY_ESCAPE = 'Escape';
|
|
14
|
-
const KEY_UP = 'ArrowUp';
|
|
15
|
-
const KEY_DOWN = 'ArrowDown';
|
|
16
|
-
const KEY_TAB = 'Tab';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @element cfpb-multiselect.
|
|
21
|
-
* @slot - The main content for the upload button.
|
|
22
|
-
*/
|
|
23
|
-
export class CfpbMultiselect extends LitElement {
|
|
24
|
-
static styles = css`
|
|
25
|
-
${unsafeCSS(styles)}
|
|
26
|
-
`;
|
|
27
|
-
|
|
28
|
-
static get properties() {
|
|
29
|
-
return {
|
|
30
|
-
// Other properties.
|
|
31
|
-
name: { type: String },
|
|
32
|
-
options: { type: Array, state: true },
|
|
33
|
-
selectedLabel: { type: String, state: true },
|
|
34
|
-
label: { type: String, attribute: true },
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// DOM references.
|
|
39
|
-
#containerDom;
|
|
40
|
-
#fieldsetDom;
|
|
41
|
-
#searchDom;
|
|
42
|
-
#optionsDom;
|
|
43
|
-
#optionItemDoms;
|
|
44
|
-
|
|
45
|
-
#model;
|
|
46
|
-
#isBlurSkipped;
|
|
47
|
-
|
|
48
|
-
constructor() {
|
|
49
|
-
super();
|
|
50
|
-
this.options = [];
|
|
51
|
-
this.selectedLabel = '';
|
|
52
|
-
this.#isBlurSkipped = false;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
firstUpdated() {
|
|
56
|
-
// Set DOM references.
|
|
57
|
-
const root = this.renderRoot;
|
|
58
|
-
this.#containerDom = root.querySelector('.o-multiselect');
|
|
59
|
-
this.#fieldsetDom = root.querySelector('fieldset');
|
|
60
|
-
this.#searchDom = root.querySelector('input');
|
|
61
|
-
this.#optionsDom = root.querySelector('ul');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
#slotChanged() {
|
|
65
|
-
this.#initializeFromLightDom();
|
|
66
|
-
|
|
67
|
-
this.#model = new MultiselectModel(this.options, this.name, {}).init();
|
|
68
|
-
|
|
69
|
-
// Wait for lit to finish its render cycle so we can query the list items.
|
|
70
|
-
this.updateComplete.then(() => {
|
|
71
|
-
this.#optionItemDoms = Array.from(this.renderRoot.querySelectorAll('li'));
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
#initializeFromLightDom() {
|
|
76
|
-
const fallbackSelect = this.querySelector('select');
|
|
77
|
-
if (fallbackSelect) {
|
|
78
|
-
this.name = fallbackSelect.name;
|
|
79
|
-
|
|
80
|
-
// Read options.
|
|
81
|
-
let index = 0;
|
|
82
|
-
this.options = Array.from(fallbackSelect.options).map((opt) => ({
|
|
83
|
-
value: opt.value,
|
|
84
|
-
label: opt.label,
|
|
85
|
-
text: opt.text,
|
|
86
|
-
checked: opt.selected,
|
|
87
|
-
index: index++,
|
|
88
|
-
}));
|
|
89
|
-
|
|
90
|
-
this.selectedLabel = fallbackSelect.selectedOptions[0]?.label || '';
|
|
91
|
-
|
|
92
|
-
// Remove or hide the fallback <select>
|
|
93
|
-
fallbackSelect.style.display = 'none';
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Set the filtered matched state.
|
|
99
|
-
*/
|
|
100
|
-
#filterMatches() {
|
|
101
|
-
this.#optionsDom.classList.remove('u-no-results');
|
|
102
|
-
this.#optionsDom.classList.add('u-filtered');
|
|
103
|
-
|
|
104
|
-
let filteredIndices = this.#model.lastFilterIndicesList;
|
|
105
|
-
for (let i = 0, len = filteredIndices.length; i < len; i++) {
|
|
106
|
-
this.#optionItemDoms[filteredIndices[i]].classList.remove(
|
|
107
|
-
'u-filter-match',
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
filteredIndices = this.#model.filterIndicesList;
|
|
112
|
-
for (let j = 0, len = filteredIndices.length; j < len; j++) {
|
|
113
|
-
this.#optionItemDoms[filteredIndices[j]].classList.add('u-filter-match');
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Resets the filtered option list.
|
|
119
|
-
*/
|
|
120
|
-
#resetFilter() {
|
|
121
|
-
this.#optionsDom.classList.remove('u-filtered', 'u-no-results');
|
|
122
|
-
|
|
123
|
-
for (let i = 0, len = this.#optionsDom.children.length; i < len; i++) {
|
|
124
|
-
this.#optionsDom.children[i].classList.remove('u-filter-match');
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
this.#model.clearFilter();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Updates the list of options to show the user there
|
|
132
|
-
* are no matching results.
|
|
133
|
-
*/
|
|
134
|
-
#filterNoMatches() {
|
|
135
|
-
this.#optionsDom.classList.add('u-no-results');
|
|
136
|
-
this.#optionsDom.classList.remove('u-filtered');
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Filter the options list.
|
|
141
|
-
* Every time we filter we have two lists of indices:
|
|
142
|
-
* - The matching options (filterIndices).
|
|
143
|
-
* - The matching options of the last filter (_lastFilterIndices).
|
|
144
|
-
* We need to turn off the filter for any of the last filter matches
|
|
145
|
-
* that are not in the new set, and turn on the filter for the matches
|
|
146
|
-
* that are not in the last set.
|
|
147
|
-
* @param {Array} filterIndices - List of indices to filter from the options.
|
|
148
|
-
* @returns {boolean} True if options are filtered, false otherwise.
|
|
149
|
-
*/
|
|
150
|
-
#filterList(filterIndices) {
|
|
151
|
-
if (filterIndices.length > 0) {
|
|
152
|
-
this.#filterMatches();
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
this.#filterNoMatches();
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Evaluates the list of options based on the user's query in the
|
|
162
|
-
* search input.
|
|
163
|
-
* @param {string} value - Text the user has entered in the search query.
|
|
164
|
-
*/
|
|
165
|
-
#evaluate(value) {
|
|
166
|
-
this.#resetFilter();
|
|
167
|
-
this.#model.resetIndex();
|
|
168
|
-
const matchedIndices = this.#model.filterIndices(value);
|
|
169
|
-
this.#filterList(matchedIndices);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Expand the multiselect drop down.
|
|
174
|
-
*/
|
|
175
|
-
expand() {
|
|
176
|
-
this.#containerDom.classList.add('u-active');
|
|
177
|
-
this.#fieldsetDom.classList.remove('u-invisible');
|
|
178
|
-
this.#fieldsetDom.setAttribute('aria-hidden', false);
|
|
179
|
-
|
|
180
|
-
const event = new Event('expandbegin', { bubbles: true, composed: true });
|
|
181
|
-
this.dispatchEvent(event);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Collapse the multiselect drop down.
|
|
186
|
-
*/
|
|
187
|
-
collapse() {
|
|
188
|
-
this.#containerDom.classList.remove('u-active');
|
|
189
|
-
this.#fieldsetDom.classList.add('u-invisible');
|
|
190
|
-
this.#fieldsetDom.setAttribute('aria-hidden', true);
|
|
191
|
-
this.#model.resetIndex();
|
|
192
|
-
|
|
193
|
-
const event = new Event('collapsebegin', { bubbles: true, composed: true });
|
|
194
|
-
this.dispatchEvent(event);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Highlights an option in the list.
|
|
199
|
-
* @param {string} direction
|
|
200
|
-
* Direction to highlight compared to the current focus.
|
|
201
|
-
*/
|
|
202
|
-
#highlight(direction) {
|
|
203
|
-
if (direction === DIR_NEXT) {
|
|
204
|
-
this.#model.index = this.#model.index + 1;
|
|
205
|
-
} else if (direction === DIR_PREV) {
|
|
206
|
-
this.#model.index = this.#model.index - 1;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const index = this.#model.index;
|
|
210
|
-
if (index > -1) {
|
|
211
|
-
let filteredIndex = index;
|
|
212
|
-
const filterIndices = this.#model.filterIndicesList;
|
|
213
|
-
if (filterIndices.length > 0) {
|
|
214
|
-
filteredIndex = filterIndices[index];
|
|
215
|
-
}
|
|
216
|
-
const option = this.#model.getOption(filteredIndex);
|
|
217
|
-
const value = option.value;
|
|
218
|
-
const item = this.#optionsDom.querySelector(
|
|
219
|
-
'[data-option="' + value + '"]',
|
|
220
|
-
);
|
|
221
|
-
this.#isBlurSkipped = true;
|
|
222
|
-
item.focus();
|
|
223
|
-
} else {
|
|
224
|
-
this.#isBlurSkipped = false;
|
|
225
|
-
this.#searchDom.focus();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Resets the search input and filtering.
|
|
231
|
-
*/
|
|
232
|
-
#resetSearch() {
|
|
233
|
-
this.#searchDom.value = '';
|
|
234
|
-
this.#resetFilter();
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Tracks a user's selections and updates the list in the dom.
|
|
239
|
-
* @param {number} optionIndex - The index position of the chosen option.
|
|
240
|
-
*/
|
|
241
|
-
#updateSelections(optionIndex) {
|
|
242
|
-
const option =
|
|
243
|
-
this.#model.getOption(optionIndex) ||
|
|
244
|
-
this.#model.getOption(this.#model.index);
|
|
245
|
-
|
|
246
|
-
if (option) {
|
|
247
|
-
if (option.checked) {
|
|
248
|
-
if (this.#optionsDom.classList.contains('u-max-selections')) {
|
|
249
|
-
this.#optionsDom.classList.remove('u-max-selections');
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (this.#model.isAtMaxSelections() && !option.checked) return;
|
|
255
|
-
|
|
256
|
-
if (this.#optionsDom.classList.contains('u-max-selections')) {
|
|
257
|
-
this.#optionsDom.classList.remove('u-max-selections');
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
this.#model.toggleOption(optionIndex);
|
|
261
|
-
|
|
262
|
-
this.#model.resetIndex();
|
|
263
|
-
this.#isBlurSkipped = false;
|
|
264
|
-
|
|
265
|
-
if (this.#fieldsetDom.getAttribute('aria-hidden') === 'false') {
|
|
266
|
-
this.#searchDom.focus();
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// Spread is used to create a new array reference,
|
|
270
|
-
// which triggers a lit lifecycle update.
|
|
271
|
-
this.options = [...this.#model.options];
|
|
272
|
-
|
|
273
|
-
if (this.#model.isAtMaxSelections()) {
|
|
274
|
-
this.#optionsDom.classList.add('u-max-selections');
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
#searchInputFocus() {
|
|
279
|
-
if (this.#fieldsetDom.getAttribute('aria-hidden') === 'true') {
|
|
280
|
-
this.expand();
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
#searchInputBlur() {
|
|
285
|
-
if (
|
|
286
|
-
!this.#isBlurSkipped &&
|
|
287
|
-
this.#fieldsetDom.getAttribute('aria-hidden') === 'false'
|
|
288
|
-
) {
|
|
289
|
-
this.collapse();
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
#searchInputKeyDown(event) {
|
|
294
|
-
const key = event.key;
|
|
295
|
-
if (
|
|
296
|
-
this.#fieldsetDom.getAttribute('aria-hidden') === 'true' &&
|
|
297
|
-
key !== KEY_TAB
|
|
298
|
-
) {
|
|
299
|
-
this.expand();
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (key === KEY_RETURN) {
|
|
303
|
-
event.preventDefault();
|
|
304
|
-
this.#highlight(DIR_NEXT);
|
|
305
|
-
} else if (key === KEY_ESCAPE) {
|
|
306
|
-
this.#resetSearch();
|
|
307
|
-
this.collapse();
|
|
308
|
-
} else if (key === KEY_DOWN) {
|
|
309
|
-
this.#highlight(DIR_NEXT);
|
|
310
|
-
} else if (
|
|
311
|
-
key === KEY_TAB &&
|
|
312
|
-
!event.shiftKey &&
|
|
313
|
-
this.#fieldsetDom.getAttribute('aria-hidden') === 'false'
|
|
314
|
-
) {
|
|
315
|
-
this.collapse();
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Handles checkbox change event.
|
|
321
|
-
* @param {number} index - The index position of the checkbox within the list.
|
|
322
|
-
*/
|
|
323
|
-
#onChangeCheckbox(index) {
|
|
324
|
-
//opt.checked = !opt.checked;
|
|
325
|
-
this.#resetSearch();
|
|
326
|
-
this.#updateSelections(index);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* @param {MouseEvent} event - The key down event.
|
|
331
|
-
*/
|
|
332
|
-
#onKeyDownList(event) {
|
|
333
|
-
const key = event.key;
|
|
334
|
-
const target = event.target;
|
|
335
|
-
const checked = target.checked;
|
|
336
|
-
|
|
337
|
-
if (key === KEY_RETURN) {
|
|
338
|
-
event.preventDefault();
|
|
339
|
-
|
|
340
|
-
/* Programmatically checking a checkbox does not fire a change event
|
|
341
|
-
so we need to manually create an event and dispatch it from the input.
|
|
342
|
-
*/
|
|
343
|
-
target.checked = !checked;
|
|
344
|
-
//const evt = new Event('change', { bubbles: false, cancelable: true });
|
|
345
|
-
//target.dispatchEvent(evt);
|
|
346
|
-
} else if (key === KEY_ESCAPE) {
|
|
347
|
-
this.#searchDom.focus();
|
|
348
|
-
this.collapse();
|
|
349
|
-
} else if (key === KEY_UP) {
|
|
350
|
-
this.#highlight(DIR_PREV);
|
|
351
|
-
} else if (key === KEY_DOWN) {
|
|
352
|
-
this.#highlight(DIR_NEXT);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
render() {
|
|
357
|
-
// Track the index position of the option in the list.
|
|
358
|
-
let index = 0;
|
|
359
|
-
|
|
360
|
-
const renderTags = [];
|
|
361
|
-
const renderChoices = [];
|
|
362
|
-
|
|
363
|
-
this.options.map((item) => {
|
|
364
|
-
renderTags.push(html`${this.#renderTag(item)}`);
|
|
365
|
-
renderChoices.push(html`${this.#renderChoice(item, index++)}`);
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
const label = this.label || 'Select options';
|
|
369
|
-
|
|
370
|
-
return html`
|
|
371
|
-
<!-- Fallback content like <select> and <options>s -->
|
|
372
|
-
<slot @slotchange=${this.#slotChanged}></slot>
|
|
373
|
-
|
|
374
|
-
<cfpb-label for="search-input">
|
|
375
|
-
<div slot="label">${label}</div>
|
|
376
|
-
</cfpb-label>
|
|
377
|
-
<div class="o-multiselect">
|
|
378
|
-
<cfpb-tag-group
|
|
379
|
-
@tag-click=${(evt) => {
|
|
380
|
-
this.#updateSelections(
|
|
381
|
-
Number(evt.detail.target.getAttribute('data-index')),
|
|
382
|
-
);
|
|
383
|
-
}}
|
|
384
|
-
>
|
|
385
|
-
${renderTags}
|
|
386
|
-
</cfpb-tag-group>
|
|
387
|
-
<header>
|
|
388
|
-
<input
|
|
389
|
-
id="search-input"
|
|
390
|
-
type="text"
|
|
391
|
-
autocomplete="off"
|
|
392
|
-
aria-label="${label}"
|
|
393
|
-
value=${this.selectedLabel || ''}
|
|
394
|
-
@input=${(event) => this.#evaluate(event.target.value)}
|
|
395
|
-
@focus=${this.#searchInputFocus}
|
|
396
|
-
@blur=${this.#searchInputBlur}
|
|
397
|
-
@keydown=${this.#searchInputKeyDown}
|
|
398
|
-
/>
|
|
399
|
-
</header>
|
|
400
|
-
|
|
401
|
-
<fieldset class="u-invisible" aria-hidden="true">
|
|
402
|
-
<ul role="listbox" @keydown=${this.#onKeyDownList}>
|
|
403
|
-
${renderChoices}
|
|
404
|
-
</ul>
|
|
405
|
-
</fieldset>
|
|
406
|
-
</div>
|
|
407
|
-
`;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
#renderTag(item) {
|
|
411
|
-
let htmlSnippet = html``;
|
|
412
|
-
if (item.checked === true) {
|
|
413
|
-
htmlSnippet = html`<cfpb-tag-filter data-index="${item.index}"
|
|
414
|
-
>${item.value}</cfpb-tag-filter
|
|
415
|
-
>`;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
return htmlSnippet;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
#renderChoice(opt, index) {
|
|
422
|
-
return html`
|
|
423
|
-
<li role="option">
|
|
424
|
-
<cfpb-form-choice
|
|
425
|
-
data-option="${opt.label}"
|
|
426
|
-
inlist="true"
|
|
427
|
-
.checked="${opt.checked}"
|
|
428
|
-
@change=${() => this.#onChangeCheckbox(index)}
|
|
429
|
-
@mousedown=${() => (this.#isBlurSkipped = true)}
|
|
430
|
-
>
|
|
431
|
-
${opt.label}
|
|
432
|
-
</cfpb-form-choice>
|
|
433
|
-
</li>
|
|
434
|
-
`;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
static init() {
|
|
438
|
-
CfpbFormChoice.init();
|
|
439
|
-
CfpbLabel.init();
|
|
440
|
-
|
|
441
|
-
window.customElements.get('cfpb-multiselect') ||
|
|
442
|
-
window.customElements.define('cfpb-multiselect', CfpbMultiselect);
|
|
443
|
-
}
|
|
444
|
-
}
|