@spectrum-web-components/grid 0.0.3 → 0.0.5
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/custom-elements.json +2 -2
- package/package.json +4 -4
- package/src/Grid.d.ts +1 -1
- package/src/Grid.js +1 -1
- package/src/Grid.js.map +1 -1
- package/src/GridController.d.ts +3 -4
- package/src/GridController.js.map +1 -1
- package/src/grid.css.js +1 -1
- package/src/grid.css.js.map +1 -1
- package/test/benchmark/basic-test.js +18 -0
- package/test/benchmark/basic-test.js.map +1 -0
- package/test/grid.test.js +184 -0
- package/test/grid.test.js.map +1 -0
package/custom-elements.json
CHANGED
|
@@ -155,7 +155,7 @@
|
|
|
155
155
|
],
|
|
156
156
|
"superclass": {
|
|
157
157
|
"name": "LitVirtualizer",
|
|
158
|
-
"package": "@lit-labs/virtualizer"
|
|
158
|
+
"package": "@lit-labs/virtualizer/LitVirtualizer.js"
|
|
159
159
|
},
|
|
160
160
|
"tagName": "sp-grid",
|
|
161
161
|
"customElement": true
|
|
@@ -185,7 +185,7 @@
|
|
|
185
185
|
"kind": "field",
|
|
186
186
|
"name": "host",
|
|
187
187
|
"type": {
|
|
188
|
-
"text": "
|
|
188
|
+
"text": "ReactiveElement"
|
|
189
189
|
},
|
|
190
190
|
"default": "host"
|
|
191
191
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/grid",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@lit-labs/observers": "^1.0.1",
|
|
48
|
-
"@lit-labs/virtualizer": "0.7.0-pre.
|
|
49
|
-
"@spectrum-web-components/base": "^0.5.
|
|
48
|
+
"@lit-labs/virtualizer": "0.7.0-pre.3",
|
|
49
|
+
"@spectrum-web-components/base": "^0.5.5",
|
|
50
50
|
"@spectrum-web-components/reactive-controllers": "^0.2.2",
|
|
51
51
|
"tslib": "^2.0.0"
|
|
52
52
|
},
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"sideEffects": [
|
|
56
56
|
"./sp-*.js"
|
|
57
57
|
],
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "bdff893e2b95aba7737c58d01c6ac68861cb8b2e"
|
|
59
59
|
}
|
package/src/Grid.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CSSResultArray, PropertyValues, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
-
import { LitVirtualizer } from '@lit-labs/virtualizer';
|
|
2
|
+
import { LitVirtualizer } from '@lit-labs/virtualizer/LitVirtualizer.js';
|
|
3
3
|
import { GridController } from './GridController.js';
|
|
4
4
|
/**
|
|
5
5
|
* @element sp-grid
|
package/src/Grid.js
CHANGED
|
@@ -11,7 +11,7 @@ governing permissions and limitations under the License.
|
|
|
11
11
|
*/
|
|
12
12
|
import { __decorate } from "tslib";
|
|
13
13
|
import { property } from '@spectrum-web-components/base/src/decorators.js';
|
|
14
|
-
import { LitVirtualizer } from '@lit-labs/virtualizer';
|
|
14
|
+
import { LitVirtualizer } from '@lit-labs/virtualizer/LitVirtualizer.js';
|
|
15
15
|
import { grid } from '@lit-labs/virtualizer/layouts/grid.js';
|
|
16
16
|
import styles from './grid.css.js';
|
|
17
17
|
import { GridController } from './GridController.js';
|
package/src/Grid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Grid.js","sourceRoot":"","sources":["Grid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAOF,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Grid.js","sourceRoot":"","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IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI;oBACjC,MAAM,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI;iBACtC;gBACD,GAAG,EAAE,IAAI,CAAC,GAAG;aAChB,CAAC,CAAC;SACN;QAED,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;IAED,iBAAiB;QACb,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,oBAAoB;QAChB,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,EAAE;YAClD,OAAO,EAAE,IAAI;SAChB,CAAC,CAAC;QACH,KAAK,CAAC,oBAAoB,EAAE,CAAC;IACjC,CAAC;CACJ;AAtGG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+CACO;AAGlC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iCACgB;AAG3C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;mCACmB;AAG7C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sCAOzB;AAoBF;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;sCACsB","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 CSSResultArray,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { LitVirtualizer } from '@lit-labs/virtualizer/LitVirtualizer.js';\nimport { grid } from '@lit-labs/virtualizer/layouts/grid.js';\nimport styles from './grid.css.js';\nimport { GridController } from './GridController.js';\n\n/**\n * @element sp-grid\n *\n * @fires change - Announces that the value of `selected` has changed\n */\nexport class Grid extends LitVirtualizer {\n public static get styles(): CSSResultArray {\n return [styles];\n }\n\n @property({ type: String })\n public focusableSelector!: string;\n\n @property({ type: String })\n public gap: `${'0' | `${number}px`}` = '0';\n\n @property({ type: Array })\n public items: Record<string, unknown>[] = [];\n\n @property({ type: Object })\n public itemSize: {\n width: number;\n height: number;\n } = {\n width: 200,\n height: 200,\n };\n\n /* c8 ignore next 3 */\n get renderItem(): (item: unknown, index: number) => TemplateResult {\n return super.renderItem;\n }\n\n set renderItem(\n fn: (item: unknown, index: number, selected: boolean) => TemplateResult\n ) {\n super.renderItem = (\n item: Record<string, unknown>,\n index: number\n ): TemplateResult => {\n const selected = this.selected.includes(item);\n return fn(item, index, selected);\n };\n }\n\n @property({ type: Array })\n public selected: Record<string, unknown>[] = [];\n\n gridController = new GridController<HTMLElement>(this, {\n elements: () => [],\n itemSize: () => this.itemSize,\n /* c8 ignore next 1 */\n gap: () => this.gap,\n });\n\n protected handleChange(event: Event): void {\n const target = event.target as HTMLElement;\n const value = this.items[\n parseFloat(target.getAttribute('key') || '')\n ] as Record<string, unknown>;\n const selected: Record<string, unknown>[] = [...this.selected];\n if (!selected.includes(value)) {\n selected.push(value);\n } else {\n const index = selected.indexOf(value);\n if (index > -1) {\n selected.splice(index, 1);\n }\n }\n this.selected = selected;\n }\n\n protected update(changes: PropertyValues<this>): void {\n if (\n changes.has('itemSize') ||\n changes.has('gap') ||\n changes.has('focusableSelector')\n ) {\n this.updateComplete.then(() => {\n this.gridController.update({\n elements: () => [\n ...this.querySelectorAll<HTMLElement>(\n this.focusableSelector\n ),\n ],\n itemSize: () => this.itemSize,\n gap: () => this.gap,\n });\n });\n\n this.layout = grid({\n itemSize: {\n width: `${this.itemSize.width}px`,\n height: `${this.itemSize.height}px`,\n },\n gap: this.gap,\n });\n }\n\n super.update(changes);\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n this.addEventListener('change', this.handleChange, { capture: true });\n }\n\n disconnectedCallback(): void {\n this.removeEventListener('change', this.handleChange, {\n capture: true,\n });\n super.disconnectedCallback();\n }\n}\n"]}
|
package/src/GridController.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import type { ReactiveController } from 'lit';
|
|
1
|
+
import type { ReactiveController, ReactiveElement } from 'lit';
|
|
2
2
|
import { ResizeController } from '@lit-labs/observers/resize_controller.js';
|
|
3
3
|
import { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';
|
|
4
4
|
import { RangeChangedEvent, VisibilityChangedEvent } from '@lit-labs/virtualizer/Virtualizer.js';
|
|
5
|
-
import type { LitVirtualizer } from '@lit-labs/virtualizer';
|
|
6
5
|
interface ItemSize {
|
|
7
6
|
width: number;
|
|
8
7
|
height: number;
|
|
9
8
|
}
|
|
10
9
|
export declare class GridController<T extends HTMLElement> implements ReactiveController {
|
|
11
|
-
host:
|
|
10
|
+
host: ReactiveElement;
|
|
12
11
|
resizeController: ResizeController;
|
|
13
12
|
rovingTabindexController: RovingTabindexController<T>;
|
|
14
13
|
get itemSize(): ItemSize;
|
|
@@ -17,7 +16,7 @@ export declare class GridController<T extends HTMLElement> implements ReactiveCo
|
|
|
17
16
|
get gap(): string | undefined;
|
|
18
17
|
private _gap;
|
|
19
18
|
_last: number;
|
|
20
|
-
constructor(host:
|
|
19
|
+
constructor(host: ReactiveElement, { elements, itemSize, gap, }: {
|
|
21
20
|
elements: () => T[];
|
|
22
21
|
itemSize: ItemSize | (() => ItemSize);
|
|
23
22
|
gap?: string | (() => string);
|
|
@@ -1 +1 @@
|
|
|
1
|
-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B,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC7D,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;IACnE,CAAC;CACJ","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*/\nimport type { ReactiveController } from 'lit';\n\nimport { ResizeController } from '@lit-labs/observers/resize_controller.js';\nimport { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';\nimport {\n RangeChangedEvent,\n VisibilityChangedEvent,\n} from '@lit-labs/virtualizer/Virtualizer.js';\nimport type { LitVirtualizer } from '@lit-labs/virtualizer';\n\ninterface ItemSize {\n width: number;\n height: number;\n}\n\nexport class GridController<T extends HTMLElement>\n implements ReactiveController\n{\n host!: LitVirtualizer;\n\n resizeController!: ResizeController;\n\n rovingTabindexController!: RovingTabindexController<T>;\n\n get itemSize(): ItemSize {\n return this._itemSize();\n }\n\n /* c8 ignore next 6 */\n private _itemSize(): ItemSize {\n return {\n width: 100,\n height: 100,\n };\n }\n\n // First visible element\n _first = 0;\n\n get gap(): string | undefined {\n return this._gap();\n }\n\n /* c8 ignore next 3 */\n private _gap(): string | undefined {\n return undefined;\n }\n\n // Last visible element\n _last = 0;\n\n constructor(\n host: LitVirtualizer,\n {\n elements,\n itemSize,\n gap,\n }: {\n elements: () => T[];\n itemSize: ItemSize | (() => ItemSize);\n gap?: string | (() => string);\n }\n ) {\n this.host = host;\n this.host.addController(this);\n this.applyLayout(itemSize, gap);\n this.resizeController = new ResizeController(this.host, {\n callback: (entries: ResizeObserverEntry[]): void => {\n entries.forEach((entry) => {\n this.measureDirectionLength(entry.contentRect);\n });\n },\n });\n this.rovingTabindexController = new RovingTabindexController<T>(\n this.host,\n {\n direction: 'grid',\n elements,\n focusInIndex: () => {\n const activeElement = (this.host.getRootNode() as Document)\n .activeElement as HTMLElement;\n return activeElement === this.host ? 0 : -1;\n },\n }\n );\n }\n\n public focus(options?: FocusOptions): void {\n this.rovingTabindexController.focus(options);\n }\n\n protected applyLayout(\n itemSize: ItemSize | (() => ItemSize),\n gap?: string | (() => string)\n ): void {\n /* c8 ignore next 2 */\n if (typeof itemSize === 'object') {\n this._itemSize = () => itemSize;\n } else if (\n typeof itemSize === 'function' &&\n typeof itemSize() !== 'undefined'\n ) {\n this._itemSize = itemSize;\n }\n /* c8 ignore next 2 */\n if (typeof gap === 'string') {\n this._gap = () => gap;\n } else if (typeof gap === 'function') {\n this._gap = gap;\n }\n }\n\n public update({\n elements,\n itemSize,\n gap,\n }: {\n elements: () => T[];\n itemSize: ItemSize | (() => ItemSize);\n gap?: string | (() => string);\n }): void {\n this.rovingTabindexController.update({ elements });\n this.applyLayout(itemSize, gap);\n const contentRect = this.host.getBoundingClientRect();\n this.measureDirectionLength(contentRect);\n }\n\n protected measureDirectionLength(contentRect: DOMRect): void {\n const gap = this.gap ? parseFloat(this.gap) : 0;\n this.rovingTabindexController.directionLength = Math.floor(\n (contentRect.width - gap) / (this.itemSize.width + gap)\n );\n }\n\n protected handleFocusin = (event: FocusEvent): void => {\n const doCallbackAfterPaint = (cb: () => void): void => {\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n cb();\n });\n });\n };\n const scrollToFirst = (): void => this.host.scrollToIndex(0);\n const focusIntoGrid = (): void => {\n this.focus();\n this.host.tabIndex = -1;\n };\n if ((event.target as HTMLElement) === this.host) {\n if (this._first > 0) {\n doCallbackAfterPaint(() => {\n scrollToFirst();\n doCallbackAfterPaint(focusIntoGrid);\n });\n } else {\n doCallbackAfterPaint(focusIntoGrid);\n }\n }\n };\n\n protected handleFocusout = (event: FocusEvent): void => {\n if (\n event.relatedTarget &&\n !this.host.contains(event.relatedTarget as HTMLElement)\n ) {\n this.host.tabIndex = 0;\n }\n };\n\n protected handleRangeChanged = (event: RangeChangedEvent): void => {\n this.rovingTabindexController.clearElementCache(event.first);\n };\n\n protected handleVisibleChanged = (event: VisibilityChangedEvent): void => {\n this._first = event.first;\n this._last = event.last;\n };\n\n public hostConnected(): void {\n this.host.addEventListener('rangeChanged', this.handleRangeChanged);\n this.host.addEventListener(\n 'visibilityChanged',\n this.handleVisibleChanged\n );\n this.host.addEventListener('focusin', this.handleFocusin);\n this.host.addEventListener('focusout', this.handleFocusout);\n this.host.tabIndex = 0;\n this.host.style.setProperty('outline', 'none', 'important');\n }\n\n public hostDisconnected(): void {\n this.host.removeEventListener('rangeChanged', this.handleRangeChanged);\n this.host.removeEventListener(\n 'visibilityChanged',\n this.handleVisibleChanged\n );\n this.host.removeEventListener('focusin', this.handleFocusin);\n this.host.removeEventListener('focusout', this.handleFocusout);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"GridController.js","sourceRoot":"","sources":["GridController.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,qEAAqE,CAAC;AAW/G,MAAM,OAAO,cAAc;IAoCvB,YACI,IAAqB,EACrB,EACI,QAAQ,EACR,QAAQ,EACR,GAAG,GAKN;QAzBL,wBAAwB;QACxB,WAAM,GAAG,CAAC,CAAC;QAWX,uBAAuB;QACvB,UAAK,GAAG,CAAC,CAAC;QAqFA,kBAAa,GAAG,CAAC,KAAiB,EAAQ,EAAE;YAClD,MAAM,oBAAoB,GAAG,CAAC,EAAc,EAAQ,EAAE;gBAClD,qBAAqB,CAAC,GAAG,EAAE;oBACvB,qBAAqB,CAAC,GAAG,EAAE;wBACvB,EAAE,EAAE,CAAC;oBACT,CAAC,CAAC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CAAC,CAAC;QACpE,IAAI,CAAC,IAAI,CAAC,gBAAgB,CACtB,mBAAmB,EACnB,IAAI,CAAC,oBAAoB,CAC5B,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IAChE,CAAC;IAEM,gBAAgB;QACnB,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,cAAc,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACvE,IAAI,CAAC,IAAI,CAAC,mBAAmB,CACzB,mBAAmB,EACnB,IAAI,CAAC,oBAAoB,CAC5B,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC7D,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;IACnE,CAAC;CACJ","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*/\nimport type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { ResizeController } from '@lit-labs/observers/resize_controller.js';\nimport { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';\nimport {\n RangeChangedEvent,\n VisibilityChangedEvent,\n} from '@lit-labs/virtualizer/Virtualizer.js';\n\ninterface ItemSize {\n width: number;\n height: number;\n}\n\nexport class GridController<T extends HTMLElement>\n implements ReactiveController\n{\n host!: ReactiveElement;\n\n resizeController!: ResizeController;\n\n rovingTabindexController!: RovingTabindexController<T>;\n\n get itemSize(): ItemSize {\n return this._itemSize();\n }\n\n /* c8 ignore next 6 */\n private _itemSize(): ItemSize {\n return {\n width: 100,\n height: 100,\n };\n }\n\n // First visible element\n _first = 0;\n\n get gap(): string | undefined {\n return this._gap();\n }\n\n /* c8 ignore next 3 */\n private _gap(): string | undefined {\n return undefined;\n }\n\n // Last visible element\n _last = 0;\n\n constructor(\n host: ReactiveElement,\n {\n elements,\n itemSize,\n gap,\n }: {\n elements: () => T[];\n itemSize: ItemSize | (() => ItemSize);\n gap?: string | (() => string);\n }\n ) {\n this.host = host;\n this.host.addController(this);\n this.applyLayout(itemSize, gap);\n this.resizeController = new ResizeController(this.host, {\n callback: (entries: ResizeObserverEntry[]): void => {\n entries.forEach((entry) => {\n this.measureDirectionLength(entry.contentRect);\n });\n },\n });\n this.rovingTabindexController = new RovingTabindexController<T>(\n this.host,\n {\n direction: 'grid',\n elements,\n focusInIndex: () => {\n const activeElement = (this.host.getRootNode() as Document)\n .activeElement as HTMLElement;\n return activeElement === this.host ? 0 : -1;\n },\n }\n );\n }\n\n public focus(options?: FocusOptions): void {\n this.rovingTabindexController.focus(options);\n }\n\n protected applyLayout(\n itemSize: ItemSize | (() => ItemSize),\n gap?: string | (() => string)\n ): void {\n /* c8 ignore next 2 */\n if (typeof itemSize === 'object') {\n this._itemSize = () => itemSize;\n } else if (\n typeof itemSize === 'function' &&\n typeof itemSize() !== 'undefined'\n ) {\n this._itemSize = itemSize;\n }\n /* c8 ignore next 2 */\n if (typeof gap === 'string') {\n this._gap = () => gap;\n } else if (typeof gap === 'function') {\n this._gap = gap;\n }\n }\n\n public update({\n elements,\n itemSize,\n gap,\n }: {\n elements: () => T[];\n itemSize: ItemSize | (() => ItemSize);\n gap?: string | (() => string);\n }): void {\n this.rovingTabindexController.update({ elements });\n this.applyLayout(itemSize, gap);\n const contentRect = this.host.getBoundingClientRect();\n this.measureDirectionLength(contentRect);\n }\n\n protected measureDirectionLength(contentRect: DOMRect): void {\n const gap = this.gap ? parseFloat(this.gap) : 0;\n this.rovingTabindexController.directionLength = Math.floor(\n (contentRect.width - gap) / (this.itemSize.width + gap)\n );\n }\n\n protected handleFocusin = (event: FocusEvent): void => {\n const doCallbackAfterPaint = (cb: () => void): void => {\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n cb();\n });\n });\n };\n const scrollToFirst = (): void => (this.host as any).scrollToIndex(0);\n const focusIntoGrid = (): void => {\n this.focus();\n this.host.tabIndex = -1;\n };\n if ((event.target as HTMLElement) === this.host) {\n if (this._first > 0) {\n doCallbackAfterPaint(() => {\n scrollToFirst();\n doCallbackAfterPaint(focusIntoGrid);\n });\n } else {\n doCallbackAfterPaint(focusIntoGrid);\n }\n }\n };\n\n protected handleFocusout = (event: FocusEvent): void => {\n if (\n event.relatedTarget &&\n !this.host.contains(event.relatedTarget as HTMLElement)\n ) {\n this.host.tabIndex = 0;\n }\n };\n\n protected handleRangeChanged = (event: RangeChangedEvent): void => {\n this.rovingTabindexController.clearElementCache(event.first);\n };\n\n protected handleVisibleChanged = (event: VisibilityChangedEvent): void => {\n this._first = event.first;\n this._last = event.last;\n };\n\n public hostConnected(): void {\n this.host.addEventListener('rangeChanged', this.handleRangeChanged);\n this.host.addEventListener(\n 'visibilityChanged',\n this.handleVisibleChanged\n );\n this.host.addEventListener('focusin', this.handleFocusin);\n this.host.addEventListener('focusout', this.handleFocusout);\n this.host.tabIndex = 0;\n this.host.style.setProperty('outline', 'none', 'important');\n }\n\n public hostDisconnected(): void {\n this.host.removeEventListener('rangeChanged', this.handleRangeChanged);\n this.host.removeEventListener(\n 'visibilityChanged',\n this.handleVisibleChanged\n );\n this.host.removeEventListener('focusin', this.handleFocusin);\n this.host.removeEventListener('focusout', this.handleFocusout);\n }\n}\n"]}
|
package/src/grid.css.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright
|
|
2
|
+
Copyright 2022 Adobe. All rights reserved.
|
|
3
3
|
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
5
|
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
package/src/grid.css.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid.css.js","sourceRoot":"","sources":["grid.css.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AACpD,MAAM,MAAM,GAAG,GAAG,CAAA;;CAEjB,CAAC;AACF,eAAe,MAAM,CAAC","sourcesContent":["/*\nCopyright
|
|
1
|
+
{"version":3,"file":"grid.css.js","sourceRoot":"","sources":["grid.css.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AACpD,MAAM,MAAM,GAAG,GAAG,CAAA;;CAEjB,CAAC;AACF,eAAe,MAAM,CAAC","sourcesContent":["/*\nCopyright 2022 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*/\nimport { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host{contain:strict;display:block;position:relative}\n`;\nexport default styles;"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import '@spectrum-web-components/grid/sp-grid.js';
|
|
13
|
+
import { html } from '@spectrum-web-components/base';
|
|
14
|
+
import { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';
|
|
15
|
+
measureFixtureCreation(html `
|
|
16
|
+
<sp-grid></sp-grid>
|
|
17
|
+
`);
|
|
18
|
+
//# sourceMappingURL=basic-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic-test.js","sourceRoot":"","sources":["basic-test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,0CAA0C,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAE/E,sBAAsB,CAAC,IAAI,CAAA;;CAE1B,CAAC,CAAC","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"]}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { elementUpdated, expect, fixture, nextFrame } from '@open-wc/testing';
|
|
13
|
+
import { html } from '@spectrum-web-components/base';
|
|
14
|
+
import '../sp-grid.js';
|
|
15
|
+
import { Default } from '../stories/grid.stories.js';
|
|
16
|
+
import { sendKeys } from '@web/test-runner-commands';
|
|
17
|
+
describe('Grid', () => {
|
|
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
|
+
el.focus();
|
|
34
|
+
await nextFrame();
|
|
35
|
+
await nextFrame();
|
|
36
|
+
expect(el.querySelector(el.focusableSelector) === document.activeElement).to.be.true;
|
|
37
|
+
});
|
|
38
|
+
it('allows to tab in and out', async () => {
|
|
39
|
+
const test = await fixture(html `
|
|
40
|
+
<div>${Default()}</div>
|
|
41
|
+
`);
|
|
42
|
+
const el = test.querySelector('sp-grid');
|
|
43
|
+
const firstInput = test.querySelector('#first-input');
|
|
44
|
+
const lastInput = test.querySelector('#last-input');
|
|
45
|
+
await elementUpdated(el);
|
|
46
|
+
expect(el.tabIndex).to.equal(0);
|
|
47
|
+
firstInput.focus();
|
|
48
|
+
expect(firstInput === document.activeElement).to.be.true;
|
|
49
|
+
expect(el.tabIndex).to.equal(0);
|
|
50
|
+
await sendKeys({
|
|
51
|
+
press: 'Tab',
|
|
52
|
+
});
|
|
53
|
+
await nextFrame();
|
|
54
|
+
await nextFrame();
|
|
55
|
+
expect(el.querySelector(el.focusableSelector) === document.activeElement).to.be.true;
|
|
56
|
+
expect(el.tabIndex).to.equal(-1);
|
|
57
|
+
await sendKeys({
|
|
58
|
+
press: 'Tab',
|
|
59
|
+
});
|
|
60
|
+
await nextFrame();
|
|
61
|
+
await nextFrame();
|
|
62
|
+
await elementUpdated(el);
|
|
63
|
+
expect(lastInput === document.activeElement).to.be.true;
|
|
64
|
+
expect(el.tabIndex).to.equal(0);
|
|
65
|
+
await sendKeys({
|
|
66
|
+
press: 'Shift+Tab',
|
|
67
|
+
});
|
|
68
|
+
await nextFrame();
|
|
69
|
+
await nextFrame();
|
|
70
|
+
await nextFrame();
|
|
71
|
+
await nextFrame();
|
|
72
|
+
expect(el.querySelector(el.focusableSelector) === document.activeElement).to.be.true;
|
|
73
|
+
expect(el.tabIndex).to.equal(-1);
|
|
74
|
+
});
|
|
75
|
+
it('manages roving tabindex', async () => {
|
|
76
|
+
const test = await fixture(html `
|
|
77
|
+
<div>${Default()}</div>
|
|
78
|
+
`);
|
|
79
|
+
const el = test.querySelector('sp-grid');
|
|
80
|
+
await elementUpdated(el);
|
|
81
|
+
expect(el.tabIndex).to.equal(0);
|
|
82
|
+
el.focus();
|
|
83
|
+
await nextFrame();
|
|
84
|
+
await nextFrame();
|
|
85
|
+
let focused = el.querySelector(el.focusableSelector);
|
|
86
|
+
await elementUpdated(focused);
|
|
87
|
+
expect(focused === document.activeElement).to.be.true;
|
|
88
|
+
expect(focused.focused).to.be.true;
|
|
89
|
+
await sendKeys({
|
|
90
|
+
press: 'ArrowRight',
|
|
91
|
+
});
|
|
92
|
+
focused = el.querySelector(`${el.focusableSelector}:nth-child(2)`);
|
|
93
|
+
await elementUpdated(focused);
|
|
94
|
+
expect(focused === document.activeElement).to.be.true;
|
|
95
|
+
expect(focused.focused).to.be.true;
|
|
96
|
+
await sendKeys({
|
|
97
|
+
press: 'ArrowDown',
|
|
98
|
+
});
|
|
99
|
+
focused = el.querySelector(`${el.focusableSelector}:nth-child(5)`);
|
|
100
|
+
await elementUpdated(focused);
|
|
101
|
+
expect(focused === document.activeElement).to.be.true;
|
|
102
|
+
expect(focused.focused).to.be.true;
|
|
103
|
+
await sendKeys({
|
|
104
|
+
press: 'ArrowLeft',
|
|
105
|
+
});
|
|
106
|
+
focused = el.querySelector(`${el.focusableSelector}:nth-child(4)`);
|
|
107
|
+
await elementUpdated(focused);
|
|
108
|
+
expect(focused === document.activeElement).to.be.true;
|
|
109
|
+
expect(focused.focused).to.be.true;
|
|
110
|
+
await sendKeys({
|
|
111
|
+
press: 'ArrowUp',
|
|
112
|
+
});
|
|
113
|
+
focused = el.querySelector(`${el.focusableSelector}`);
|
|
114
|
+
await elementUpdated(focused);
|
|
115
|
+
expect(focused === document.activeElement).to.be.true;
|
|
116
|
+
expect(focused.focused).to.be.true;
|
|
117
|
+
});
|
|
118
|
+
it('manages selection', async () => {
|
|
119
|
+
const test = await fixture(html `
|
|
120
|
+
<div>${Default()}</div>
|
|
121
|
+
`);
|
|
122
|
+
const el = test.querySelector('sp-grid');
|
|
123
|
+
await elementUpdated(el);
|
|
124
|
+
expect(el.tabIndex).to.equal(0);
|
|
125
|
+
el.focus();
|
|
126
|
+
await nextFrame();
|
|
127
|
+
await nextFrame();
|
|
128
|
+
let focused = el.querySelector(el.focusableSelector);
|
|
129
|
+
await elementUpdated(focused);
|
|
130
|
+
expect(focused === document.activeElement).to.be.true;
|
|
131
|
+
expect(focused.focused).to.be.true;
|
|
132
|
+
await sendKeys({
|
|
133
|
+
press: 'ArrowRight',
|
|
134
|
+
});
|
|
135
|
+
focused = el.querySelector(`${el.focusableSelector}:nth-child(2)`);
|
|
136
|
+
await elementUpdated(focused);
|
|
137
|
+
expect(focused === document.activeElement).to.be.true;
|
|
138
|
+
expect(focused.focused).to.be.true;
|
|
139
|
+
await sendKeys({
|
|
140
|
+
press: 'Space',
|
|
141
|
+
});
|
|
142
|
+
await elementUpdated(el);
|
|
143
|
+
expect(el.selected).to.deep.equal([{ id: 1 }]);
|
|
144
|
+
await sendKeys({
|
|
145
|
+
press: 'ArrowDown',
|
|
146
|
+
});
|
|
147
|
+
focused = el.querySelector(`${el.focusableSelector}:nth-child(5)`);
|
|
148
|
+
await elementUpdated(focused);
|
|
149
|
+
expect(focused === document.activeElement).to.be.true;
|
|
150
|
+
expect(focused.focused).to.be.true;
|
|
151
|
+
await sendKeys({
|
|
152
|
+
press: 'Space',
|
|
153
|
+
});
|
|
154
|
+
await elementUpdated(el);
|
|
155
|
+
expect(el.selected).to.deep.equal([{ id: 1 }, { id: 4 }]);
|
|
156
|
+
await sendKeys({
|
|
157
|
+
press: 'ArrowUp',
|
|
158
|
+
});
|
|
159
|
+
focused = el.querySelector(`${el.focusableSelector}:nth-child(2)`);
|
|
160
|
+
await elementUpdated(focused);
|
|
161
|
+
expect(focused === document.activeElement).to.be.true;
|
|
162
|
+
expect(focused.focused).to.be.true;
|
|
163
|
+
await sendKeys({
|
|
164
|
+
press: 'Space',
|
|
165
|
+
});
|
|
166
|
+
await elementUpdated(el);
|
|
167
|
+
expect(el.selected).to.deep.equal([{ id: 4 }]);
|
|
168
|
+
});
|
|
169
|
+
it('does not claim lit-virtualizer on the global registry', async () => {
|
|
170
|
+
const test = await fixture(html `
|
|
171
|
+
<div>${Default()}</div>
|
|
172
|
+
`);
|
|
173
|
+
const el = test.querySelector('sp-grid');
|
|
174
|
+
await elementUpdated(el);
|
|
175
|
+
customElements.define('lit-virtualizer', class extends HTMLElement {
|
|
176
|
+
});
|
|
177
|
+
// make sure we also don't prevent *any* registration of lit-virtualizer
|
|
178
|
+
expect(() => {
|
|
179
|
+
customElements.define('lit-virtualizer', class extends HTMLElement {
|
|
180
|
+
});
|
|
181
|
+
}).to.throw();
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
//# sourceMappingURL=grid.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid.test.js","sourceRoot":"","sources":["grid.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAGrD,OAAO,eAAe,CAAC;AAEvB,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IAClB,EAAE,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;QAC3C,MAAM,IAAI,GAAG,MAAM,OAAO,CACtB,IAAI,CAAA;uBACO,OAAO,EAAE;aACnB,CACJ,CAAC;QACF,MAAM,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC,SAAS,CAAS,CAAC;QAEjD,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC;IACxC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,eAAe,EAAE,KA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nD,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,uDAAuD,EAAE,KAAK,IAAI,EAAE;QACnE,MAAM,IAAI,GAAG,MAAM,OAAO,CACtB,IAAI,CAAA;uBACO,OAAO,EAAE;aACnB,CACJ,CAAC;QACF,MAAM,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC,SAAS,CAAS,CAAC;QAEjD,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,KAAM,SAAQ,WAAW;SAAG,CAAC,CAAC;QAEvE,wEAAwE;QACxE,MAAM,CAAC,GAAG,EAAE;YACR,cAAc,CAAC,MAAM,CACjB,iBAAiB,EACjB,KAAM,SAAQ,WAAW;aAAG,CAC/B,CAAC;QACN,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","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 '../sp-grid.js';\nimport { Grid } from '..';\nimport { Default } from '../stories/grid.stories.js';\nimport { sendKeys } from '@web/test-runner-commands';\n\ndescribe('Grid', () => {\n it('loads default grid accessibly', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\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>(\n html`\n <div>${Default()}</div>\n `\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 expect(\n el.querySelector(el.focusableSelector) === document.activeElement\n ).to.be.true;\n });\n it('allows to tab in and out', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\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>(\n html`\n <div>${Default()}</div>\n `\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>(\n html`\n <div>${Default()}</div>\n `\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>(\n html`\n <div>${Default()}</div>\n `\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"]}
|