@cfpb/cfpb-design-system 3.3.1 → 3.4.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 +22 -1
- package/dist/components/cfpb-expandables/index.js.map +1 -1
- package/dist/components/cfpb-forms/index.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/utilities/index.js +1 -1
- package/dist/utilities/index.js.map +3 -3
- package/package.json +1 -1
- package/src/utilities/atomic-helpers.spec.js +2 -2
- package/src/utilities/behavior/behavior.js +4 -13
- package/src/utilities/behavior/behavior.spec.js +36 -0
- package/src/utilities/index.js +5 -1
package/package.json
CHANGED
|
@@ -57,7 +57,7 @@ describe('atomic-helpers', () => {
|
|
|
57
57
|
'Check that element is a DOM node with ' +
|
|
58
58
|
`class ".${testClass}"`;
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
60
|
+
* Mock error function.
|
|
61
61
|
*/
|
|
62
62
|
function errFunc() {
|
|
63
63
|
checkDom(null, testClass);
|
|
@@ -68,7 +68,7 @@ describe('atomic-helpers', () => {
|
|
|
68
68
|
it('should throw an error if element class not found', () => {
|
|
69
69
|
const errMsg = 'mock-class not found on or in passed DOM node.';
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
71
|
+
* Mock error function.
|
|
72
72
|
*/
|
|
73
73
|
function errFunc() {
|
|
74
74
|
checkDom(componentDom, 'mock-class');
|
|
@@ -45,7 +45,7 @@ function _findElements(behaviorSelector, baseElement) {
|
|
|
45
45
|
behaviorElements.length === 0 &&
|
|
46
46
|
behaviorSelector.indexOf(BEHAVIOR_PREFIX) === -1
|
|
47
47
|
) {
|
|
48
|
-
behaviorElements =
|
|
48
|
+
behaviorElements = behaviorFind(behaviorSelector, baseElement);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
return behaviorElements;
|
|
@@ -60,7 +60,7 @@ function _findElements(behaviorSelector, baseElement) {
|
|
|
60
60
|
* for the behavior element.
|
|
61
61
|
* @returns {Array|NodeList} if it exists in the dom, null otherwise.
|
|
62
62
|
*/
|
|
63
|
-
function
|
|
63
|
+
function behaviorAttach(behaviorElement, event, eventHandler, baseElement) {
|
|
64
64
|
let behaviorElements = [];
|
|
65
65
|
|
|
66
66
|
if (behaviorElement instanceof NodeList === true) {
|
|
@@ -118,21 +118,12 @@ function checkBehaviorDom(element, behaviorDataAttr) {
|
|
|
118
118
|
* for the behavior element.
|
|
119
119
|
* @returns {NodeList} if it exists in the dom, null otherwise.
|
|
120
120
|
*/
|
|
121
|
-
function
|
|
121
|
+
function behaviorFind(behaviorSelector, baseElement) {
|
|
122
122
|
behaviorSelector = JS_HOOK + '*=' + BEHAVIOR_PREFIX + behaviorSelector;
|
|
123
123
|
behaviorSelector = '[' + behaviorSelector + ']';
|
|
124
124
|
|
|
125
125
|
return _findElements(behaviorSelector, baseElement);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
/**
|
|
129
|
-
* @param {HTMLElement} behaviorElement - Element in which to remove the event.
|
|
130
|
-
* @param {string} event - Event type to remove from the element.
|
|
131
|
-
* @param {Function} eventHandler - Callback for event.
|
|
132
|
-
*/
|
|
133
|
-
function remove(behaviorElement, event, eventHandler) {
|
|
134
|
-
behaviorElement.removeEventListener(event, eventHandler);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
128
|
// Expose public methods.
|
|
138
|
-
export {
|
|
129
|
+
export { behaviorAttach, checkBehaviorDom, behaviorFind };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { checkBehaviorDom, behaviorFind } from './behavior.js';
|
|
2
|
+
|
|
3
|
+
let containerDom;
|
|
4
|
+
|
|
5
|
+
const HTML_SNIPPET = `
|
|
6
|
+
<div id="container" data-js-hook="behavior_flyout-menu">
|
|
7
|
+
<button data-js-hook="behavior_flyout-menu_trigger">
|
|
8
|
+
<div data-js-hook="behavior_flyout-menu_content">…</div>
|
|
9
|
+
</div>
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
describe('behaviors', () => {
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
document.body.innerHTML = HTML_SNIPPET;
|
|
15
|
+
containerDom = document.querySelector('#container');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('.checkBehaviorDom()', () => {
|
|
19
|
+
it('should return an HTML element', () => {
|
|
20
|
+
expect(
|
|
21
|
+
checkBehaviorDom(
|
|
22
|
+
containerDom,
|
|
23
|
+
'behavior_flyout-menu_content',
|
|
24
|
+
).getAttribute('data-js-hook'),
|
|
25
|
+
).toBe('behavior_flyout-menu_content');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('.behaviorFind()', () => {
|
|
30
|
+
it('should return an array with two items when selectors are found', () => {
|
|
31
|
+
const result = behaviorFind('flyout-menu', containerDom);
|
|
32
|
+
expect(result).toBeInstanceOf(NodeList);
|
|
33
|
+
expect(result.length).toBe(2);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
package/src/utilities/index.js
CHANGED
|
@@ -13,7 +13,11 @@ export { EventObserver } from './event-observer.js';
|
|
|
13
13
|
|
|
14
14
|
export { checkDom, instantiateAll, setInitFlag } from './atomic-helpers.js';
|
|
15
15
|
|
|
16
|
-
export {
|
|
16
|
+
export {
|
|
17
|
+
behaviorAttach,
|
|
18
|
+
checkBehaviorDom,
|
|
19
|
+
behaviorFind,
|
|
20
|
+
} from './behavior/behavior.js';
|
|
17
21
|
|
|
18
22
|
export {
|
|
19
23
|
isUndefined,
|