@noctuatech/uswds 0.1.2 → 0.1.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.
- package/package.json +13 -11
- package/src/lib/collection/collection.stories.ts +2 -2
- package/src/lib/combo-box/combo-box-option/combo-box-option.element.ts +4 -5
- package/src/lib/combo-box/combo-box.element.ts +132 -18
- package/src/lib/combo-box/combo-box.stories.ts +52 -60
- package/src/lib/combo-box/combo-box.test.ts +123 -15
- package/target/lib/accordion/accordion.element.js +2 -86
- package/target/lib/accordion/accordion.stories.js +1 -26
- package/target/lib/accordion/accordion.test.js +5 -72
- package/target/lib/alert/alert.element.js +2 -71
- package/target/lib/alert/alert.stories.js +1 -41
- package/target/lib/alert/alert.test.js +1 -9
- package/target/lib/button/button.element.js +2 -142
- package/target/lib/button/button.stories.js +1 -6
- package/target/lib/button/button.test.js +1 -3
- package/target/lib/card/card-body/card-body.element.js +1 -8
- package/target/lib/card/card-footer/card-footer.element.js +1 -6
- package/target/lib/card/card-group/card-group.element.js +1 -12
- package/target/lib/card/card-header/card-header.element.js +1 -16
- package/target/lib/card/card-media/card-media.element.js +2 -33
- package/target/lib/card/card.element.js +1 -32
- package/target/lib/card/card.stories.js +2 -107
- package/target/lib/card/card.test.js +1 -20
- package/target/lib/checkbox/checkbox-group/checkbox-group.element.js +2 -10
- package/target/lib/checkbox/checkbox.element.js +2 -112
- package/target/lib/checkbox/checkbox.stories.js +2 -43
- package/target/lib/checkbox/checkbox.test.js +4 -28
- package/target/lib/collection/collection-item/collection-item.element.js +2 -40
- package/target/lib/collection/collection-item/collection-item.test.js +1 -3
- package/target/lib/collection/collection.element.js +2 -10
- package/target/lib/collection/collection.stories.js +1 -63
- package/target/lib/collection/collection.test.js +1 -3
- package/target/lib/combo-box/combo-box-option/combo-box-option.element.js +4 -16
- package/target/lib/combo-box/combo-box-option/combo-box-option.element.js.map +1 -1
- package/target/lib/combo-box/combo-box.element.d.ts +8 -0
- package/target/lib/combo-box/combo-box.element.js +73 -64
- package/target/lib/combo-box/combo-box.element.js.map +1 -1
- package/target/lib/combo-box/combo-box.stories.js +1 -213
- package/target/lib/combo-box/combo-box.stories.js.map +1 -1
- package/target/lib/combo-box/combo-box.test.js +58 -15
- package/target/lib/combo-box/combo-box.test.js.map +1 -1
- package/target/lib/config/config.element.js +1 -5
- package/target/lib/config/config.test.js +1 -3
- package/target/lib/description/description.element.js +1 -7
- package/target/lib/description/description.test.js +1 -3
- package/target/lib/file-input/file-input-preview/file-input-preview.element.js +2 -61
- package/target/lib/file-input/file-input-preview/file-input-preview.test.js +5 -25
- package/target/lib/file-input/file-input.element.js +2 -82
- package/target/lib/file-input/file-input.stories.js +1 -13
- package/target/lib/file-input/file-input.test.js +2 -16
- package/target/lib/icon/icon.element.js +1 -14
- package/target/lib/icon/icon.stories.js +2 -13
- package/target/lib/input/input.element.js +2 -73
- package/target/lib/input/input.stories.js +2 -12
- package/target/lib/input/input.test.js +4 -24
- package/target/lib/input-mask/input-mask.element.js +1 -5
- package/target/lib/input-mask/input-mask.stories.js +1 -12
- package/target/lib/input-mask/input-mask.test.js +4 -24
- package/target/lib/link/link.element.js +2 -18
- package/target/lib/modal/modal-close/modal-close.element.js +2 -36
- package/target/lib/modal/modal-close/modal-close.test.js +1 -3
- package/target/lib/modal/modal-heading/modal-heading.element.js +2 -24
- package/target/lib/modal/modal-heading/modal-heading.test.js +1 -3
- package/target/lib/modal/modal.element.js +2 -33
- package/target/lib/modal/modal.stories.js +1 -18
- package/target/lib/modal/modal.test.js +1 -11
- package/target/lib/radio/radio-option/radio-option.element.js +2 -16
- package/target/lib/radio/radio-option/radio-option.test.js +1 -5
- package/target/lib/radio/radio.element.js +2 -98
- package/target/lib/radio/radio.stories.js +1 -26
- package/target/lib/radio/radio.test.js +5 -103
- package/target/lib/range-slider/range-slider.element.js +2 -52
- package/target/lib/range-slider/range-slider.test.js +3 -17
- package/target/lib/select/select-option/select-option.element.js +1 -5
- package/target/lib/select/select.element.js +2 -49
- package/target/lib/select/select.stories.js +1 -10
- package/target/lib/select/select.test.js +6 -64
- package/target/lib/side-nav/side-nav-item/side-nav-item.element.js +2 -67
- package/target/lib/side-nav/side-nav.element.js +1 -8
- package/target/lib/side-nav/side-nav.stories.js +1 -39
- package/target/lib/side-nav/side-nav.test.js +2 -78
- package/target/lib/step-indicator/step/step.element.js +2 -96
- package/target/lib/step-indicator/step-indicator.element.js +1 -9
- package/target/lib/step-indicator/step-indicator.stories.js +1 -21
- package/target/lib/step-indicator/step-indicator.test.js +1 -9
- package/target/lib/summary-box/summary-box.element.js +2 -14
- package/target/lib/summary-box/summary-box.stories.js +1 -1
- package/target/lib/summary-box/summary-box.test.js +1 -3
- package/target/lib/tag/tag.element.js +1 -22
- package/target/lib/tag/tag.stories.js +1 -1
- package/target/lib/tag/tag.test.js +1 -3
- package/target/lib/textarea/textarea.element.js +2 -49
- package/target/lib/textarea/textarea.test.js +4 -24
|
@@ -3,33 +3,27 @@ import "./combo-box-option/combo-box-option.element.js";
|
|
|
3
3
|
import "../input/input.element.js";
|
|
4
4
|
|
|
5
5
|
import { assert, fixture, html } from "@open-wc/testing";
|
|
6
|
+
import { userEvent } from "@testing-library/user-event";
|
|
6
7
|
|
|
7
|
-
import type { USATextInputElement } from "../input/input.element.js";
|
|
8
8
|
import type { USAComboBoxElement } from "./combo-box.element.js";
|
|
9
9
|
|
|
10
10
|
describe("usa-combo-box", () => {
|
|
11
11
|
let autocomplete: USAComboBoxElement;
|
|
12
|
-
let input:
|
|
12
|
+
let input: HTMLInputElement;
|
|
13
13
|
|
|
14
14
|
beforeEach(async () => {
|
|
15
15
|
autocomplete = await fixture<USAComboBoxElement>(html`
|
|
16
|
-
<usa-combo-box>
|
|
17
|
-
<
|
|
16
|
+
<usa-combo-box name="search" placeholder="Select a fruit">
|
|
17
|
+
<span slot="label">Fruits</span>
|
|
18
18
|
|
|
19
|
-
<usa-combo-box-option value="Apple"
|
|
20
|
-
<usa-combo-box-option value="Banana"
|
|
21
|
-
<usa-combo-box-option value="Blueberry"
|
|
22
|
-
<usa-combo-box-option value="Cherry"
|
|
19
|
+
<usa-combo-box-option value="Apple">Apple</usa-combo-box-option>
|
|
20
|
+
<usa-combo-box-option value="Banana">Banana</usa-combo-box-option>
|
|
21
|
+
<usa-combo-box-option value="Blueberry">Blueberry</usa-combo-box-option>
|
|
22
|
+
<usa-combo-box-option value="Cherry">Cherry</usa-combo-box-option>
|
|
23
23
|
</usa-combo-box>
|
|
24
24
|
`);
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (!inputElement) {
|
|
29
|
-
throw new Error("Input element not found");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
input = inputElement;
|
|
26
|
+
input = autocomplete.input();
|
|
33
27
|
});
|
|
34
28
|
|
|
35
29
|
it("should filter items based on input", async () => {
|
|
@@ -147,4 +141,118 @@ describe("usa-combo-box", () => {
|
|
|
147
141
|
"Blueberry",
|
|
148
142
|
);
|
|
149
143
|
});
|
|
144
|
+
|
|
145
|
+
it("should submit form with default values", async () => {
|
|
146
|
+
const form = await fixture<HTMLFormElement>(html`
|
|
147
|
+
<form>
|
|
148
|
+
<usa-combo-box name="search" value="Apple" placeholder="Select a fruit">
|
|
149
|
+
<span slot="label">Fruits</span>
|
|
150
|
+
|
|
151
|
+
<usa-combo-box-option value="Apple">Apple</usa-combo-box-option>
|
|
152
|
+
<usa-combo-box-option value="Banana">Banana</usa-combo-box-option>
|
|
153
|
+
<usa-combo-box-option value="Blueberry">Blueberry</usa-combo-box-option>
|
|
154
|
+
<usa-combo-box-option value="Cherry">Cherry</usa-combo-box-option>
|
|
155
|
+
</usa-combo-box>
|
|
156
|
+
|
|
157
|
+
<button>Submit</button>
|
|
158
|
+
</form>
|
|
159
|
+
`);
|
|
160
|
+
|
|
161
|
+
const value = new FormData(form);
|
|
162
|
+
assert.equal(value.get("search"), "Apple");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("should update form value when an option is selected", async () => {
|
|
166
|
+
const form = await fixture<HTMLFormElement>(html`
|
|
167
|
+
<form>
|
|
168
|
+
<usa-combo-box name="search" placeholder="Select a fruit">
|
|
169
|
+
<span slot="label">Fruits</span>
|
|
170
|
+
|
|
171
|
+
<usa-combo-box-option value="Apple">Apple</usa-combo-box-option>
|
|
172
|
+
<usa-combo-box-option value="Banana">Banana</usa-combo-box-option>
|
|
173
|
+
<usa-combo-box-option value="Blueberry">Blueberry</usa-combo-box-option>
|
|
174
|
+
<usa-combo-box-option value="Cherry">Cherry</usa-combo-box-option>
|
|
175
|
+
</usa-combo-box>
|
|
176
|
+
|
|
177
|
+
<button>Submit</button>
|
|
178
|
+
</form>
|
|
179
|
+
`);
|
|
180
|
+
|
|
181
|
+
const comboBox = form.querySelector("usa-combo-box");
|
|
182
|
+
|
|
183
|
+
if (!comboBox) {
|
|
184
|
+
throw new Error("Combo box not found");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const input = comboBox.shadowRoot?.querySelector("input");
|
|
188
|
+
|
|
189
|
+
if (!input) {
|
|
190
|
+
throw new Error("input not found");
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Type to show suggestions
|
|
194
|
+
input.value = "Ban";
|
|
195
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
196
|
+
|
|
197
|
+
// Select the first suggestion
|
|
198
|
+
const suggestions = comboBox.listItems();
|
|
199
|
+
|
|
200
|
+
suggestions[0]
|
|
201
|
+
.querySelector("slot")
|
|
202
|
+
?.assignedElements()[0]
|
|
203
|
+
.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
204
|
+
|
|
205
|
+
const value = new FormData(form);
|
|
206
|
+
assert.equal(value.get("search"), "Banana");
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("should not submit when required and no value is selected", async () => {
|
|
210
|
+
const form = await fixture<HTMLFormElement>(html`
|
|
211
|
+
<form>
|
|
212
|
+
<usa-combo-box name="search" required placeholder="Select a fruit">
|
|
213
|
+
<span slot="label">Fruits</span>
|
|
214
|
+
|
|
215
|
+
<usa-combo-box-option value="Apple">Apple</usa-combo-box-option>
|
|
216
|
+
<usa-combo-box-option value="Banana">Banana</usa-combo-box-option>
|
|
217
|
+
<usa-combo-box-option value="Blueberry">Blueberry</usa-combo-box-option>
|
|
218
|
+
<usa-combo-box-option value="Cherry">Cherry</usa-combo-box-option>
|
|
219
|
+
</usa-combo-box>
|
|
220
|
+
|
|
221
|
+
<button>Submit</button>
|
|
222
|
+
</form>
|
|
223
|
+
`);
|
|
224
|
+
|
|
225
|
+
assert.equal(form.checkValidity(), false);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// it("should reset to default value when form is reset", async () => {
|
|
229
|
+
// const form = await fixture<HTMLFormElement>(html`
|
|
230
|
+
// <form>
|
|
231
|
+
// <usa-combo-box name="search" value="Apple" placeholder="Select a fruit">
|
|
232
|
+
// <span slot="label">Fruits</span>
|
|
233
|
+
|
|
234
|
+
// <usa-combo-box-option value="Apple">Apple</usa-combo-box-option>
|
|
235
|
+
// <usa-combo-box-option value="Banana">Banana</usa-combo-box-option>
|
|
236
|
+
// <usa-combo-box-option value="Blueberry">Blueberry</usa-combo-box-option>
|
|
237
|
+
// <usa-combo-box-option value="Cherry">Cherry</usa-combo-box-option>
|
|
238
|
+
// </usa-combo-box>
|
|
239
|
+
|
|
240
|
+
// <button type="submit">Submit</button>
|
|
241
|
+
// <button type="reset">Reset</button>
|
|
242
|
+
// </form>
|
|
243
|
+
// `);
|
|
244
|
+
|
|
245
|
+
// const comboBox = form.querySelector("usa-combo-box");
|
|
246
|
+
// if (comboBox) {
|
|
247
|
+
// // Change the value
|
|
248
|
+
// comboBox.value = "Banana";
|
|
249
|
+
// comboBox.dispatchEvent(new Event("input", { bubbles: true }));
|
|
250
|
+
|
|
251
|
+
// // Reset the form
|
|
252
|
+
// form.reset();
|
|
253
|
+
|
|
254
|
+
// // Check that the value was reset
|
|
255
|
+
// assert.equal(comboBox.value, "Apple");
|
|
256
|
+
// }
|
|
257
|
+
// });
|
|
150
258
|
});
|
|
@@ -9,92 +9,8 @@ let USAAccordionElement = (() => {
|
|
|
9
9
|
delegatesFocus: true,
|
|
10
10
|
},
|
|
11
11
|
shadowDom: [
|
|
12
|
-
css
|
|
13
|
-
|
|
14
|
-
box-sizing: border-box;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
:host {
|
|
18
|
-
display: block;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
:host(:not(:first-child)) summary {
|
|
22
|
-
margin-top: 0.5rem;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
summary {
|
|
26
|
-
align-items: center;
|
|
27
|
-
border: 0;
|
|
28
|
-
border-radius: 0;
|
|
29
|
-
box-shadow: none;
|
|
30
|
-
justify-content: normal;
|
|
31
|
-
text-align: left;
|
|
32
|
-
padding: 0;
|
|
33
|
-
color: #1b1b1b;
|
|
34
|
-
background-color: #f0f0f0;
|
|
35
|
-
cursor: pointer;
|
|
36
|
-
display: flex;
|
|
37
|
-
font-weight: 700;
|
|
38
|
-
margin: 0;
|
|
39
|
-
padding: 1rem 1.25rem 1rem 1.25rem;
|
|
40
|
-
text-decoration: none;
|
|
41
|
-
width: 100%;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
summary::-webkit-details-marker {
|
|
45
|
-
display: none;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
slot[name="heading"] {
|
|
49
|
-
display: block;
|
|
50
|
-
flex: 1 1 auto;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
slot[name="heading"]::slotted(*) {
|
|
54
|
-
margin: 0;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.content {
|
|
58
|
-
padding-bottom: 1.5rem;
|
|
59
|
-
padding-left: 1rem;
|
|
60
|
-
padding-top: 1.5rem;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
usa-icon[icon="remove"] {
|
|
64
|
-
display: none;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
details[open] usa-icon[icon="add"] {
|
|
68
|
-
display: none;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
details[open] usa-icon[icon="remove"] {
|
|
72
|
-
display: block;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
summary:hover {
|
|
76
|
-
background-color: #e6e6e6;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
summary:focus {
|
|
80
|
-
outline: 0.25rem solid #2491ff;
|
|
81
|
-
outline-offset: 0;
|
|
82
|
-
}
|
|
83
|
-
`,
|
|
84
|
-
html `
|
|
85
|
-
<details>
|
|
86
|
-
<summary>
|
|
87
|
-
<slot name="heading"></slot>
|
|
88
|
-
|
|
89
|
-
<usa-icon icon="add"></usa-icon>
|
|
90
|
-
<usa-icon icon="remove"></usa-icon>
|
|
91
|
-
</summary>
|
|
92
|
-
|
|
93
|
-
<div class="content">
|
|
94
|
-
<slot></slot>
|
|
95
|
-
</div>
|
|
96
|
-
</details>
|
|
97
|
-
`,
|
|
12
|
+
css `*{box-sizing:border-box}:host{display:block}:host(:not(:first-child)) summary{margin-top:.5rem}summary{align-items:center;border:0;border-radius:0;box-shadow:none;justify-content:normal;text-align:left;padding:0;color:#1b1b1b;background-color:#f0f0f0;cursor:pointer;display:flex;font-weight:700;margin:0;padding:1rem 1.25rem 1rem 1.25rem;text-decoration:none;width:100%}summary::-webkit-details-marker{display:none}slot[name=heading]{display:block;flex:1 1 auto}slot[name=heading]::slotted(*){margin:0}.content{padding-bottom:1.5rem;padding-left:1rem;padding-top:1.5rem}usa-icon[icon=remove]{display:none}details[open] usa-icon[icon=add]{display:none}details[open] usa-icon[icon=remove]{display:block}summary:hover{background-color:#e6e6e6}summary:focus{outline:.25rem solid #2491ff;outline-offset:0}`,
|
|
13
|
+
html `<details><summary><slot name="heading"></slot><usa-icon icon="add"></usa-icon><usa-icon icon="remove"></usa-icon></summary><div class="content"><slot></slot></div></details>`,
|
|
98
14
|
],
|
|
99
15
|
})];
|
|
100
16
|
let _classDescriptor;
|
|
@@ -4,32 +4,7 @@ const meta = {
|
|
|
4
4
|
title: "usa-accordion",
|
|
5
5
|
tags: ["autodocs"],
|
|
6
6
|
render() {
|
|
7
|
-
return html
|
|
8
|
-
<usa-accordion id="first" name="ammendment">
|
|
9
|
-
<h4 slot="heading">First Ammendment</h4>
|
|
10
|
-
|
|
11
|
-
Congress shall make no law respecting an establishment of religion, or
|
|
12
|
-
prohibiting the free exercise thereof; or abridging the freedom of
|
|
13
|
-
speech, or of the press; or the right of the people peaceably to
|
|
14
|
-
assemble, and to petition the Government for a redress of grievances.
|
|
15
|
-
</usa-accordion>
|
|
16
|
-
|
|
17
|
-
<usa-accordion id="second" name="ammendment">
|
|
18
|
-
<h4 slot="heading">Second Ammendment</h4>
|
|
19
|
-
|
|
20
|
-
A well regulated Militia, being necessary to the security of a free
|
|
21
|
-
State, the right of the people to keep and bear Arms, shall not be
|
|
22
|
-
infringed.
|
|
23
|
-
</usa-accordion>
|
|
24
|
-
|
|
25
|
-
<usa-accordion id="third" name="ammendment">
|
|
26
|
-
<h4 slot="heading">Third Ammendment</h4>
|
|
27
|
-
|
|
28
|
-
No Soldier shall, in time of peace be quartered in any house, without
|
|
29
|
-
the consent of the Owner, nor in time of war, but in a manner to be
|
|
30
|
-
prescribed by law.
|
|
31
|
-
</usa-accordion>
|
|
32
|
-
`;
|
|
7
|
+
return html `<usa-accordion id="first" name="ammendment"><h4 slot="heading">First Ammendment</h4>Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances.</usa-accordion><usa-accordion id="second" name="ammendment"><h4 slot="heading">Second Ammendment</h4>A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed.</usa-accordion><usa-accordion id="third" name="ammendment"><h4 slot="heading">Third Ammendment</h4>No Soldier shall, in time of peace be quartered in any house, without the consent of the Owner, nor in time of war, but in a manner to be prescribed by law.</usa-accordion>`;
|
|
33
8
|
},
|
|
34
9
|
argTypes: {},
|
|
35
10
|
args: {},
|
|
@@ -4,51 +4,18 @@ import { screen } from "@testing-library/dom";
|
|
|
4
4
|
import { userEvent } from "@testing-library/user-event";
|
|
5
5
|
describe("usa-accordion", () => {
|
|
6
6
|
it("should be accessible", async () => {
|
|
7
|
-
const accordion = await fixture(html
|
|
8
|
-
<usa-accordion id="first" name="ammendment">
|
|
9
|
-
<h4 slot="heading">First Ammendment</h4>
|
|
10
|
-
|
|
11
|
-
<div class="content">
|
|
12
|
-
Congress shall make no law respecting an establishment of religion, or
|
|
13
|
-
prohibiting the free exercise thereof; or abridging the freedom of
|
|
14
|
-
speech, or of the press; or the right of the people peaceably to
|
|
15
|
-
assemble, and to petition the Government for a redress of grievances.
|
|
16
|
-
</div>
|
|
17
|
-
</usa-accordion>
|
|
18
|
-
`);
|
|
7
|
+
const accordion = await fixture(html `<usa-accordion id="first" name="ammendment"><h4 slot="heading">First Ammendment</h4><div class="content">Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances.</div></usa-accordion>`);
|
|
19
8
|
return assert.isAccessible(accordion);
|
|
20
9
|
});
|
|
21
10
|
it("should toggle the open state when clicked", async () => {
|
|
22
|
-
const accordion = await fixture(html
|
|
23
|
-
<usa-accordion id="first" name="ammendment">
|
|
24
|
-
<h4 slot="heading">First Ammendment</h4>
|
|
25
|
-
|
|
26
|
-
<div class="content">
|
|
27
|
-
Congress shall make no law respecting an establishment of religion, or
|
|
28
|
-
prohibiting the free exercise thereof; or abridging the freedom of
|
|
29
|
-
speech, or of the press; or the right of the people peaceably to
|
|
30
|
-
assemble, and to petition the Government for a redress of grievances.
|
|
31
|
-
</div>
|
|
32
|
-
</usa-accordion>
|
|
33
|
-
`);
|
|
11
|
+
const accordion = await fixture(html `<usa-accordion id="first" name="ammendment"><h4 slot="heading">First Ammendment</h4><div class="content">Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances.</div></usa-accordion>`);
|
|
34
12
|
const heading = await screen.findByRole("heading");
|
|
35
13
|
const content = accordion.querySelector(".content");
|
|
36
14
|
await userEvent.click(heading);
|
|
37
15
|
assert.isTrue(content?.checkVisibility());
|
|
38
16
|
});
|
|
39
17
|
it("should toggle the open state when clicked", async () => {
|
|
40
|
-
const accordion = await fixture(html
|
|
41
|
-
<usa-accordion id="first" name="ammendment">
|
|
42
|
-
<h4 slot="heading">First Ammendment</h4>
|
|
43
|
-
|
|
44
|
-
<div class="content">
|
|
45
|
-
Congress shall make no law respecting an establishment of religion, or
|
|
46
|
-
prohibiting the free exercise thereof; or abridging the freedom of
|
|
47
|
-
speech, or of the press; or the right of the people peaceably to
|
|
48
|
-
assemble, and to petition the Government for a redress of grievances.
|
|
49
|
-
</div>
|
|
50
|
-
</usa-accordion>
|
|
51
|
-
`);
|
|
18
|
+
const accordion = await fixture(html `<usa-accordion id="first" name="ammendment"><h4 slot="heading">First Ammendment</h4><div class="content">Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances.</div></usa-accordion>`);
|
|
52
19
|
const heading = await screen.findByRole("heading");
|
|
53
20
|
const content = accordion.querySelector(".content");
|
|
54
21
|
assert.isFalse(content?.checkVisibility());
|
|
@@ -56,24 +23,7 @@ describe("usa-accordion", () => {
|
|
|
56
23
|
assert.isTrue(content.checkVisibility());
|
|
57
24
|
});
|
|
58
25
|
it("should only allow a single accordion in a group to be open", async () => {
|
|
59
|
-
const el = await fixture(html
|
|
60
|
-
<section>
|
|
61
|
-
<usa-accordion name="ammendment">
|
|
62
|
-
<h4 slot="heading">First Ammendment</h4>
|
|
63
|
-
<div class="content">Content for First</div>
|
|
64
|
-
</usa-accordion>
|
|
65
|
-
|
|
66
|
-
<usa-accordion name="ammendment">
|
|
67
|
-
<h4 slot="heading">Second Ammendment</h4>
|
|
68
|
-
<div class="content">Content for Second</div>
|
|
69
|
-
</usa-accordion>
|
|
70
|
-
|
|
71
|
-
<usa-accordion name="ammendment">
|
|
72
|
-
<h4 slot="heading">Third Ammendment</h4>
|
|
73
|
-
<div class="content">Content for Third</div>
|
|
74
|
-
</usa-accordion>
|
|
75
|
-
</section>
|
|
76
|
-
`);
|
|
26
|
+
const el = await fixture(html `<section><usa-accordion name="ammendment"><h4 slot="heading">First Ammendment</h4><div class="content">Content for First</div></usa-accordion><usa-accordion name="ammendment"><h4 slot="heading">Second Ammendment</h4><div class="content">Content for Second</div></usa-accordion><usa-accordion name="ammendment"><h4 slot="heading">Third Ammendment</h4><div class="content">Content for Third</div></usa-accordion></section>`);
|
|
77
27
|
const headings = el.querySelectorAll("h4");
|
|
78
28
|
const content = Array.from(el.querySelectorAll(".content"));
|
|
79
29
|
await userEvent.click(headings[0]);
|
|
@@ -84,24 +34,7 @@ describe("usa-accordion", () => {
|
|
|
84
34
|
assert.deepEqual(content.map((el) => el.checkVisibility()), [false, false, true]);
|
|
85
35
|
});
|
|
86
36
|
it("should not close accordion not in the same group", async () => {
|
|
87
|
-
const el = await fixture(html
|
|
88
|
-
<section>
|
|
89
|
-
<usa-accordion name="ammendment">
|
|
90
|
-
<h4 slot="heading">First Ammendment</h4>
|
|
91
|
-
<div class="content">Content for First</div>
|
|
92
|
-
</usa-accordion>
|
|
93
|
-
|
|
94
|
-
<usa-accordion name="ammendment">
|
|
95
|
-
<h4 slot="heading">Second Ammendment</h4>
|
|
96
|
-
<div class="content">Content for Second</div>
|
|
97
|
-
</usa-accordion>
|
|
98
|
-
|
|
99
|
-
<usa-accordion name="different">
|
|
100
|
-
<h4 slot="heading">Third Ammendment</h4>
|
|
101
|
-
<div class="content">Content for Third</div>
|
|
102
|
-
</usa-accordion>
|
|
103
|
-
</section>
|
|
104
|
-
`);
|
|
37
|
+
const el = await fixture(html `<section><usa-accordion name="ammendment"><h4 slot="heading">First Ammendment</h4><div class="content">Content for First</div></usa-accordion><usa-accordion name="ammendment"><h4 slot="heading">Second Ammendment</h4><div class="content">Content for Second</div></usa-accordion><usa-accordion name="different"><h4 slot="heading">Third Ammendment</h4><div class="content">Content for Third</div></usa-accordion></section>`);
|
|
105
38
|
const headings = el.querySelectorAll("h4");
|
|
106
39
|
const content = Array.from(el.querySelectorAll(".content"));
|
|
107
40
|
await userEvent.click(headings[0]);
|
|
@@ -9,77 +9,8 @@ let USAAlertElement = (() => {
|
|
|
9
9
|
delegatesFocus: true,
|
|
10
10
|
},
|
|
11
11
|
shadowDom: [
|
|
12
|
-
css
|
|
13
|
-
|
|
14
|
-
display: block;
|
|
15
|
-
border-left: 0.5rem solid #adadad;
|
|
16
|
-
padding: 1rem 1.2rem;
|
|
17
|
-
color: #1b1b1b;
|
|
18
|
-
margin-bottom: 1rem;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
:host([type="info"]) {
|
|
22
|
-
border-left-color: #00bde3;
|
|
23
|
-
background-color: #e7f6f8;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
:host([type="warning"]) {
|
|
27
|
-
background-color: #faf3d1;
|
|
28
|
-
border-left-color: #ffbe2e;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
:host([type="success"]) {
|
|
32
|
-
background-color: #ecf3ec;
|
|
33
|
-
border-left-color: #00a91c;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
:host([type="error"]) {
|
|
37
|
-
background-color: #f4e3db;
|
|
38
|
-
border-left-color: #d54309;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
:host([type="emergency"]) {
|
|
42
|
-
background-color: #9c3d10;
|
|
43
|
-
border-left-color: #9c3d10;
|
|
44
|
-
color: #fff;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
:host([type="emergency"]) ::slotted(*) {
|
|
48
|
-
color: #fff;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
.alert-heading {
|
|
52
|
-
display: grid;
|
|
53
|
-
grid-template-columns: auto 1fr;
|
|
54
|
-
align-items: center;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
usa-icon {
|
|
58
|
-
margin: -0.28rem 0.75rem 0 0;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
#heading::slotted(*) {
|
|
62
|
-
font-size: 1.33rem;
|
|
63
|
-
line-height: 0.9;
|
|
64
|
-
margin-top: 0;
|
|
65
|
-
margin-bottom: 0.5rem;
|
|
66
|
-
}
|
|
67
|
-
`,
|
|
68
|
-
html `
|
|
69
|
-
<div class="alert-heading">
|
|
70
|
-
<usa-icon icon="check_circle"></usa-icon>
|
|
71
|
-
|
|
72
|
-
<div>
|
|
73
|
-
<slot id="heading" name="heading"></slot>
|
|
74
|
-
</div>
|
|
75
|
-
|
|
76
|
-
<div class="spacer"></div>
|
|
77
|
-
|
|
78
|
-
<div>
|
|
79
|
-
<slot></slot>
|
|
80
|
-
</div>
|
|
81
|
-
</div>
|
|
82
|
-
`,
|
|
12
|
+
css `:host{display:block;border-left:.5rem solid #adadad;padding:1rem 1.2rem;color:#1b1b1b;margin-bottom:1rem}:host([type=info]){border-left-color:#00bde3;background-color:#e7f6f8}:host([type=warning]){background-color:#faf3d1;border-left-color:#ffbe2e}:host([type=success]){background-color:#ecf3ec;border-left-color:#00a91c}:host([type=error]){background-color:#f4e3db;border-left-color:#d54309}:host([type=emergency]){background-color:#9c3d10;border-left-color:#9c3d10;color:#fff}:host([type=emergency]) ::slotted(*){color:#fff}.alert-heading{display:grid;grid-template-columns:auto 1fr;align-items:center}usa-icon{margin:-.28rem .75rem 0 0}#heading::slotted(*){font-size:1.33rem;line-height:.9;margin-top:0;margin-bottom:.5rem}`,
|
|
13
|
+
html `<div class="alert-heading"><usa-icon icon="check_circle"></usa-icon><div><slot id="heading" name="heading"></slot></div><div class="spacer"></div><div><slot></slot></div></div>`,
|
|
83
14
|
],
|
|
84
15
|
})];
|
|
85
16
|
let _classDescriptor;
|
|
@@ -10,47 +10,7 @@ export default meta;
|
|
|
10
10
|
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
11
11
|
export const Primary = {
|
|
12
12
|
render() {
|
|
13
|
-
return html
|
|
14
|
-
<usa-alert type="info">
|
|
15
|
-
<h3 slot="heading">Informative status</h3>
|
|
16
|
-
|
|
17
|
-
Lorem ipsum dolor sit amet,
|
|
18
|
-
<usa-link href="#">consectetur adipiscing</usa-link> elit, sed do
|
|
19
|
-
eiusmod.
|
|
20
|
-
</usa-alert>
|
|
21
|
-
|
|
22
|
-
<usa-alert type="warning">
|
|
23
|
-
<h3 slot="heading">Warning status</h3>
|
|
24
|
-
|
|
25
|
-
Lorem ipsum dolor sit amet,
|
|
26
|
-
<usa-link href="#">consectetur adipiscing</usa-link> elit, sed do
|
|
27
|
-
eiusmod.
|
|
28
|
-
</usa-alert>
|
|
29
|
-
|
|
30
|
-
<usa-alert type="success">
|
|
31
|
-
<h3 slot="heading">Success status</h3>
|
|
32
|
-
|
|
33
|
-
Lorem ipsum dolor sit amet,
|
|
34
|
-
<usa-link href="#">consectetur adipiscing</usa-link> elit, sed do
|
|
35
|
-
eiusmod.
|
|
36
|
-
</usa-alert>
|
|
37
|
-
|
|
38
|
-
<usa-alert type="error">
|
|
39
|
-
<h3 slot="heading">Error status</h3>
|
|
40
|
-
|
|
41
|
-
Lorem ipsum dolor sit amet,
|
|
42
|
-
<usa-link href="#">consectetur adipiscing</usa-link> elit, sed do
|
|
43
|
-
eiusmod.
|
|
44
|
-
</usa-alert>
|
|
45
|
-
|
|
46
|
-
<usa-alert type="emergency">
|
|
47
|
-
<h3 slot="heading">Emergency status</h3>
|
|
48
|
-
|
|
49
|
-
Lorem ipsum dolor sit amet,
|
|
50
|
-
<usa-link href="#">consectetur adipiscing</usa-link> elit, sed do
|
|
51
|
-
eiusmod.
|
|
52
|
-
</usa-alert>
|
|
53
|
-
`;
|
|
13
|
+
return html `<usa-alert type="info"><h3 slot="heading">Informative status</h3>Lorem ipsum dolor sit amet, <usa-link href="#">consectetur adipiscing</usa-link> elit, sed do eiusmod.</usa-alert><usa-alert type="warning"><h3 slot="heading">Warning status</h3>Lorem ipsum dolor sit amet, <usa-link href="#">consectetur adipiscing</usa-link> elit, sed do eiusmod.</usa-alert><usa-alert type="success"><h3 slot="heading">Success status</h3>Lorem ipsum dolor sit amet, <usa-link href="#">consectetur adipiscing</usa-link> elit, sed do eiusmod.</usa-alert><usa-alert type="error"><h3 slot="heading">Error status</h3>Lorem ipsum dolor sit amet, <usa-link href="#">consectetur adipiscing</usa-link> elit, sed do eiusmod.</usa-alert><usa-alert type="emergency"><h3 slot="heading">Emergency status</h3>Lorem ipsum dolor sit amet, <usa-link href="#">consectetur adipiscing</usa-link> elit, sed do eiusmod.</usa-alert>`;
|
|
54
14
|
},
|
|
55
15
|
};
|
|
56
16
|
//# sourceMappingURL=alert.stories.js.map
|
|
@@ -4,15 +4,7 @@ import { USA_ALERT_TYPES } from "./alert-types.js";
|
|
|
4
4
|
describe("usa-alert", () => {
|
|
5
5
|
for (const alert of USA_ALERT_TYPES) {
|
|
6
6
|
it(`should be accessible: ${alert}`, async () => {
|
|
7
|
-
const form = await fixture(html
|
|
8
|
-
<usa-alert type=${alert}>
|
|
9
|
-
<h3 slot="heading">Status</h3>
|
|
10
|
-
|
|
11
|
-
Lorem ipsum dolor sit amet,
|
|
12
|
-
<usa-link href="#">consectetur adipiscing</usa-link> elit, sed do
|
|
13
|
-
eiusmod.
|
|
14
|
-
</usa-alert>
|
|
15
|
-
`);
|
|
7
|
+
const form = await fixture(html `<usa-alert type="${alert}"><h3 slot="heading">Status</h3>Lorem ipsum dolor sit amet, <usa-link href="#">consectetur adipiscing</usa-link> elit, sed do eiusmod.</usa-alert>`);
|
|
16
8
|
return assert.isAccessible(form);
|
|
17
9
|
});
|
|
18
10
|
}
|