@spectrum-web-components/grid 1.1.0 → 1.1.2
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 +4 -4
- package/sp-grid.d.ts +6 -0
- package/sp-grid.dev.js +4 -0
- package/sp-grid.dev.js.map +7 -0
- package/sp-grid.js +2 -0
- package/sp-grid.js.map +7 -0
- package/src/Grid.d.ts +28 -0
- package/src/Grid.dev.js +144 -0
- package/src/Grid.dev.js.map +7 -0
- package/src/Grid.js +4 -0
- package/src/Grid.js.map +7 -0
- package/src/GridController.d.ts +44 -0
- package/src/GridController.dev.js +158 -0
- package/src/GridController.dev.js.map +7 -0
- package/src/GridController.js +2 -0
- package/src/GridController.js.map +7 -0
- package/src/grid.css.d.ts +2 -0
- package/src/grid.css.dev.js +7 -0
- package/src/grid.css.dev.js.map +7 -0
- package/src/grid.css.js +4 -0
- package/src/grid.css.js.map +7 -0
- package/src/index.d.ts +1 -0
- package/src/index.dev.js +3 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +2 -0
- package/src/index.js.map +7 -0
- package/stories/grid.stories.js +261 -0
- package/stories/grid.stories.js.map +7 -0
- package/test/benchmark/basic-test.js +8 -0
- package/test/benchmark/basic-test.js.map +7 -0
- package/test/grid-memory.test.js +5 -0
- package/test/grid-memory.test.js.map +7 -0
- package/test/grid.test-vrt.js +5 -0
- package/test/grid.test-vrt.js.map +7 -0
- package/test/grid.test.js +239 -0
- package/test/grid.test.js.map +7 -0
package/src/index.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["index.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport * from './Grid.js';\n"],
|
|
5
|
+
"mappings": "aAYA,WAAc",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import {
|
|
3
|
+
css,
|
|
4
|
+
html,
|
|
5
|
+
SpectrumElement
|
|
6
|
+
} from "@spectrum-web-components/base";
|
|
7
|
+
import "@spectrum-web-components/grid/sp-grid.js";
|
|
8
|
+
import "@spectrum-web-components/action-bar/sp-action-bar.js";
|
|
9
|
+
import "@spectrum-web-components/card/sp-card.js";
|
|
10
|
+
import "@spectrum-web-components/action-menu/sp-action-menu.js";
|
|
11
|
+
import "@spectrum-web-components/menu/sp-menu-item.js";
|
|
12
|
+
import "@spectrum-web-components/tooltip/sp-tooltip.js";
|
|
13
|
+
import "@spectrum-web-components/checkbox/sp-checkbox.js";
|
|
14
|
+
import "@spectrum-web-components/action-button/sp-action-button.js";
|
|
15
|
+
import "@spectrum-web-components/action-group/sp-action-group.js";
|
|
16
|
+
import "@spectrum-web-components/icons-workflow/icons/sp-icon-edit.js";
|
|
17
|
+
import "@spectrum-web-components/icons-workflow/icons/sp-icon-more.js";
|
|
18
|
+
export default {
|
|
19
|
+
title: "Grid",
|
|
20
|
+
component: "sp-grid"
|
|
21
|
+
};
|
|
22
|
+
function generateItems(count) {
|
|
23
|
+
const items = [];
|
|
24
|
+
while (count) {
|
|
25
|
+
count -= 1;
|
|
26
|
+
items.unshift({ id: count });
|
|
27
|
+
}
|
|
28
|
+
return items;
|
|
29
|
+
}
|
|
30
|
+
const renderItem = (item, index, selected) => {
|
|
31
|
+
return html`
|
|
32
|
+
<sp-card
|
|
33
|
+
toggles
|
|
34
|
+
variant="quiet"
|
|
35
|
+
heading="Card Heading ${item.id}"
|
|
36
|
+
subheading="JPG Photo"
|
|
37
|
+
style="contain: strict; padding: 1px;"
|
|
38
|
+
value="card-${item.id}"
|
|
39
|
+
.selected=${selected}
|
|
40
|
+
key=${index}
|
|
41
|
+
draggable="true"
|
|
42
|
+
>
|
|
43
|
+
<img
|
|
44
|
+
alt=""
|
|
45
|
+
slot="preview"
|
|
46
|
+
src="https://picsum.photos/id/${item.id}/200/300"
|
|
47
|
+
decoding="async"
|
|
48
|
+
/>
|
|
49
|
+
<div slot="description">10/15/18</div>
|
|
50
|
+
<div slot="footer">Footer</div>
|
|
51
|
+
<sp-action-menu
|
|
52
|
+
label="File actions"
|
|
53
|
+
slot="actions"
|
|
54
|
+
placement="bottom-end"
|
|
55
|
+
quiet
|
|
56
|
+
tabindex="-1"
|
|
57
|
+
>
|
|
58
|
+
<sp-tooltip slot="tooltip" self-managed placement="top">
|
|
59
|
+
Do stuff
|
|
60
|
+
</sp-tooltip>
|
|
61
|
+
<sp-menu-item>Deselect</sp-menu-item>
|
|
62
|
+
<sp-menu-item>Select Inverse</sp-menu-item>
|
|
63
|
+
<sp-menu-item>Feather...</sp-menu-item>
|
|
64
|
+
<sp-menu-item>Select and Mask...</sp-menu-item>
|
|
65
|
+
<sp-menu-divider></sp-menu-divider>
|
|
66
|
+
<sp-menu-item>Save Selection</sp-menu-item>
|
|
67
|
+
<sp-menu-item disabled>Make Work Path</sp-menu-item>
|
|
68
|
+
</sp-action-menu>
|
|
69
|
+
</sp-card>
|
|
70
|
+
`;
|
|
71
|
+
};
|
|
72
|
+
const handleChange = (event) => {
|
|
73
|
+
const actionbar = document.querySelector("sp-action-bar");
|
|
74
|
+
const selected = document.querySelector(".selected");
|
|
75
|
+
const ids = document.querySelector(".ids");
|
|
76
|
+
actionbar.open = !!event.currentTarget.selected.length;
|
|
77
|
+
actionbar.style.setProperty(
|
|
78
|
+
"display",
|
|
79
|
+
!!event.currentTarget.selected.length ? "flex" : "none"
|
|
80
|
+
);
|
|
81
|
+
selected.textContent = "" + event.currentTarget.selected.length;
|
|
82
|
+
ids.textContent = "" + event.currentTarget.selected.map((selection) => selection.id).join(", ");
|
|
83
|
+
};
|
|
84
|
+
const handleActionBarChange = (event) => {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
const grid = document.querySelector("sp-grid");
|
|
87
|
+
const actionbar = document.querySelector("sp-action-bar");
|
|
88
|
+
actionbar.open = false;
|
|
89
|
+
grid.selected = [];
|
|
90
|
+
};
|
|
91
|
+
export const Default = () => {
|
|
92
|
+
const items = generateItems(1e3);
|
|
93
|
+
return html`
|
|
94
|
+
<h1>Random before content that is focusable</h1>
|
|
95
|
+
<input id="first-input" />
|
|
96
|
+
<sp-grid
|
|
97
|
+
@change=${handleChange}
|
|
98
|
+
.items=${items}
|
|
99
|
+
.focusableSelector=${"sp-card"}
|
|
100
|
+
.renderItem=${renderItem}
|
|
101
|
+
></sp-grid>
|
|
102
|
+
<sp-action-bar variant="fixed">
|
|
103
|
+
<sp-checkbox @click=${handleActionBarChange} checked>
|
|
104
|
+
<span class="selected"></span>
|
|
105
|
+
Selected
|
|
106
|
+
<span class="ids"></span>
|
|
107
|
+
</sp-checkbox>
|
|
108
|
+
<sp-action-group quiet>
|
|
109
|
+
<sp-action-button>
|
|
110
|
+
<sp-icon-edit slot="icon" label="Edit"></sp-icon-edit>
|
|
111
|
+
</sp-action-button>
|
|
112
|
+
<sp-action-button>
|
|
113
|
+
<sp-icon-more slot="icon" label="More"></sp-icon-more>
|
|
114
|
+
</sp-action-button>
|
|
115
|
+
</sp-action-group>
|
|
116
|
+
</sp-action-bar>
|
|
117
|
+
<h2>Random after content that is focusable</h2>
|
|
118
|
+
<input id="last-input" />
|
|
119
|
+
`;
|
|
120
|
+
};
|
|
121
|
+
Default.swc_vrt = {
|
|
122
|
+
skip: true
|
|
123
|
+
};
|
|
124
|
+
Default.parameters = {
|
|
125
|
+
// Disables Chromatic's snapshotting on a global level
|
|
126
|
+
chromatic: { disableSnapshot: true }
|
|
127
|
+
};
|
|
128
|
+
export const sized = ({ gap, padding } = { gap: 10, padding: 10 }) => {
|
|
129
|
+
const items = generateItems(1e3);
|
|
130
|
+
function handleMediaChange() {
|
|
131
|
+
let width = document.body.offsetWidth * 0.4;
|
|
132
|
+
const height = 300;
|
|
133
|
+
if (matchMedium.matches) {
|
|
134
|
+
width = 300;
|
|
135
|
+
} else if (matchLarge.matches) {
|
|
136
|
+
width = 400;
|
|
137
|
+
}
|
|
138
|
+
document.querySelector("sp-grid").itemSize = {
|
|
139
|
+
width,
|
|
140
|
+
height
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
const matchSmall = window.matchMedia("(max-width: 600px)");
|
|
144
|
+
const matchMedium = window.matchMedia(
|
|
145
|
+
"(min-width: 601px) and (max-width: 1200px)"
|
|
146
|
+
);
|
|
147
|
+
const matchLarge = window.matchMedia("(min-width: 1201px)");
|
|
148
|
+
matchSmall.addEventListener("change", handleMediaChange);
|
|
149
|
+
matchMedium.addEventListener("change", handleMediaChange);
|
|
150
|
+
matchLarge.addEventListener("change", handleMediaChange);
|
|
151
|
+
return html`
|
|
152
|
+
<h1>Random before content that is focusable</h1>
|
|
153
|
+
<input id="first-input" />
|
|
154
|
+
<sp-grid
|
|
155
|
+
@change=${handleChange}
|
|
156
|
+
.items=${items}
|
|
157
|
+
.focusableSelector=${"sp-card"}
|
|
158
|
+
.renderItem=${renderItem}
|
|
159
|
+
.itemSize=${{
|
|
160
|
+
width: 200,
|
|
161
|
+
height: 300
|
|
162
|
+
}}
|
|
163
|
+
.gap=${`${gap}px`}
|
|
164
|
+
.padding=${`${padding}px`}
|
|
165
|
+
></sp-grid>
|
|
166
|
+
<sp-action-bar variant="fixed" style="display: none">
|
|
167
|
+
<sp-checkbox @click=${handleActionBarChange} checked>
|
|
168
|
+
<span class="selected"></span>
|
|
169
|
+
Selected
|
|
170
|
+
<span class="ids"></span>
|
|
171
|
+
</sp-checkbox>
|
|
172
|
+
<sp-action-group quiet>
|
|
173
|
+
<sp-action-button>
|
|
174
|
+
<sp-icon-edit slot="icon" label="Edit"></sp-icon-edit>
|
|
175
|
+
</sp-action-button>
|
|
176
|
+
<sp-action-button>
|
|
177
|
+
<sp-icon-more slot="icon" label="More"></sp-icon-more>
|
|
178
|
+
</sp-action-button>
|
|
179
|
+
</sp-action-group>
|
|
180
|
+
</sp-action-bar>
|
|
181
|
+
<h2>Random after content that is focusable</h2>
|
|
182
|
+
<input id="last-input" />
|
|
183
|
+
`;
|
|
184
|
+
};
|
|
185
|
+
sized.args = {
|
|
186
|
+
gap: 10,
|
|
187
|
+
padding: 10
|
|
188
|
+
};
|
|
189
|
+
sized.argTypes = {
|
|
190
|
+
gap: {
|
|
191
|
+
name: "gap",
|
|
192
|
+
type: { name: "number", required: false },
|
|
193
|
+
description: "Spacing between items.",
|
|
194
|
+
table: {
|
|
195
|
+
type: { summary: "number" }
|
|
196
|
+
},
|
|
197
|
+
control: {
|
|
198
|
+
type: "number"
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
padding: {
|
|
202
|
+
name: "padding",
|
|
203
|
+
type: { name: "number", required: false },
|
|
204
|
+
description: "Spacing around all items.",
|
|
205
|
+
table: {
|
|
206
|
+
type: { summary: "number" }
|
|
207
|
+
},
|
|
208
|
+
control: {
|
|
209
|
+
type: "number"
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
sized.swc_vrt = {
|
|
214
|
+
skip: true
|
|
215
|
+
};
|
|
216
|
+
sized.parameters = {
|
|
217
|
+
// Disables Chromatic's snapshotting on a global level
|
|
218
|
+
chromatic: { disableSnapshot: true }
|
|
219
|
+
};
|
|
220
|
+
class MyParent extends SpectrumElement {
|
|
221
|
+
render() {
|
|
222
|
+
return html`
|
|
223
|
+
<div class="child"><slot></slot></div>
|
|
224
|
+
`;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
MyParent.styles = [
|
|
228
|
+
css`
|
|
229
|
+
:host {
|
|
230
|
+
display: block;
|
|
231
|
+
height: 100vh;
|
|
232
|
+
overflow: hidden;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.child {
|
|
236
|
+
height: 100%;
|
|
237
|
+
overflow: scroll;
|
|
238
|
+
}
|
|
239
|
+
`
|
|
240
|
+
];
|
|
241
|
+
customElements.define("my-parent", MyParent);
|
|
242
|
+
export const scrollParentInAssignedSlot = () => {
|
|
243
|
+
const items = generateItems(1e3);
|
|
244
|
+
return html`
|
|
245
|
+
<my-parent>
|
|
246
|
+
<sp-grid
|
|
247
|
+
.items=${items}
|
|
248
|
+
.focusableSelector=${"sp-card"}
|
|
249
|
+
.renderItem=${renderItem}
|
|
250
|
+
></sp-grid>
|
|
251
|
+
</my-parent>
|
|
252
|
+
`;
|
|
253
|
+
};
|
|
254
|
+
scrollParentInAssignedSlot.swc_vrt = {
|
|
255
|
+
skip: true
|
|
256
|
+
};
|
|
257
|
+
scrollParentInAssignedSlot.parameters = {
|
|
258
|
+
// Disables Chromatic's snapshotting on a global level
|
|
259
|
+
chromatic: { disableSnapshot: true }
|
|
260
|
+
};
|
|
261
|
+
//# sourceMappingURL=grid.stories.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["grid.stories.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n css,\n html,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\n\nimport '@spectrum-web-components/grid/sp-grid.js';\nimport '@spectrum-web-components/action-bar/sp-action-bar.js';\nimport '@spectrum-web-components/card/sp-card.js';\nimport '@spectrum-web-components/action-menu/sp-action-menu.js';\nimport '@spectrum-web-components/menu/sp-menu-item.js';\nimport '@spectrum-web-components/tooltip/sp-tooltip.js';\nimport '@spectrum-web-components/checkbox/sp-checkbox.js';\nimport '@spectrum-web-components/action-button/sp-action-button.js';\nimport '@spectrum-web-components/action-group/sp-action-group.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-edit.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-more.js';\nimport type { ActionBar } from '@spectrum-web-components/action-bar';\nimport type { Grid } from '@spectrum-web-components/grid';\n\nexport default {\n title: 'Grid',\n component: 'sp-grid',\n};\n\ninterface Item extends Record<string, unknown> {\n id: number;\n}\n\nfunction generateItems(count: number): Item[] {\n const items: Item[] = [];\n while (count) {\n count -= 1;\n items.unshift({ id: count });\n }\n return items;\n}\n\nconst renderItem = (\n item: Item,\n index: number,\n selected: boolean\n): TemplateResult => {\n return html`\n <sp-card\n toggles\n variant=\"quiet\"\n heading=\"Card Heading ${item.id}\"\n subheading=\"JPG Photo\"\n style=\"contain: strict; padding: 1px;\"\n value=\"card-${item.id}\"\n .selected=${selected}\n key=${index}\n draggable=\"true\"\n >\n <img\n alt=\"\"\n slot=\"preview\"\n src=\"https://picsum.photos/id/${item.id}/200/300\"\n decoding=\"async\"\n />\n <div slot=\"description\">10/15/18</div>\n <div slot=\"footer\">Footer</div>\n <sp-action-menu\n label=\"File actions\"\n slot=\"actions\"\n placement=\"bottom-end\"\n quiet\n tabindex=\"-1\"\n >\n <sp-tooltip slot=\"tooltip\" self-managed placement=\"top\">\n Do stuff\n </sp-tooltip>\n <sp-menu-item>Deselect</sp-menu-item>\n <sp-menu-item>Select Inverse</sp-menu-item>\n <sp-menu-item>Feather...</sp-menu-item>\n <sp-menu-item>Select and Mask...</sp-menu-item>\n <sp-menu-divider></sp-menu-divider>\n <sp-menu-item>Save Selection</sp-menu-item>\n <sp-menu-item disabled>Make Work Path</sp-menu-item>\n </sp-action-menu>\n </sp-card>\n `;\n};\n\nconst handleChange = (event: Event & { currentTarget: Grid }): void => {\n const actionbar = document.querySelector('sp-action-bar') as ActionBar;\n const selected = document.querySelector('.selected') as HTMLElement;\n const ids = document.querySelector('.ids') as HTMLElement;\n actionbar.open = !!event.currentTarget.selected.length;\n actionbar.style.setProperty(\n 'display',\n !!event.currentTarget.selected.length ? 'flex' : 'none'\n );\n selected.textContent = '' + event.currentTarget.selected.length;\n ids.textContent =\n '' +\n event.currentTarget.selected\n .map((selection) => selection.id)\n .join(', ');\n};\n\nconst handleActionBarChange = (event: Event): void => {\n event.preventDefault();\n const grid = document.querySelector('sp-grid') as Grid;\n const actionbar = document.querySelector('sp-action-bar') as ActionBar;\n actionbar.open = false;\n grid.selected = [];\n};\n\nexport const Default = (): TemplateResult => {\n const items = generateItems(1000);\n\n return html`\n <h1>Random before content that is focusable</h1>\n <input id=\"first-input\" />\n <sp-grid\n @change=${handleChange}\n .items=${items}\n .focusableSelector=${'sp-card'}\n .renderItem=${renderItem}\n ></sp-grid>\n <sp-action-bar variant=\"fixed\">\n <sp-checkbox @click=${handleActionBarChange} checked>\n <span class=\"selected\"></span>\n Selected\n <span class=\"ids\"></span>\n </sp-checkbox>\n <sp-action-group quiet>\n <sp-action-button>\n <sp-icon-edit slot=\"icon\" label=\"Edit\"></sp-icon-edit>\n </sp-action-button>\n <sp-action-button>\n <sp-icon-more slot=\"icon\" label=\"More\"></sp-icon-more>\n </sp-action-button>\n </sp-action-group>\n </sp-action-bar>\n <h2>Random after content that is focusable</h2>\n <input id=\"last-input\" />\n `;\n};\n\nDefault.swc_vrt = {\n skip: true,\n};\n\nDefault.parameters = {\n // Disables Chromatic's snapshotting on a global level\n chromatic: { disableSnapshot: true },\n};\n\nexport const sized = (\n { gap, padding } = { gap: 10, padding: 10 }\n): TemplateResult => {\n const items = generateItems(1000);\n\n function handleMediaChange(): void {\n let width = document.body.offsetWidth * 0.4;\n const height = 300;\n if (matchMedium.matches) {\n width = 300;\n } else if (matchLarge.matches) {\n width = 400;\n }\n (document.querySelector('sp-grid') as Grid).itemSize = {\n width,\n height,\n };\n }\n\n const matchSmall = window.matchMedia('(max-width: 600px)');\n const matchMedium = window.matchMedia(\n '(min-width: 601px) and (max-width: 1200px)'\n );\n const matchLarge = window.matchMedia('(min-width: 1201px)');\n\n matchSmall.addEventListener('change', handleMediaChange);\n matchMedium.addEventListener('change', handleMediaChange);\n matchLarge.addEventListener('change', handleMediaChange);\n\n return html`\n <h1>Random before content that is focusable</h1>\n <input id=\"first-input\" />\n <sp-grid\n @change=${handleChange}\n .items=${items}\n .focusableSelector=${'sp-card'}\n .renderItem=${renderItem}\n .itemSize=${{\n width: 200,\n height: 300,\n }}\n .gap=${`${gap}px`}\n .padding=${`${padding}px`}\n ></sp-grid>\n <sp-action-bar variant=\"fixed\" style=\"display: none\">\n <sp-checkbox @click=${handleActionBarChange} checked>\n <span class=\"selected\"></span>\n Selected\n <span class=\"ids\"></span>\n </sp-checkbox>\n <sp-action-group quiet>\n <sp-action-button>\n <sp-icon-edit slot=\"icon\" label=\"Edit\"></sp-icon-edit>\n </sp-action-button>\n <sp-action-button>\n <sp-icon-more slot=\"icon\" label=\"More\"></sp-icon-more>\n </sp-action-button>\n </sp-action-group>\n </sp-action-bar>\n <h2>Random after content that is focusable</h2>\n <input id=\"last-input\" />\n `;\n};\n\nsized.args = {\n gap: 10,\n padding: 10,\n};\n\nsized.argTypes = {\n gap: {\n name: 'gap',\n type: { name: 'number', required: false },\n description: 'Spacing between items.',\n table: {\n type: { summary: 'number' },\n },\n control: {\n type: 'number',\n },\n },\n padding: {\n name: 'padding',\n type: { name: 'number', required: false },\n description: 'Spacing around all items.',\n table: {\n type: { summary: 'number' },\n },\n control: {\n type: 'number',\n },\n },\n};\n\nsized.swc_vrt = {\n skip: true,\n};\n\nsized.parameters = {\n // Disables Chromatic's snapshotting on a global level\n chromatic: { disableSnapshot: true },\n};\n\nclass MyParent extends SpectrumElement {\n static override styles = [\n css`\n :host {\n display: block;\n height: 100vh;\n overflow: hidden;\n }\n\n .child {\n height: 100%;\n overflow: scroll;\n }\n `,\n ];\n\n override render(): TemplateResult {\n return html`\n <div class=\"child\"><slot></slot></div>\n `;\n }\n}\n\ncustomElements.define('my-parent', MyParent);\n\nexport const scrollParentInAssignedSlot = (): TemplateResult => {\n const items = generateItems(1000);\n\n return html`\n <my-parent>\n <sp-grid\n .items=${items}\n .focusableSelector=${'sp-card'}\n .renderItem=${renderItem}\n ></sp-grid>\n </my-parent>\n `;\n};\n\nscrollParentInAssignedSlot.swc_vrt = {\n skip: true,\n};\n\nscrollParentInAssignedSlot.parameters = {\n // Disables Chromatic's snapshotting on a global level\n chromatic: { disableSnapshot: true },\n};\n"],
|
|
5
|
+
"mappings": ";AAYA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OAEG;AAEP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AAIP,eAAe;AAAA,EACX,OAAO;AAAA,EACP,WAAW;AACf;AAMA,SAAS,cAAc,OAAuB;AAC1C,QAAM,QAAgB,CAAC;AACvB,SAAO,OAAO;AACV,aAAS;AACT,UAAM,QAAQ,EAAE,IAAI,MAAM,CAAC;AAAA,EAC/B;AACA,SAAO;AACX;AAEA,MAAM,aAAa,CACf,MACA,OACA,aACiB;AACjB,SAAO;AAAA;AAAA;AAAA;AAAA,oCAIyB,KAAK,EAAE;AAAA;AAAA;AAAA,0BAGjB,KAAK,EAAE;AAAA,wBACT,QAAQ;AAAA,kBACd,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gDAMyB,KAAK,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBvD;AAEA,M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;AAAA,IACV;AAAA,EACJ;AACJ;AAEA,MAAM,UAAU;AAAA,EACZ,MAAM;AACV;AAEA,MAAM,aAAa;AAAA;AAAA,EAEf,WAAW,EAAE,iBAAiB,KAAK;AACvC;AAEA,MAAM,iBAAiB,gBAAgB;AAAA,EAgB1B,SAAyB;AAC9B,WAAO;AAAA;AAAA;AAAA,EAGX;AACJ;AArBM,SACc,SAAS;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYJ;AASJ,eAAe,OAAO,aAAa,QAAQ;AAEpC,aAAM,6BAA6B,MAAsB;AAC5D,QAAM,QAAQ,cAAc,GAAI;AAEhC,SAAO;AAAA;AAAA;AAAA,yBAGc,KAAK;AAAA,qCACO,SAAS;AAAA,8BAChB,UAAU;AAAA;AAAA;AAAA;AAIxC;AAEA,2BAA2B,UAAU;AAAA,EACjC,MAAM;AACV;AAEA,2BAA2B,aAAa;AAAA;AAAA,EAEpC,WAAW,EAAE,iBAAiB,KAAK;AACvC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import "@spectrum-web-components/grid/sp-grid.js";
|
|
3
|
+
import { html } from "@spectrum-web-components/base";
|
|
4
|
+
import { measureFixtureCreation } from "../../../../test/benchmark/helpers.js";
|
|
5
|
+
measureFixtureCreation(html`
|
|
6
|
+
<sp-grid></sp-grid>
|
|
7
|
+
`);
|
|
8
|
+
//# sourceMappingURL=basic-test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["basic-test.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport '@spectrum-web-components/grid/sp-grid.js';\nimport { html } from '@spectrum-web-components/base';\nimport { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';\n\nmeasureFixtureCreation(html`\n <sp-grid></sp-grid>\n`);\n"],
|
|
5
|
+
"mappings": ";AAYA,OAAO;AACP,SAAS,YAAY;AACrB,SAAS,8BAA8B;AAEvC,uBAAuB;AAAA;AAAA,CAEtB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["grid-memory.test.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2023 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Default } from '../stories/grid.stories.js';\nimport { testForMemoryLeaks } from '../../../test/testing-helpers.js';\n\ntestForMemoryLeaks(Default());\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,eAAe;AACxB,SAAS,0BAA0B;AAEnC,mBAAmB,QAAQ,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["grid.test-vrt.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport * as stories from '../stories/grid.stories.js';\nimport { regressVisuals } from '../../../test/visual/test.js';\nimport type { TestsType } from '../../../test/visual/test.js';\n\nregressVisuals('GridStories', stories as unknown as TestsType);\n"],
|
|
5
|
+
"mappings": ";AAYA,YAAY,aAAa;AACzB,SAAS,sBAAsB;AAG/B,eAAe,eAAe,OAA+B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { elementUpdated, expect, fixture, nextFrame } from "@open-wc/testing";
|
|
3
|
+
import { html } from "@spectrum-web-components/base";
|
|
4
|
+
import "@spectrum-web-components/theme/sp-theme.js";
|
|
5
|
+
import "@spectrum-web-components/theme/scale-medium.js";
|
|
6
|
+
import "@spectrum-web-components/theme/theme-light.js";
|
|
7
|
+
import "@spectrum-web-components/grid/sp-grid.js";
|
|
8
|
+
import { Default } from "../stories/grid.stories.js";
|
|
9
|
+
import { sendKeys, sendMouse } from "@web/test-runner-commands";
|
|
10
|
+
import { testForLitDevWarnings } from "../../../test/testing-helpers.js";
|
|
11
|
+
import { isWebKit } from "@spectrum-web-components/shared";
|
|
12
|
+
describe("Grid", () => {
|
|
13
|
+
testForLitDevWarnings(
|
|
14
|
+
async () => await fixture(html`
|
|
15
|
+
<div>${Default()}</div>
|
|
16
|
+
`)
|
|
17
|
+
);
|
|
18
|
+
it("loads default grid accessibly", async () => {
|
|
19
|
+
const test = await fixture(html`
|
|
20
|
+
<div>${Default()}</div>
|
|
21
|
+
`);
|
|
22
|
+
const el = test.querySelector("sp-grid");
|
|
23
|
+
await elementUpdated(el);
|
|
24
|
+
await expect(el).to.be.accessible();
|
|
25
|
+
});
|
|
26
|
+
it("accepts focus", async () => {
|
|
27
|
+
const test = await fixture(html`
|
|
28
|
+
<div>${Default()}</div>
|
|
29
|
+
`);
|
|
30
|
+
const el = test.querySelector("sp-grid");
|
|
31
|
+
await elementUpdated(el);
|
|
32
|
+
expect(el.tabIndex).to.equal(0);
|
|
33
|
+
await sendKeys({ press: "Tab" });
|
|
34
|
+
await sendKeys({ press: "Tab" });
|
|
35
|
+
await nextFrame();
|
|
36
|
+
await nextFrame();
|
|
37
|
+
if (!isWebKit()) {
|
|
38
|
+
sendMouse({
|
|
39
|
+
type: "click",
|
|
40
|
+
position: [0, 0]
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
expect(
|
|
44
|
+
el.querySelector(el.focusableSelector) === document.activeElement
|
|
45
|
+
).to.be.true;
|
|
46
|
+
});
|
|
47
|
+
it("does not focus when clicking grid", async () => {
|
|
48
|
+
const test = await fixture(html`
|
|
49
|
+
<sp-theme color="light" scale="medium">${Default()}</sp-theme>
|
|
50
|
+
`);
|
|
51
|
+
const el = test.querySelector("sp-grid");
|
|
52
|
+
await elementUpdated(el);
|
|
53
|
+
expect(el.tabIndex).to.equal(0);
|
|
54
|
+
await sendKeys({ press: "Tab" });
|
|
55
|
+
await sendKeys({ press: "Tab" });
|
|
56
|
+
await nextFrame();
|
|
57
|
+
await nextFrame();
|
|
58
|
+
const firstItem = el.querySelector(el.focusableSelector);
|
|
59
|
+
expect(firstItem === document.activeElement).to.be.true;
|
|
60
|
+
const firstRect = firstItem == null ? void 0 : firstItem.getBoundingClientRect();
|
|
61
|
+
const position = [
|
|
62
|
+
Math.round(firstRect.x + firstRect.width + 2),
|
|
63
|
+
Math.round(firstRect.y + 2)
|
|
64
|
+
];
|
|
65
|
+
await sendMouse({
|
|
66
|
+
type: "click",
|
|
67
|
+
position
|
|
68
|
+
});
|
|
69
|
+
await nextFrame();
|
|
70
|
+
await nextFrame();
|
|
71
|
+
expect(
|
|
72
|
+
el.querySelector(el.focusableSelector) === document.activeElement
|
|
73
|
+
).to.be.false;
|
|
74
|
+
});
|
|
75
|
+
it("allows to tab in and out", async () => {
|
|
76
|
+
const test = await fixture(html`
|
|
77
|
+
<div>${Default()}</div>
|
|
78
|
+
`);
|
|
79
|
+
const el = test.querySelector("sp-grid");
|
|
80
|
+
const firstInput = test.querySelector("#first-input");
|
|
81
|
+
const lastInput = test.querySelector("#last-input");
|
|
82
|
+
await elementUpdated(el);
|
|
83
|
+
expect(el.tabIndex).to.equal(0);
|
|
84
|
+
firstInput.focus();
|
|
85
|
+
expect(firstInput === document.activeElement).to.be.true;
|
|
86
|
+
expect(el.tabIndex).to.equal(0);
|
|
87
|
+
await sendKeys({
|
|
88
|
+
press: "Tab"
|
|
89
|
+
});
|
|
90
|
+
await nextFrame();
|
|
91
|
+
await nextFrame();
|
|
92
|
+
expect(
|
|
93
|
+
el.querySelector(el.focusableSelector) === document.activeElement
|
|
94
|
+
).to.be.true;
|
|
95
|
+
expect(el.tabIndex).to.equal(-1);
|
|
96
|
+
await sendKeys({
|
|
97
|
+
press: "Tab"
|
|
98
|
+
});
|
|
99
|
+
await nextFrame();
|
|
100
|
+
await nextFrame();
|
|
101
|
+
await elementUpdated(el);
|
|
102
|
+
expect(lastInput === document.activeElement).to.be.true;
|
|
103
|
+
expect(el.tabIndex).to.equal(0);
|
|
104
|
+
await sendKeys({
|
|
105
|
+
press: "Shift+Tab"
|
|
106
|
+
});
|
|
107
|
+
await nextFrame();
|
|
108
|
+
await nextFrame();
|
|
109
|
+
await nextFrame();
|
|
110
|
+
await nextFrame();
|
|
111
|
+
expect(
|
|
112
|
+
el.querySelector(el.focusableSelector) === document.activeElement
|
|
113
|
+
).to.be.true;
|
|
114
|
+
expect(el.tabIndex).to.equal(-1);
|
|
115
|
+
});
|
|
116
|
+
it("manages roving tabindex", async () => {
|
|
117
|
+
const test = await fixture(html`
|
|
118
|
+
<div>${Default()}</div>
|
|
119
|
+
`);
|
|
120
|
+
const el = test.querySelector("sp-grid");
|
|
121
|
+
await elementUpdated(el);
|
|
122
|
+
expect(el.tabIndex).to.equal(0);
|
|
123
|
+
el.focus();
|
|
124
|
+
await nextFrame();
|
|
125
|
+
await nextFrame();
|
|
126
|
+
let focused = el.querySelector(el.focusableSelector);
|
|
127
|
+
await elementUpdated(focused);
|
|
128
|
+
expect(focused === document.activeElement).to.be.true;
|
|
129
|
+
expect(focused.focused).to.be.true;
|
|
130
|
+
await sendKeys({
|
|
131
|
+
press: "ArrowRight"
|
|
132
|
+
});
|
|
133
|
+
focused = el.querySelector(
|
|
134
|
+
`${el.focusableSelector}:nth-child(2)`
|
|
135
|
+
);
|
|
136
|
+
await elementUpdated(focused);
|
|
137
|
+
expect(focused === document.activeElement).to.be.true;
|
|
138
|
+
expect(focused.focused).to.be.true;
|
|
139
|
+
await sendKeys({
|
|
140
|
+
press: "ArrowDown"
|
|
141
|
+
});
|
|
142
|
+
focused = el.querySelector(
|
|
143
|
+
`${el.focusableSelector}:nth-child(5)`
|
|
144
|
+
);
|
|
145
|
+
await elementUpdated(focused);
|
|
146
|
+
expect(focused === document.activeElement).to.be.true;
|
|
147
|
+
expect(focused.focused).to.be.true;
|
|
148
|
+
await sendKeys({
|
|
149
|
+
press: "ArrowLeft"
|
|
150
|
+
});
|
|
151
|
+
focused = el.querySelector(
|
|
152
|
+
`${el.focusableSelector}:nth-child(4)`
|
|
153
|
+
);
|
|
154
|
+
await elementUpdated(focused);
|
|
155
|
+
expect(focused === document.activeElement).to.be.true;
|
|
156
|
+
expect(focused.focused).to.be.true;
|
|
157
|
+
await sendKeys({
|
|
158
|
+
press: "ArrowUp"
|
|
159
|
+
});
|
|
160
|
+
focused = el.querySelector(`${el.focusableSelector}`);
|
|
161
|
+
await elementUpdated(focused);
|
|
162
|
+
expect(focused === document.activeElement).to.be.true;
|
|
163
|
+
expect(focused.focused).to.be.true;
|
|
164
|
+
});
|
|
165
|
+
it("manages selection", async () => {
|
|
166
|
+
const test = await fixture(html`
|
|
167
|
+
<div>${Default()}</div>
|
|
168
|
+
`);
|
|
169
|
+
const el = test.querySelector("sp-grid");
|
|
170
|
+
await elementUpdated(el);
|
|
171
|
+
expect(el.tabIndex).to.equal(0);
|
|
172
|
+
el.focus();
|
|
173
|
+
await nextFrame();
|
|
174
|
+
await nextFrame();
|
|
175
|
+
let focused = el.querySelector(el.focusableSelector);
|
|
176
|
+
await elementUpdated(focused);
|
|
177
|
+
expect(focused === document.activeElement).to.be.true;
|
|
178
|
+
expect(focused.focused).to.be.true;
|
|
179
|
+
await sendKeys({
|
|
180
|
+
press: "ArrowRight"
|
|
181
|
+
});
|
|
182
|
+
focused = el.querySelector(
|
|
183
|
+
`${el.focusableSelector}:nth-child(2)`
|
|
184
|
+
);
|
|
185
|
+
await elementUpdated(focused);
|
|
186
|
+
expect(focused === document.activeElement).to.be.true;
|
|
187
|
+
expect(focused.focused).to.be.true;
|
|
188
|
+
await sendKeys({
|
|
189
|
+
press: "Space"
|
|
190
|
+
});
|
|
191
|
+
await elementUpdated(el);
|
|
192
|
+
expect(el.selected).to.deep.equal([{ id: 1 }]);
|
|
193
|
+
await sendKeys({
|
|
194
|
+
press: "ArrowDown"
|
|
195
|
+
});
|
|
196
|
+
focused = el.querySelector(
|
|
197
|
+
`${el.focusableSelector}:nth-child(5)`
|
|
198
|
+
);
|
|
199
|
+
await elementUpdated(focused);
|
|
200
|
+
expect(focused === document.activeElement).to.be.true;
|
|
201
|
+
expect(focused.focused).to.be.true;
|
|
202
|
+
await sendKeys({
|
|
203
|
+
press: "Space"
|
|
204
|
+
});
|
|
205
|
+
await elementUpdated(el);
|
|
206
|
+
expect(el.selected).to.deep.equal([{ id: 1 }, { id: 4 }]);
|
|
207
|
+
await sendKeys({
|
|
208
|
+
press: "ArrowUp"
|
|
209
|
+
});
|
|
210
|
+
focused = el.querySelector(
|
|
211
|
+
`${el.focusableSelector}:nth-child(2)`
|
|
212
|
+
);
|
|
213
|
+
await elementUpdated(focused);
|
|
214
|
+
expect(focused === document.activeElement).to.be.true;
|
|
215
|
+
expect(focused.focused).to.be.true;
|
|
216
|
+
await sendKeys({
|
|
217
|
+
press: "Space"
|
|
218
|
+
});
|
|
219
|
+
await elementUpdated(el);
|
|
220
|
+
expect(el.selected).to.deep.equal([{ id: 4 }]);
|
|
221
|
+
});
|
|
222
|
+
it("does not claim lit-virtualizer on the global registry", async () => {
|
|
223
|
+
const test = await fixture(html`
|
|
224
|
+
<div>${Default()}</div>
|
|
225
|
+
`);
|
|
226
|
+
const el = test.querySelector("sp-grid");
|
|
227
|
+
await elementUpdated(el);
|
|
228
|
+
customElements.define("lit-virtualizer", class extends HTMLElement {
|
|
229
|
+
});
|
|
230
|
+
expect(() => {
|
|
231
|
+
customElements.define(
|
|
232
|
+
"lit-virtualizer",
|
|
233
|
+
class extends HTMLElement {
|
|
234
|
+
}
|
|
235
|
+
);
|
|
236
|
+
}).to.throw();
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
//# sourceMappingURL=grid.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["grid.test.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { elementUpdated, expect, fixture, nextFrame } from '@open-wc/testing';\nimport { html } from '@spectrum-web-components/base';\nimport { Card } from '@spectrum-web-components/card';\n\nimport '@spectrum-web-components/theme/sp-theme.js';\nimport '@spectrum-web-components/theme/scale-medium.js';\nimport '@spectrum-web-components/theme/theme-light.js';\nimport '@spectrum-web-components/grid/sp-grid.js';\nimport { Grid } from '@spectrum-web-components/grid';\nimport { Default } from '../stories/grid.stories.js';\nimport { sendKeys, sendMouse } from '@web/test-runner-commands';\nimport { testForLitDevWarnings } from '../../../test/testing-helpers.js';\nimport { isWebKit } from '@spectrum-web-components/shared';\n\ndescribe('Grid', () => {\n testForLitDevWarnings(\n async () =>\n await fixture<HTMLDivElement>(html`\n <div>${Default()}</div>\n `)\n );\n it('loads default grid accessibly', async () => {\n const test = await fixture<HTMLDivElement>(html`\n <div>${Default()}</div>\n `);\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n await expect(el).to.be.accessible();\n });\n it('accepts focus', async () => {\n const test = await fixture<HTMLDivElement>(html`\n <div>${Default()}</div>\n `);\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n expect(el.tabIndex).to.equal(0);\n\n await sendKeys({ press: 'Tab' });\n await sendKeys({ press: 'Tab' });\n\n await nextFrame();\n await nextFrame();\n\n if (!isWebKit()) {\n sendMouse({\n type: 'click',\n position: [0, 0],\n });\n }\n\n expect(\n el.querySelector(el.focusableSelector) === document.activeElement\n ).to.be.true;\n });\n it('does not focus when clicking grid', async () => {\n const test = await fixture<HTMLDivElement>(html`\n <sp-theme color=\"light\" scale=\"medium\">${Default()}</sp-theme>\n `);\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n expect(el.tabIndex).to.equal(0);\n\n await sendKeys({ press: 'Tab' });\n await sendKeys({ press: 'Tab' });\n\n await nextFrame();\n await nextFrame();\n\n const firstItem = el.querySelector(el.focusableSelector) as HTMLElement;\n\n expect(firstItem === document.activeElement).to.be.true;\n\n const firstRect = firstItem?.getBoundingClientRect();\n const position = [\n Math.round(firstRect.x + firstRect.width + 2),\n Math.round(firstRect.y + 2),\n ] as [number, number];\n await sendMouse({\n type: 'click',\n position,\n });\n\n await nextFrame();\n await nextFrame();\n\n expect(\n el.querySelector(el.focusableSelector) === document.activeElement\n ).to.be.false;\n });\n it('allows to tab in and out', async () => {\n const test = await fixture<HTMLDivElement>(html`\n <div>${Default()}</div>\n `);\n const el = test.querySelector('sp-grid') as Grid;\n const firstInput = test.querySelector('#first-input') as HTMLElement;\n const lastInput = test.querySelector('#last-input') as HTMLElement;\n\n await elementUpdated(el);\n\n expect(el.tabIndex).to.equal(0);\n\n firstInput.focus();\n expect(firstInput === document.activeElement).to.be.true;\n expect(el.tabIndex).to.equal(0);\n\n await sendKeys({\n press: 'Tab',\n });\n\n await nextFrame();\n await nextFrame();\n\n expect(\n el.querySelector(el.focusableSelector) === document.activeElement\n ).to.be.true;\n expect(el.tabIndex).to.equal(-1);\n\n await sendKeys({\n press: 'Tab',\n });\n\n await nextFrame();\n await nextFrame();\n\n await elementUpdated(el);\n expect(lastInput === document.activeElement).to.be.true;\n expect(el.tabIndex).to.equal(0);\n\n await sendKeys({\n press: 'Shift+Tab',\n });\n\n await nextFrame();\n await nextFrame();\n await nextFrame();\n await nextFrame();\n\n expect(\n el.querySelector(el.focusableSelector) === document.activeElement\n ).to.be.true;\n expect(el.tabIndex).to.equal(-1);\n });\n it('manages roving tabindex', async () => {\n const test = await fixture<HTMLDivElement>(html`\n <div>${Default()}</div>\n `);\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n expect(el.tabIndex).to.equal(0);\n\n el.focus();\n\n await nextFrame();\n await nextFrame();\n\n let focused = el.querySelector(el.focusableSelector) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'ArrowRight',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(2)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'ArrowDown',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(5)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'ArrowLeft',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(4)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'ArrowUp',\n });\n\n focused = el.querySelector(`${el.focusableSelector}`) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n });\n it('manages selection', async () => {\n const test = await fixture<HTMLDivElement>(html`\n <div>${Default()}</div>\n `);\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n expect(el.tabIndex).to.equal(0);\n\n el.focus();\n\n await nextFrame();\n await nextFrame();\n\n let focused = el.querySelector(el.focusableSelector) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'ArrowRight',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(2)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'Space',\n });\n\n await elementUpdated(el);\n\n expect(el.selected).to.deep.equal([{ id: 1 }]);\n\n await sendKeys({\n press: 'ArrowDown',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(5)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'Space',\n });\n\n await elementUpdated(el);\n\n expect(el.selected).to.deep.equal([{ id: 1 }, { id: 4 }]);\n\n await sendKeys({\n press: 'ArrowUp',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(2)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'Space',\n });\n\n await elementUpdated(el);\n\n expect(el.selected).to.deep.equal([{ id: 4 }]);\n });\n it('does not claim lit-virtualizer on the global registry', async () => {\n const test = await fixture<HTMLDivElement>(html`\n <div>${Default()}</div>\n `);\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n customElements.define('lit-virtualizer', class extends HTMLElement {});\n\n // make sure we also don't prevent *any* registration of lit-virtualizer\n expect(() => {\n customElements.define(\n 'lit-virtualizer',\n class extends HTMLElement {}\n );\n }).to.throw();\n });\n});\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,gBAAgB,QAAQ,SAAS,iBAAiB;AAC3D,SAAS,YAAY;AAGrB,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AAEP,SAAS,eAAe;AACxB,SAAS,UAAU,iBAAiB;AACpC,SAAS,6BAA6B;AACtC,SAAS,gBAAgB;AAEzB,SAAS,QAAQ,MAAM;AACnB;AAAA,IACI,YACI,MAAM,QAAwB;AAAA,uBACnB,QAAQ,CAAC;AAAA,aACnB;AAAA,EACT;AACA,KAAG,iCAAiC,YAAY;AAC5C,UAAM,OAAO,MAAM,QAAwB;AAAA,mBAChC,QAAQ,CAAC;AAAA,SACnB;AACD,UAAM,KAAK,KAAK,cAAc,SAAS;AAEvC,UAAM,eAAe,EAAE;AAEvB,UAAM,OAAO,EAAE,EAAE,GAAG,GAAG,WAAW;AAAA,EACtC,CAAC;AACD,KAAG,iBAAiB,YAAY;AAC5B,UAAM,OAAO,MAAM,QAAwB;AAAA,mBAChC,QAAQ,CAAC;AAAA,SACnB;AACD,UAAM,KAAK,KAAK,cAAc,SAAS;AAEvC,UAAM,eAAe,EAAE;AAEvB,WAAO,GAAG,QAAQ,EAAE,GAAG,MAAM,CAAC;AAE9B,UAAM,SAAS,EAAE,OAAO,MAAM,CAAC;AAC/B,UAAM,SAAS,EAAE,OAAO,MAAM,CAAC;AAE/B,UAAM,UAAU;AAChB,UAAM,UAAU;AAEhB,QAAI,CAAC,SAAS,GAAG;AACb,gBAAU;AAAA,Q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