@spectrum-web-components/reactive-controllers 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/reactive-controllers",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -42,10 +42,10 @@
42
42
  "reactive controllers"
43
43
  ],
44
44
  "dependencies": {
45
- "lit": "^2.0.2",
45
+ "lit": "^2.1.2",
46
46
  "tslib": "^2.0.0"
47
47
  },
48
48
  "types": "./src/index.d.ts",
49
49
  "customElements": "custom-elements.json",
50
- "gitHead": "f23b15ec952d7450272a8275524c905e028b4ddc"
50
+ "gitHead": "57aba8030b6af96af4015a0aa830e342a17dc219"
51
51
  }
@@ -34,11 +34,13 @@ export declare class RovingTabindexController<T extends HTMLElement> implements
34
34
  isFocusableElement: (_el: T) => boolean;
35
35
  isEventWithinListenerScope(event: Event): boolean;
36
36
  _listenerScope: () => HTMLElement;
37
+ offset: number;
37
38
  private managed;
38
39
  constructor(host: ReactiveElement, { direction, elementEnterAction, elements, focusInIndex, isFocusableElement, listenerScope, }?: RovingTabindexConfig<T>);
40
+ update({ elements }?: RovingTabindexConfig<T>): void;
39
41
  focus(options?: FocusOptions): void;
40
42
  private manageIndexesAnimationFrame;
41
- clearElementCache(): void;
43
+ clearElementCache(offset?: number): void;
42
44
  setCurrentIndexCircularly(diff: number): void;
43
45
  hostContainsFocus(): void;
44
46
  hostNoLongerContainsFocus(): void;
@@ -14,6 +14,9 @@ export class RovingTabindexController {
14
14
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
15
15
  this.isFocusableElement = (_el) => true;
16
16
  this._listenerScope = () => this.host;
17
+ // When elements are virtualized, the delta between the first element
18
+ // and the first rendered element.
19
+ this.offset = 0;
17
20
  this.managed = true;
18
21
  this.manageIndexesAnimationFrame = 0;
19
22
  this.handleFocusin = (event) => {
@@ -63,7 +66,16 @@ export class RovingTabindexController {
63
66
  break;
64
67
  }
65
68
  event.preventDefault();
66
- this.setCurrentIndexCircularly(diff);
69
+ if (this.direction === 'grid' && this.currentIndex + diff < 0) {
70
+ this.currentIndex = 0;
71
+ }
72
+ else if (this.direction === 'grid' &&
73
+ this.currentIndex + diff > this.elements.length - 1) {
74
+ this.currentIndex = this.elements.length - 1;
75
+ }
76
+ else {
77
+ this.setCurrentIndexCircularly(diff);
78
+ }
67
79
  // To allow the `focusInIndex` to be calculated with the "after" state of the keyboard interaction
68
80
  // do `elementEnterAction` _before_ focusing the next element.
69
81
  this.elementEnterAction(this.elements[this.currentIndex]);
@@ -97,10 +109,10 @@ export class RovingTabindexController {
97
109
  if (this._currentIndex === -1) {
98
110
  this._currentIndex = this.focusInIndex;
99
111
  }
100
- return this._currentIndex;
112
+ return this._currentIndex - this.offset;
101
113
  }
102
114
  set currentIndex(currentIndex) {
103
- this._currentIndex = currentIndex;
115
+ this._currentIndex = currentIndex + this.offset;
104
116
  }
105
117
  get direction() {
106
118
  return this._direction();
@@ -131,13 +143,20 @@ export class RovingTabindexController {
131
143
  return true;
132
144
  return event.composedPath().includes(this._listenerScope());
133
145
  }
146
+ update({ elements } = { elements: () => [] }) {
147
+ this.unmanage();
148
+ this._elements = elements;
149
+ this.clearElementCache();
150
+ this.manage();
151
+ }
134
152
  focus(options) {
135
153
  var _a;
136
154
  (_a = this.elements[this.currentIndex]) === null || _a === void 0 ? void 0 : _a.focus(options);
137
155
  }
138
- clearElementCache() {
156
+ clearElementCache(offset = 0) {
139
157
  delete this.cachedElements;
140
158
  cancelAnimationFrame(this.manageIndexesAnimationFrame);
159
+ this.offset = offset;
141
160
  if (!this.managed)
142
161
  return;
143
162
  this.manageIndexesAnimationFrame = requestAnimationFrame(() => this.manageTabindexes());
@@ -1 +1 @@
1
- {"version":3,"file":"RovingTabindex.js","sourceRoot":"","sources":["RovingTabindex.ts"],"names":[],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,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACjE,CAAC;IAED,WAAW;QACP,IAAI,IAAI,CAAC,YAAY,EAAE;YACnB,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACxB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;SAC7B;IACL,CAAC;IAED,aAAa;QACT,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC7B,CAAC;IAED,gBAAgB;QACZ,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAChC,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\ntype DirectionTypes = 'horizontal' | 'vertical' | 'both' | 'grid';\nexport type RovingTabindexConfig<T> = {\n focusInIndex?: (_elements: T[]) => number;\n direction?: DirectionTypes | (() => DirectionTypes);\n elementEnterAction?: (el: T) => void;\n elements: () => T[];\n isFocusableElement?: (el: T) => boolean;\n listenerScope?: HTMLElement | (() => HTMLElement);\n};\ninterface UpdateTabIndexes {\n tabIndex: number;\n removeTabIndex?: boolean;\n}\n\nexport class RovingTabindexController<T extends HTMLElement>\n implements ReactiveController\n{\n private cachedElements?: T[];\n\n get currentIndex(): number {\n if (this._currentIndex === -1) {\n this._currentIndex = this.focusInIndex;\n }\n return this._currentIndex;\n }\n\n set currentIndex(currentIndex) {\n this._currentIndex = currentIndex;\n }\n\n private _currentIndex = -1;\n\n get direction(): DirectionTypes {\n return this._direction();\n }\n\n _direction = (): DirectionTypes => 'both';\n\n directionLength = 5;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n elementEnterAction = (_el: T): void => {\n return;\n };\n\n get elements(): T[] {\n if (!this.cachedElements) {\n this.cachedElements = this._elements();\n }\n return this.cachedElements;\n }\n\n private _elements!: () => T[];\n\n firstUpdated = true;\n\n private set focused(focused: boolean) {\n if (focused === this.focused) return;\n this._focused = focused;\n this.manageTabindexes();\n }\n\n private get focused(): boolean {\n return this._focused;\n }\n private _focused = false;\n\n get focusInElement(): T {\n return this.elements[this.focusInIndex];\n }\n\n get focusInIndex(): number {\n return this._focusInIndex(this.elements);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _focusInIndex = (_elements: T[]): number => 0;\n\n host: ReactiveElement;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n isFocusableElement = (_el: T): boolean => true;\n\n isEventWithinListenerScope(event: Event): boolean {\n if (this._listenerScope() === this.host) return true;\n return event.composedPath().includes(this._listenerScope());\n }\n\n _listenerScope = (): HTMLElement => this.host;\n\n private managed = true;\n\n constructor(\n host: ReactiveElement,\n {\n direction,\n elementEnterAction,\n elements,\n focusInIndex,\n isFocusableElement,\n listenerScope,\n }: RovingTabindexConfig<T> = { elements: () => [] }\n ) {\n this.host = host;\n this.host.addController(this);\n this._elements = elements;\n this.isFocusableElement = isFocusableElement || this.isFocusableElement;\n if (typeof direction === 'string') {\n this._direction = () => direction;\n } else if (typeof direction === 'function') {\n this._direction = direction;\n }\n this.elementEnterAction = elementEnterAction || this.elementEnterAction;\n if (typeof focusInIndex === 'number') {\n this._focusInIndex = () => focusInIndex;\n } else if (typeof focusInIndex === 'function') {\n this._focusInIndex = focusInIndex;\n }\n if (typeof listenerScope === 'object') {\n this._listenerScope = () => listenerScope;\n } else if (typeof listenerScope === 'function') {\n this._listenerScope = listenerScope;\n }\n }\n\n focus(options?: FocusOptions): void {\n this.elements[this.currentIndex]?.focus(options);\n }\n\n private manageIndexesAnimationFrame = 0;\n\n clearElementCache(): void {\n delete this.cachedElements;\n cancelAnimationFrame(this.manageIndexesAnimationFrame);\n if (!this.managed) return;\n\n this.manageIndexesAnimationFrame = requestAnimationFrame(() =>\n this.manageTabindexes()\n );\n }\n\n setCurrentIndexCircularly(diff: number): void {\n const { length } = this.elements;\n let steps = length;\n // start at a possibly not 0 index\n let nextIndex = (length + this.currentIndex + diff) % length;\n while (\n // don't cycle the elements more than once\n steps &&\n this.elements[nextIndex] &&\n !this.isFocusableElement(this.elements[nextIndex])\n ) {\n nextIndex = (length + nextIndex + diff) % length;\n steps -= 1;\n }\n this.currentIndex = nextIndex;\n }\n\n hostContainsFocus(): void {\n this.host.addEventListener('focusout', this.handleFocusout);\n this.host.addEventListener('keydown', this.handleKeydown);\n this.focused = true;\n }\n\n hostNoLongerContainsFocus(): void {\n this.host.addEventListener('focusin', this.handleFocusin);\n this.host.removeEventListener('focusout', this.handleFocusout);\n this.host.removeEventListener('keydown', this.handleKeydown);\n this.currentIndex = this.focusInIndex;\n this.focused = false;\n }\n\n isRelatedTargetAnElement(event: FocusEvent): boolean {\n const relatedTarget = event.relatedTarget as null | Element;\n return !this.elements.includes(relatedTarget as T);\n }\n\n handleFocusin = (event: FocusEvent): void => {\n if (!this.isEventWithinListenerScope(event)) return;\n if (this.isRelatedTargetAnElement(event)) {\n this.hostContainsFocus();\n }\n const path = event.composedPath() as T[];\n let targetIndex = -1;\n path.find((el) => {\n targetIndex = this.elements.indexOf(el);\n return targetIndex !== -1;\n });\n this.currentIndex = targetIndex > -1 ? targetIndex : this.currentIndex;\n };\n\n handleFocusout = (event: FocusEvent): void => {\n if (this.isRelatedTargetAnElement(event)) {\n this.hostNoLongerContainsFocus();\n }\n };\n\n acceptsEventCode(code: string): boolean {\n if (code === 'End' || code === 'Home') {\n return true;\n }\n switch (this.direction) {\n case 'horizontal':\n return code === 'ArrowLeft' || code === 'ArrowRight';\n case 'vertical':\n return code === 'ArrowUp' || code === 'ArrowDown';\n case 'both':\n case 'grid':\n return code.startsWith('Arrow');\n }\n }\n\n handleKeydown = (event: KeyboardEvent): void => {\n if (!this.acceptsEventCode(event.code) || event.defaultPrevented) {\n return;\n }\n let diff = 0;\n switch (event.code) {\n case 'ArrowRight':\n diff += 1;\n break;\n case 'ArrowDown':\n diff += this.direction === 'grid' ? this.directionLength : 1;\n break;\n case 'ArrowLeft':\n diff -= 1;\n break;\n case 'ArrowUp':\n diff -= this.direction === 'grid' ? this.directionLength : 1;\n break;\n case 'End':\n this.currentIndex = 0;\n diff -= 1;\n break;\n case 'Home':\n this.currentIndex = this.elements.length - 1;\n diff += 1;\n break;\n }\n event.preventDefault();\n this.setCurrentIndexCircularly(diff);\n // To allow the `focusInIndex` to be calculated with the \"after\" state of the keyboard interaction\n // do `elementEnterAction` _before_ focusing the next element.\n this.elementEnterAction(this.elements[this.currentIndex]);\n this.focus();\n };\n\n manageTabindexes(): void {\n if (this.focused) {\n this.updateTabindexes(() => ({ tabIndex: -1 }));\n } else {\n this.updateTabindexes((el: HTMLElement): UpdateTabIndexes => {\n return {\n removeTabIndex:\n el.contains(this.focusInElement) &&\n el !== this.focusInElement,\n tabIndex: el === this.focusInElement ? 0 : -1,\n };\n });\n }\n }\n\n updateTabindexes(getTabIndex: (el: HTMLElement) => UpdateTabIndexes): void {\n this.elements.forEach((el) => {\n const { tabIndex, removeTabIndex } = getTabIndex(el);\n if (!removeTabIndex) {\n el.tabIndex = tabIndex;\n return;\n }\n el.removeAttribute('tabindex');\n const updatable = el as unknown as {\n requestUpdate?: () => void;\n };\n if (updatable.requestUpdate) updatable.requestUpdate();\n });\n }\n\n manage(): void {\n this.managed = true;\n this.manageTabindexes();\n this.addEventListeners();\n }\n\n unmanage(): void {\n this.managed = false;\n this.updateTabindexes(() => ({ tabIndex: 0 }));\n this.removeEventListeners();\n }\n\n addEventListeners(): void {\n this.host.addEventListener('focusin', this.handleFocusin);\n }\n\n removeEventListeners(): void {\n this.host.removeEventListener('focusin', this.handleFocusin);\n this.host.removeEventListener('focusout', this.handleFocusout);\n this.host.removeEventListener('keydown', this.handleKeydown);\n }\n\n hostUpdated(): void {\n if (this.firstUpdated) {\n this.manageTabindexes();\n this.firstUpdated = false;\n }\n }\n\n hostConnected(): void {\n this.addEventListeners();\n }\n\n hostDisconnected(): void {\n this.removeEventListeners();\n }\n}\n"]}
1
+ {"version":3,"file":"RovingTabindex.js","sourceRoot":"","sources":["RovingTabindex.ts"],"names":[],"mappings":"AA2BA,MAAM,OAAO,wBAAwB;IAkFjC,YACI,IAAqB,EACrB,EACI,SAAS,EACT,kBAAkB,EAClB,QAAQ,EACR,YAAY,EACZ,kBAAkB,EAClB,aAAa,MACY,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE;QA3E/C,kBAAa,GAAG,CAAC,CAAC,CAAC;QAM3B,eAAU,GAAG,GAAmB,EAAE,CAAC,MAAM,CAAC;QAEnC,oBAAe,GAAG,CAAC,CAAC;QAE3B,6DAA6D;QAC7D,uBAAkB,GAAG,CAAC,GAAM,EAAQ,EAAE;YAClC,OAAO;QACX,CAAC,CAAC;QAWF,iBAAY,GAAG,IAAI,CAAC;QAWZ,aAAQ,GAAG,KAAK,CAAC;QAUzB,6DAA6D;QAC7D,kBAAa,GAAG,CAAC,SAAc,EAAU,EAAE,CAAC,CAAC,CAAC;QAI9C,6DAA6D;QAC7D,uBAAkB,GAAG,CAAC,GAAM,EAAW,EAAE,CAAC,IAAI,CAAC;QAO/C,mBAAc,GAAG,GAAgB,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;QAE9C,qEAAqE;QACrE,kCAAkC;QAClC,WAAM,GAAG,CAAC,CAAC;QAEH,YAAO,GAAG,IAAI,CAAC;QAgDf,gCAA2B,GAAG,CAAC,CAAC;QAiDxC,kBAAa,GAAG,CAAC,KAAiB,EAAQ,EAAE;YACxC,IAAI,CAAC,IAAI,CAAC,0BAA0B,CAAC,KAAK,CAAC;gBAAE,OAAO;YACpD,IAAI,IAAI,CAAC,wBAAwB,CAAC,KAAK,CA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E,CAAC;YACxB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;SAC7B;IACL,CAAC;IAED,aAAa;QACT,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC7B,CAAC;IAED,gBAAgB;QACZ,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAChC,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\ntype DirectionTypes = 'horizontal' | 'vertical' | 'both' | 'grid';\nexport type RovingTabindexConfig<T> = {\n focusInIndex?: (_elements: T[]) => number;\n direction?: DirectionTypes | (() => DirectionTypes);\n elementEnterAction?: (el: T) => void;\n elements: () => T[];\n isFocusableElement?: (el: T) => boolean;\n listenerScope?: HTMLElement | (() => HTMLElement);\n};\ninterface UpdateTabIndexes {\n tabIndex: number;\n removeTabIndex?: boolean;\n}\n\nexport class RovingTabindexController<T extends HTMLElement>\n implements ReactiveController\n{\n private cachedElements?: T[];\n\n get currentIndex(): number {\n if (this._currentIndex === -1) {\n this._currentIndex = this.focusInIndex;\n }\n return this._currentIndex - this.offset;\n }\n\n set currentIndex(currentIndex) {\n this._currentIndex = currentIndex + this.offset;\n }\n\n private _currentIndex = -1;\n\n get direction(): DirectionTypes {\n return this._direction();\n }\n\n _direction = (): DirectionTypes => 'both';\n\n public directionLength = 5;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n elementEnterAction = (_el: T): void => {\n return;\n };\n\n get elements(): T[] {\n if (!this.cachedElements) {\n this.cachedElements = this._elements();\n }\n return this.cachedElements;\n }\n\n private _elements!: () => T[];\n\n firstUpdated = true;\n\n private set focused(focused: boolean) {\n if (focused === this.focused) return;\n this._focused = focused;\n this.manageTabindexes();\n }\n\n private get focused(): boolean {\n return this._focused;\n }\n private _focused = false;\n\n get focusInElement(): T {\n return this.elements[this.focusInIndex];\n }\n\n get focusInIndex(): number {\n return this._focusInIndex(this.elements);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _focusInIndex = (_elements: T[]): number => 0;\n\n host: ReactiveElement;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n isFocusableElement = (_el: T): boolean => true;\n\n isEventWithinListenerScope(event: Event): boolean {\n if (this._listenerScope() === this.host) return true;\n return event.composedPath().includes(this._listenerScope());\n }\n\n _listenerScope = (): HTMLElement => this.host;\n\n // When elements are virtualized, the delta between the first element\n // and the first rendered element.\n offset = 0;\n\n private managed = true;\n\n constructor(\n host: ReactiveElement,\n {\n direction,\n elementEnterAction,\n elements,\n focusInIndex,\n isFocusableElement,\n listenerScope,\n }: RovingTabindexConfig<T> = { elements: () => [] }\n ) {\n this.host = host;\n this.host.addController(this);\n this._elements = elements;\n this.isFocusableElement = isFocusableElement || this.isFocusableElement;\n if (typeof direction === 'string') {\n this._direction = () => direction;\n } else if (typeof direction === 'function') {\n this._direction = direction;\n }\n this.elementEnterAction = elementEnterAction || this.elementEnterAction;\n if (typeof focusInIndex === 'number') {\n this._focusInIndex = () => focusInIndex;\n } else if (typeof focusInIndex === 'function') {\n this._focusInIndex = focusInIndex;\n }\n if (typeof listenerScope === 'object') {\n this._listenerScope = () => listenerScope;\n } else if (typeof listenerScope === 'function') {\n this._listenerScope = listenerScope;\n }\n }\n\n update(\n { elements }: RovingTabindexConfig<T> = { elements: () => [] }\n ): void {\n this.unmanage();\n this._elements = elements;\n this.clearElementCache();\n this.manage();\n }\n\n focus(options?: FocusOptions): void {\n this.elements[this.currentIndex]?.focus(options);\n }\n\n private manageIndexesAnimationFrame = 0;\n\n clearElementCache(offset = 0): void {\n delete this.cachedElements;\n cancelAnimationFrame(this.manageIndexesAnimationFrame);\n this.offset = offset;\n if (!this.managed) return;\n\n this.manageIndexesAnimationFrame = requestAnimationFrame(() =>\n this.manageTabindexes()\n );\n }\n\n setCurrentIndexCircularly(diff: number): void {\n const { length } = this.elements;\n let steps = length;\n // start at a possibly not 0 index\n let nextIndex = (length + this.currentIndex + diff) % length;\n while (\n // don't cycle the elements more than once\n steps &&\n this.elements[nextIndex] &&\n !this.isFocusableElement(this.elements[nextIndex])\n ) {\n nextIndex = (length + nextIndex + diff) % length;\n steps -= 1;\n }\n this.currentIndex = nextIndex;\n }\n\n hostContainsFocus(): void {\n this.host.addEventListener('focusout', this.handleFocusout);\n this.host.addEventListener('keydown', this.handleKeydown);\n this.focused = true;\n }\n\n hostNoLongerContainsFocus(): void {\n this.host.addEventListener('focusin', this.handleFocusin);\n this.host.removeEventListener('focusout', this.handleFocusout);\n this.host.removeEventListener('keydown', this.handleKeydown);\n this.currentIndex = this.focusInIndex;\n this.focused = false;\n }\n\n isRelatedTargetAnElement(event: FocusEvent): boolean {\n const relatedTarget = event.relatedTarget as null | Element;\n return !this.elements.includes(relatedTarget as T);\n }\n\n handleFocusin = (event: FocusEvent): void => {\n if (!this.isEventWithinListenerScope(event)) return;\n if (this.isRelatedTargetAnElement(event)) {\n this.hostContainsFocus();\n }\n const path = event.composedPath() as T[];\n let targetIndex = -1;\n path.find((el) => {\n targetIndex = this.elements.indexOf(el);\n return targetIndex !== -1;\n });\n this.currentIndex = targetIndex > -1 ? targetIndex : this.currentIndex;\n };\n\n handleFocusout = (event: FocusEvent): void => {\n if (this.isRelatedTargetAnElement(event)) {\n this.hostNoLongerContainsFocus();\n }\n };\n\n acceptsEventCode(code: string): boolean {\n if (code === 'End' || code === 'Home') {\n return true;\n }\n switch (this.direction) {\n case 'horizontal':\n return code === 'ArrowLeft' || code === 'ArrowRight';\n case 'vertical':\n return code === 'ArrowUp' || code === 'ArrowDown';\n case 'both':\n case 'grid':\n return code.startsWith('Arrow');\n }\n }\n\n handleKeydown = (event: KeyboardEvent): void => {\n if (!this.acceptsEventCode(event.code) || event.defaultPrevented) {\n return;\n }\n let diff = 0;\n switch (event.code) {\n case 'ArrowRight':\n diff += 1;\n break;\n case 'ArrowDown':\n diff += this.direction === 'grid' ? this.directionLength : 1;\n break;\n case 'ArrowLeft':\n diff -= 1;\n break;\n case 'ArrowUp':\n diff -= this.direction === 'grid' ? this.directionLength : 1;\n break;\n case 'End':\n this.currentIndex = 0;\n diff -= 1;\n break;\n case 'Home':\n this.currentIndex = this.elements.length - 1;\n diff += 1;\n break;\n }\n event.preventDefault();\n if (this.direction === 'grid' && this.currentIndex + diff < 0) {\n this.currentIndex = 0;\n } else if (\n this.direction === 'grid' &&\n this.currentIndex + diff > this.elements.length - 1\n ) {\n this.currentIndex = this.elements.length - 1;\n } else {\n this.setCurrentIndexCircularly(diff);\n }\n // To allow the `focusInIndex` to be calculated with the \"after\" state of the keyboard interaction\n // do `elementEnterAction` _before_ focusing the next element.\n this.elementEnterAction(this.elements[this.currentIndex]);\n this.focus();\n };\n\n manageTabindexes(): void {\n if (this.focused) {\n this.updateTabindexes(() => ({ tabIndex: -1 }));\n } else {\n this.updateTabindexes((el: HTMLElement): UpdateTabIndexes => {\n return {\n removeTabIndex:\n el.contains(this.focusInElement) &&\n el !== this.focusInElement,\n tabIndex: el === this.focusInElement ? 0 : -1,\n };\n });\n }\n }\n\n updateTabindexes(getTabIndex: (el: HTMLElement) => UpdateTabIndexes): void {\n this.elements.forEach((el) => {\n const { tabIndex, removeTabIndex } = getTabIndex(el);\n if (!removeTabIndex) {\n el.tabIndex = tabIndex;\n return;\n }\n el.removeAttribute('tabindex');\n const updatable = el as unknown as {\n requestUpdate?: () => void;\n };\n if (updatable.requestUpdate) updatable.requestUpdate();\n });\n }\n\n manage(): void {\n this.managed = true;\n this.manageTabindexes();\n this.addEventListeners();\n }\n\n unmanage(): void {\n this.managed = false;\n this.updateTabindexes(() => ({ tabIndex: 0 }));\n this.removeEventListeners();\n }\n\n addEventListeners(): void {\n this.host.addEventListener('focusin', this.handleFocusin);\n }\n\n removeEventListeners(): void {\n this.host.removeEventListener('focusin', this.handleFocusin);\n this.host.removeEventListener('focusout', this.handleFocusout);\n this.host.removeEventListener('keydown', this.handleKeydown);\n }\n\n hostUpdated(): void {\n if (this.firstUpdated) {\n this.manageTabindexes();\n this.firstUpdated = false;\n }\n }\n\n hostConnected(): void {\n this.addEventListeners();\n }\n\n hostDisconnected(): void {\n this.removeEventListeners();\n }\n}\n"]}
@@ -1,32 +0,0 @@
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 { html, LitElement } from 'lit';
13
- import { expect, fixture, nextFrame } from '@open-wc/testing';
14
- import { setViewport } from '@web/test-runner-commands';
15
- import { MatchMediaController } from '../';
16
- describe('Match Media', () => {
17
- it('responds to media changes', async () => {
18
- class TestEl extends LitElement {
19
- }
20
- customElements.define('test-match-media-el', TestEl);
21
- const el = await fixture(html `
22
- <test-match-media-el></test-match-media-el>
23
- `);
24
- const controller = new MatchMediaController(el, '(min-width: 500px)');
25
- expect(controller.matches).to.be.true;
26
- await setViewport({ width: 360, height: 640 });
27
- // Allow viewport update to propagate.
28
- await nextFrame();
29
- expect(controller.matches).to.be.false;
30
- });
31
- });
32
- //# sourceMappingURL=match-media.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"match-media.test.js","sourceRoot":"","sources":["match-media.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,KAAK,CAAC;AAE3C,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;QACvC,MAAM,MAAO,SAAQ,UAAU;SAAG;QAClC,cAAc,CAAC,MAAM,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;QACrD,MAAM,EAAE,GAAG,MAAM,OAAO,CACpB,IAAI,CAAA;;aAEH,CACJ,CAAC;QACF,MAAM,UAAU,GAAG,IAAI,oBAAoB,CACvC,EAA6C,EAC7C,oBAAoB,CACvB,CAAC;QACF,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;QACtC,MAAM,WAAW,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;QAC/C,sCAAsC;QACtC,MAAM,SAAS,EAAE,CAAC;QAClB,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;IAC3C,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 { html, LitElement } from 'lit';\nimport { expect, fixture, nextFrame } from '@open-wc/testing';\nimport { setViewport } from '@web/test-runner-commands';\nimport { MatchMediaController } from '../';\n\ndescribe('Match Media', () => {\n it('responds to media changes', async () => {\n class TestEl extends LitElement {}\n customElements.define('test-match-media-el', TestEl);\n const el = await fixture(\n html`\n <test-match-media-el></test-match-media-el>\n `\n );\n const controller = new MatchMediaController(\n el as LitElement & { shadowRoot: ShadowRoot },\n '(min-width: 500px)'\n );\n expect(controller.matches).to.be.true;\n await setViewport({ width: 360, height: 640 });\n // Allow viewport update to propagate.\n await nextFrame();\n expect(controller.matches).to.be.false;\n });\n});\n"]}
@@ -1,137 +0,0 @@
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/action-button/sp-action-button.js';
13
- import '@spectrum-web-components/action-group/sp-action-group.js';
14
- import '@spectrum-web-components/tabs/sp-tab-panel.js';
15
- import '@spectrum-web-components/tabs/sp-tab.js';
16
- import '@spectrum-web-components/tabs/sp-tabs.js';
17
- import { elementUpdated, expect, fixture, nextFrame } from '@open-wc/testing';
18
- import { html } from '@spectrum-web-components/base';
19
- import { sendKeys } from '@web/test-runner-commands';
20
- import { sendMouse } from '../../../test/plugins/browser.js';
21
- const createTabs = async () => {
22
- const tabs = await fixture(html `
23
- <sp-tabs selected="second">
24
- <sp-tab label="Tab 1" value="first"></sp-tab>
25
- <sp-tab label="Tab 2" value="second"></sp-tab>
26
- <sp-tab label="Tab 3" value="third"></sp-tab>
27
- <sp-tab-panel value="first">
28
- <sp-action-group selects="single">
29
- <sp-action-button selected value="1">
30
- Single Button 1
31
- </sp-action-button>
32
- <sp-action-button value="2">
33
- Single Button 2
34
- </sp-action-button>
35
- <sp-action-button value="3">
36
- Single Button 3
37
- </sp-action-button>
38
- </sp-action-group>
39
- </sp-tab-panel>
40
- <sp-tab-panel value="second">
41
- <sp-action-group selects="multiple">
42
- <sp-action-button value="1">
43
- Multiple Button 1
44
- </sp-action-button>
45
- <sp-action-button selected value="2">
46
- Multiple Button 2
47
- </sp-action-button>
48
- <sp-action-button selected value="3">
49
- Multiple Button 3
50
- </sp-action-button>
51
- </sp-action-group>
52
- </sp-tab-panel>
53
- <sp-tab-panel value="third">
54
- <sp-action-group>
55
- <sp-action-button value="1">
56
- None Button 1
57
- </sp-action-button>
58
- <sp-action-button value="2">
59
- None Button 2
60
- </sp-action-button>
61
- <sp-action-button selected value="3">
62
- None Button 3
63
- </sp-action-button>
64
- </sp-action-group>
65
- </sp-tab-panel>
66
- </sp-tabs>
67
- `);
68
- await elementUpdated(tabs);
69
- return tabs;
70
- };
71
- describe('Action Group inside of Tabs', () => {
72
- it('accurately navigates the desired element', async () => {
73
- const el = await createTabs();
74
- const tab1 = el.querySelector('sp-tab[value="first"]');
75
- const tab2 = el.querySelector('sp-tab[value="second"]');
76
- const tab3 = el.querySelector('sp-tab[value="third"]');
77
- const tabPanel1 = el.querySelector('sp-tab-panel[value="first"]');
78
- const tabPanel2 = el.querySelector('sp-tab-panel[value="second"]');
79
- const tabPanel3 = el.querySelector('sp-tab-panel[value="third"]');
80
- const actionGroup1 = tabPanel1.querySelector('sp-action-group');
81
- const actionGroup2 = tabPanel2.querySelector('sp-action-group');
82
- const actionGroup3 = tabPanel3.querySelector('sp-action-group');
83
- const actionButton1 = actionGroup1.querySelector('[selected]');
84
- const actionButton2 = actionGroup2.querySelector('[selected]');
85
- const actionButton3 = actionGroup3.querySelector('[selected]');
86
- el.focus();
87
- expect(el.contains(document.activeElement)).to.be.true;
88
- expect(document.activeElement === tab2).to.be.true;
89
- actionGroup2.focus();
90
- expect(document.activeElement === actionButton2).to.be.true;
91
- await nextFrame();
92
- await sendKeys({
93
- press: 'ArrowLeft',
94
- });
95
- expect(document.activeElement === tab1).to.be.false;
96
- expect(actionGroup2.contains(document.activeElement)).to.be.true;
97
- el.focus();
98
- expect(document.activeElement === tab2).to.be.true;
99
- await sendKeys({
100
- press: 'ArrowRight',
101
- });
102
- expect(document.activeElement === tab3).to.be.true;
103
- await sendKeys({
104
- press: 'Enter',
105
- });
106
- expect(document.activeElement === tab3).to.be.true;
107
- actionGroup3.focus();
108
- expect(document.activeElement === actionButton3).to.be.true;
109
- await sendKeys({
110
- press: 'ArrowLeft',
111
- });
112
- expect(document.activeElement === tab2).to.be.false;
113
- expect(actionGroup3.contains(document.activeElement)).to.be.true;
114
- const boundingRect = tab1.getBoundingClientRect();
115
- // tab1.click() doesn't current reach into the focus management here.
116
- await sendMouse({
117
- steps: [
118
- {
119
- type: 'click',
120
- position: [
121
- boundingRect.left + boundingRect.width / 2,
122
- boundingRect.top + boundingRect.height / 2,
123
- ],
124
- },
125
- ],
126
- });
127
- expect(document.activeElement === tab1).to.be.true;
128
- actionGroup1.focus();
129
- expect(document.activeElement === actionButton1).to.be.true;
130
- await sendKeys({
131
- press: 'ArrowRight',
132
- });
133
- expect(document.activeElement === tab2).to.be.false;
134
- expect(actionGroup1.contains(document.activeElement)).to.be.true;
135
- });
136
- });
137
- //# sourceMappingURL=reactive-controllers-integration.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reactive-controllers-integration.test.js","sourceRoot":"","sources":["reactive-controllers-integration.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,4DAA4D,CAAC;AAEpE,OAAO,0DAA0D,CAAC;AAElE,OAAO,+CAA+C,CAAC;AACvD,OAAO,yCAAyC,CAAC;AACjD,OAAO,0CAA0C,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,IAAI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AAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IACrE,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*/\nimport '@spectrum-web-components/action-button/sp-action-button.js';\nimport { ActionButton } from '@spectrum-web-components/action-button';\nimport '@spectrum-web-components/action-group/sp-action-group.js';\nimport { ActionGroup } from '@spectrum-web-components/action-group';\nimport '@spectrum-web-components/tabs/sp-tab-panel.js';\nimport '@spectrum-web-components/tabs/sp-tab.js';\nimport '@spectrum-web-components/tabs/sp-tabs.js';\nimport { Tab, TabPanel, Tabs } from '@spectrum-web-components/tabs';\nimport { elementUpdated, expect, fixture, nextFrame } from '@open-wc/testing';\nimport { html } from '@spectrum-web-components/base';\nimport { sendKeys } from '@web/test-runner-commands';\nimport { sendMouse } from '../../../test/plugins/browser.js';\n\nconst createTabs = async (): Promise<Tabs> => {\n const tabs = await fixture<Tabs>(\n html`\n <sp-tabs selected=\"second\">\n <sp-tab label=\"Tab 1\" value=\"first\"></sp-tab>\n <sp-tab label=\"Tab 2\" value=\"second\"></sp-tab>\n <sp-tab label=\"Tab 3\" value=\"third\"></sp-tab>\n <sp-tab-panel value=\"first\">\n <sp-action-group selects=\"single\">\n <sp-action-button selected value=\"1\">\n Single Button 1\n </sp-action-button>\n <sp-action-button value=\"2\">\n Single Button 2\n </sp-action-button>\n <sp-action-button value=\"3\">\n Single Button 3\n </sp-action-button>\n </sp-action-group>\n </sp-tab-panel>\n <sp-tab-panel value=\"second\">\n <sp-action-group selects=\"multiple\">\n <sp-action-button value=\"1\">\n Multiple Button 1\n </sp-action-button>\n <sp-action-button selected value=\"2\">\n Multiple Button 2\n </sp-action-button>\n <sp-action-button selected value=\"3\">\n Multiple Button 3\n </sp-action-button>\n </sp-action-group>\n </sp-tab-panel>\n <sp-tab-panel value=\"third\">\n <sp-action-group>\n <sp-action-button value=\"1\">\n None Button 1\n </sp-action-button>\n <sp-action-button value=\"2\">\n None Button 2\n </sp-action-button>\n <sp-action-button selected value=\"3\">\n None Button 3\n </sp-action-button>\n </sp-action-group>\n </sp-tab-panel>\n </sp-tabs>\n `\n );\n await elementUpdated(tabs);\n return tabs;\n};\n\ndescribe('Action Group inside of Tabs', () => {\n it('accurately navigates the desired element', async () => {\n const el = await createTabs();\n const tab1 = el.querySelector('sp-tab[value=\"first\"]') as Tab;\n const tab2 = el.querySelector('sp-tab[value=\"second\"]');\n const tab3 = el.querySelector('sp-tab[value=\"third\"]') as Tab;\n const tabPanel1 = el.querySelector(\n 'sp-tab-panel[value=\"first\"]'\n ) as TabPanel;\n const tabPanel2 = el.querySelector(\n 'sp-tab-panel[value=\"second\"]'\n ) as TabPanel;\n const tabPanel3 = el.querySelector(\n 'sp-tab-panel[value=\"third\"]'\n ) as TabPanel;\n const actionGroup1 = tabPanel1.querySelector(\n 'sp-action-group'\n ) as ActionGroup;\n const actionGroup2 = tabPanel2.querySelector(\n 'sp-action-group'\n ) as ActionGroup;\n const actionGroup3 = tabPanel3.querySelector(\n 'sp-action-group'\n ) as ActionGroup;\n const actionButton1 = actionGroup1.querySelector(\n '[selected]'\n ) as ActionButton;\n const actionButton2 = actionGroup2.querySelector(\n '[selected]'\n ) as ActionButton;\n const actionButton3 = actionGroup3.querySelector(\n '[selected]'\n ) as ActionButton;\n\n el.focus();\n expect(el.contains(document.activeElement)).to.be.true;\n expect(document.activeElement === tab2).to.be.true;\n\n actionGroup2.focus();\n expect(document.activeElement === actionButton2).to.be.true;\n\n await nextFrame();\n await sendKeys({\n press: 'ArrowLeft',\n });\n\n expect(document.activeElement === tab1).to.be.false;\n expect(actionGroup2.contains(document.activeElement)).to.be.true;\n\n el.focus();\n expect(document.activeElement === tab2).to.be.true;\n\n await sendKeys({\n press: 'ArrowRight',\n });\n\n expect(document.activeElement === tab3).to.be.true;\n\n await sendKeys({\n press: 'Enter',\n });\n\n expect(document.activeElement === tab3).to.be.true;\n\n actionGroup3.focus();\n expect(document.activeElement === actionButton3).to.be.true;\n\n await sendKeys({\n press: 'ArrowLeft',\n });\n\n expect(document.activeElement === tab2).to.be.false;\n expect(actionGroup3.contains(document.activeElement)).to.be.true;\n\n const boundingRect = tab1.getBoundingClientRect();\n // tab1.click() doesn't current reach into the focus management here.\n await sendMouse({\n steps: [\n {\n type: 'click',\n position: [\n boundingRect.left + boundingRect.width / 2,\n boundingRect.top + boundingRect.height / 2,\n ],\n },\n ],\n });\n expect(document.activeElement === tab1).to.be.true;\n\n actionGroup1.focus();\n expect(document.activeElement === actionButton1).to.be.true;\n\n await sendKeys({\n press: 'ArrowRight',\n });\n\n expect(document.activeElement === tab2).to.be.false;\n expect(actionGroup1.contains(document.activeElement)).to.be.true;\n });\n});\n"]}
@@ -1,27 +0,0 @@
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 { LitElement } from 'lit';
13
- import { expect } from '@open-wc/testing';
14
- import { RovingTabindexController } from '../';
15
- describe('RovingTabindex', () => {
16
- it('constructs with defaults', async () => {
17
- class TestEl extends LitElement {
18
- }
19
- customElements.define('test-roving-tabindex-el', TestEl);
20
- const el = new TestEl();
21
- const controller = new RovingTabindexController(el);
22
- expect(controller.direction).to.equal('both');
23
- expect(controller.focusInIndex).to.equal(0);
24
- expect(controller.isFocusableElement(el)).to.be.true;
25
- });
26
- });
27
- //# sourceMappingURL=reactive-controllers.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reactive-controllers.test.js","sourceRoot":"","sources":["reactive-controllers.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,KAAK,CAAC;AAE/C,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,0BAA0B,EAAE,KAAK,IAAI,EAAE;QACtC,MAAM,MAAO,SAAQ,UAAU;SAAG;QAClC,cAAc,CAAC,MAAM,CAAC,yBAAyB,EAAE,MAAM,CAAC,CAAC;QACzD,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,CAAC;QACxB,MAAM,UAAU,GAAG,IAAI,wBAAwB,CAC3C,EAA6C,CAChD,CAAC;QACF,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC9C,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC5C,MAAM,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IACzD,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 { LitElement } from 'lit';\nimport { expect } from '@open-wc/testing';\nimport { RovingTabindexController } from '../';\n\ndescribe('RovingTabindex', () => {\n it('constructs with defaults', async () => {\n class TestEl extends LitElement {}\n customElements.define('test-roving-tabindex-el', TestEl);\n const el = new TestEl();\n const controller = new RovingTabindexController(\n el as LitElement & { shadowRoot: ShadowRoot }\n );\n expect(controller.direction).to.equal('both');\n expect(controller.focusInIndex).to.equal(0);\n expect(controller.isFocusableElement(el)).to.be.true;\n });\n});\n"]}
@@ -1,137 +0,0 @@
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/action-button/sp-action-button.js';
13
- import '@spectrum-web-components/action-group/sp-action-group.js';
14
- import '@spectrum-web-components/tabs/sp-tab-panel.js';
15
- import '@spectrum-web-components/tabs/sp-tab.js';
16
- import '@spectrum-web-components/tabs/sp-tabs.js';
17
- import { elementUpdated, expect, fixture, nextFrame } from '@open-wc/testing';
18
- import { html } from '@spectrum-web-components/base';
19
- import { sendKeys } from '@web/test-runner-commands';
20
- import { sendMouse } from '../../../test/plugins/browser.js';
21
- const createTabs = async () => {
22
- const tabs = await fixture(html `
23
- <sp-tabs selected="second">
24
- <sp-tab label="Tab 1" value="first"></sp-tab>
25
- <sp-tab label="Tab 2" value="second"></sp-tab>
26
- <sp-tab label="Tab 3" value="third"></sp-tab>
27
- <sp-tab-panel value="first">
28
- <sp-action-group selects="single">
29
- <sp-action-button selected value="1">
30
- Single Button 1
31
- </sp-action-button>
32
- <sp-action-button value="2">
33
- Single Button 2
34
- </sp-action-button>
35
- <sp-action-button value="3">
36
- Single Button 3
37
- </sp-action-button>
38
- </sp-action-group>
39
- </sp-tab-panel>
40
- <sp-tab-panel value="second">
41
- <sp-action-group selects="multiple">
42
- <sp-action-button value="1">
43
- Multiple Button 1
44
- </sp-action-button>
45
- <sp-action-button selected value="2">
46
- Multiple Button 2
47
- </sp-action-button>
48
- <sp-action-button selected value="3">
49
- Multiple Button 3
50
- </sp-action-button>
51
- </sp-action-group>
52
- </sp-tab-panel>
53
- <sp-tab-panel value="third">
54
- <sp-action-group>
55
- <sp-action-button value="1">
56
- None Button 1
57
- </sp-action-button>
58
- <sp-action-button value="2">
59
- None Button 2
60
- </sp-action-button>
61
- <sp-action-button selected value="3">
62
- None Button 3
63
- </sp-action-button>
64
- </sp-action-group>
65
- </sp-tab-panel>
66
- </sp-tabs>
67
- `);
68
- await elementUpdated(tabs);
69
- return tabs;
70
- };
71
- describe('Action Group inside of Tabs', () => {
72
- it('accurately navigates the desired element', async () => {
73
- const el = await createTabs();
74
- const tab1 = el.querySelector('sp-tab[value="first"]');
75
- const tab2 = el.querySelector('sp-tab[value="second"]');
76
- const tab3 = el.querySelector('sp-tab[value="third"]');
77
- const tabPanel1 = el.querySelector('sp-tab-panel[value="first"]');
78
- const tabPanel2 = el.querySelector('sp-tab-panel[value="second"]');
79
- const tabPanel3 = el.querySelector('sp-tab-panel[value="third"]');
80
- const actionGroup1 = tabPanel1.querySelector('sp-action-group');
81
- const actionGroup2 = tabPanel2.querySelector('sp-action-group');
82
- const actionGroup3 = tabPanel3.querySelector('sp-action-group');
83
- const actionButton1 = actionGroup1.querySelector('[selected]');
84
- const actionButton2 = actionGroup2.querySelector('[selected]');
85
- const actionButton3 = actionGroup3.querySelector('[selected]');
86
- el.focus();
87
- expect(el.contains(document.activeElement)).to.be.true;
88
- expect(document.activeElement === tab2).to.be.true;
89
- actionGroup2.focus();
90
- expect(document.activeElement === actionButton2).to.be.true;
91
- await nextFrame();
92
- await sendKeys({
93
- press: 'ArrowLeft',
94
- });
95
- expect(document.activeElement === tab1).to.be.false;
96
- expect(actionGroup2.contains(document.activeElement)).to.be.true;
97
- el.focus();
98
- expect(document.activeElement === tab2).to.be.true;
99
- await sendKeys({
100
- press: 'ArrowRight',
101
- });
102
- expect(document.activeElement === tab3).to.be.true;
103
- await sendKeys({
104
- press: 'Enter',
105
- });
106
- expect(document.activeElement === tab3).to.be.true;
107
- actionGroup3.focus();
108
- expect(document.activeElement === actionButton3).to.be.true;
109
- await sendKeys({
110
- press: 'ArrowLeft',
111
- });
112
- expect(document.activeElement === tab2).to.be.false;
113
- expect(actionGroup3.contains(document.activeElement)).to.be.true;
114
- const boundingRect = tab1.getBoundingClientRect();
115
- // tab1.click() doesn't current reach into the focus management here.
116
- await sendMouse({
117
- steps: [
118
- {
119
- type: 'click',
120
- position: [
121
- boundingRect.left + boundingRect.width / 2,
122
- boundingRect.top + boundingRect.height / 2,
123
- ],
124
- },
125
- ],
126
- });
127
- expect(document.activeElement === tab1).to.be.true;
128
- actionGroup1.focus();
129
- expect(document.activeElement === actionButton1).to.be.true;
130
- await sendKeys({
131
- press: 'ArrowRight',
132
- });
133
- expect(document.activeElement === tab2).to.be.false;
134
- expect(actionGroup1.contains(document.activeElement)).to.be.true;
135
- });
136
- });
137
- //# sourceMappingURL=roving-tabindex-integration.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"roving-tabindex-integration.test.js","sourceRoot":"","sources":["roving-tabindex-integration.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,4DAA4D,CAAC;AAEpE,OAAO,0DAA0D,CAAC;AAElE,OAAO,+CAA+C,CAAC;AACvD,OAAO,yCAAyC,CAAC;AACjD,OAAO,0CAA0C,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,E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AK,CAAC;QACpD,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IACrE,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*/\nimport '@spectrum-web-components/action-button/sp-action-button.js';\nimport { ActionButton } from '@spectrum-web-components/action-button';\nimport '@spectrum-web-components/action-group/sp-action-group.js';\nimport { ActionGroup } from '@spectrum-web-components/action-group';\nimport '@spectrum-web-components/tabs/sp-tab-panel.js';\nimport '@spectrum-web-components/tabs/sp-tab.js';\nimport '@spectrum-web-components/tabs/sp-tabs.js';\nimport { Tab, TabPanel, Tabs } from '@spectrum-web-components/tabs';\nimport { elementUpdated, expect, fixture, nextFrame } from '@open-wc/testing';\nimport { html } from '@spectrum-web-components/base';\nimport { sendKeys } from '@web/test-runner-commands';\nimport { sendMouse } from '../../../test/plugins/browser.js';\n\nconst createTabs = async (): Promise<Tabs> => {\n const tabs = await fixture<Tabs>(\n html`\n <sp-tabs selected=\"second\">\n <sp-tab label=\"Tab 1\" value=\"first\"></sp-tab>\n <sp-tab label=\"Tab 2\" value=\"second\"></sp-tab>\n <sp-tab label=\"Tab 3\" value=\"third\"></sp-tab>\n <sp-tab-panel value=\"first\">\n <sp-action-group selects=\"single\">\n <sp-action-button selected value=\"1\">\n Single Button 1\n </sp-action-button>\n <sp-action-button value=\"2\">\n Single Button 2\n </sp-action-button>\n <sp-action-button value=\"3\">\n Single Button 3\n </sp-action-button>\n </sp-action-group>\n </sp-tab-panel>\n <sp-tab-panel value=\"second\">\n <sp-action-group selects=\"multiple\">\n <sp-action-button value=\"1\">\n Multiple Button 1\n </sp-action-button>\n <sp-action-button selected value=\"2\">\n Multiple Button 2\n </sp-action-button>\n <sp-action-button selected value=\"3\">\n Multiple Button 3\n </sp-action-button>\n </sp-action-group>\n </sp-tab-panel>\n <sp-tab-panel value=\"third\">\n <sp-action-group>\n <sp-action-button value=\"1\">\n None Button 1\n </sp-action-button>\n <sp-action-button value=\"2\">\n None Button 2\n </sp-action-button>\n <sp-action-button selected value=\"3\">\n None Button 3\n </sp-action-button>\n </sp-action-group>\n </sp-tab-panel>\n </sp-tabs>\n `\n );\n await elementUpdated(tabs);\n return tabs;\n};\n\ndescribe('Action Group inside of Tabs', () => {\n it('accurately navigates the desired element', async () => {\n const el = await createTabs();\n const tab1 = el.querySelector('sp-tab[value=\"first\"]') as Tab;\n const tab2 = el.querySelector('sp-tab[value=\"second\"]');\n const tab3 = el.querySelector('sp-tab[value=\"third\"]') as Tab;\n const tabPanel1 = el.querySelector(\n 'sp-tab-panel[value=\"first\"]'\n ) as TabPanel;\n const tabPanel2 = el.querySelector(\n 'sp-tab-panel[value=\"second\"]'\n ) as TabPanel;\n const tabPanel3 = el.querySelector(\n 'sp-tab-panel[value=\"third\"]'\n ) as TabPanel;\n const actionGroup1 = tabPanel1.querySelector(\n 'sp-action-group'\n ) as ActionGroup;\n const actionGroup2 = tabPanel2.querySelector(\n 'sp-action-group'\n ) as ActionGroup;\n const actionGroup3 = tabPanel3.querySelector(\n 'sp-action-group'\n ) as ActionGroup;\n const actionButton1 = actionGroup1.querySelector(\n '[selected]'\n ) as ActionButton;\n const actionButton2 = actionGroup2.querySelector(\n '[selected]'\n ) as ActionButton;\n const actionButton3 = actionGroup3.querySelector(\n '[selected]'\n ) as ActionButton;\n\n el.focus();\n expect(el.contains(document.activeElement)).to.be.true;\n expect(document.activeElement === tab2).to.be.true;\n\n actionGroup2.focus();\n expect(document.activeElement === actionButton2).to.be.true;\n\n await nextFrame();\n await sendKeys({\n press: 'ArrowLeft',\n });\n\n expect(document.activeElement === tab1).to.be.false;\n expect(actionGroup2.contains(document.activeElement)).to.be.true;\n\n el.focus();\n expect(document.activeElement === tab2).to.be.true;\n\n await sendKeys({\n press: 'ArrowRight',\n });\n\n expect(document.activeElement === tab3).to.be.true;\n\n await sendKeys({\n press: 'Enter',\n });\n\n expect(document.activeElement === tab3).to.be.true;\n\n actionGroup3.focus();\n expect(document.activeElement === actionButton3).to.be.true;\n\n await sendKeys({\n press: 'ArrowLeft',\n });\n\n expect(document.activeElement === tab2).to.be.false;\n expect(actionGroup3.contains(document.activeElement)).to.be.true;\n\n const boundingRect = tab1.getBoundingClientRect();\n // tab1.click() doesn't current reach into the focus management here.\n await sendMouse({\n steps: [\n {\n type: 'click',\n position: [\n boundingRect.left + boundingRect.width / 2,\n boundingRect.top + boundingRect.height / 2,\n ],\n },\n ],\n });\n expect(document.activeElement === tab1).to.be.true;\n\n actionGroup1.focus();\n expect(document.activeElement === actionButton1).to.be.true;\n\n await sendKeys({\n press: 'ArrowRight',\n });\n\n expect(document.activeElement === tab2).to.be.false;\n expect(actionGroup1.contains(document.activeElement)).to.be.true;\n });\n});\n"]}
@@ -1,27 +0,0 @@
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 { LitElement } from 'lit';
13
- import { expect } from '@open-wc/testing';
14
- import { RovingTabindexController } from '../src';
15
- describe('RovingTabindex', () => {
16
- it('constructs with defaults', async () => {
17
- class TestEl extends LitElement {
18
- }
19
- customElements.define('test-roving-tabindex-el', TestEl);
20
- const el = new TestEl();
21
- const controller = new RovingTabindexController(el);
22
- expect(controller.direction).to.equal('both');
23
- expect(controller.focusInIndex).to.equal(0);
24
- expect(controller.isFocusableElement(el)).to.be.true;
25
- });
26
- });
27
- //# sourceMappingURL=roving-tabindex.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"roving-tabindex.test.js","sourceRoot":"","sources":["roving-tabindex.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAElD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,0BAA0B,EAAE,KAAK,IAAI,EAAE;QACtC,MAAM,MAAO,SAAQ,UAAU;SAAG;QAClC,cAAc,CAAC,MAAM,CAAC,yBAAyB,EAAE,MAAM,CAAC,CAAC;QACzD,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,CAAC;QACxB,MAAM,UAAU,GAAG,IAAI,wBAAwB,CAC3C,EAA6C,CAChD,CAAC;QACF,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC9C,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC5C,MAAM,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IACzD,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 { LitElement } from 'lit';\nimport { expect } from '@open-wc/testing';\nimport { RovingTabindexController } from '../src';\n\ndescribe('RovingTabindex', () => {\n it('constructs with defaults', async () => {\n class TestEl extends LitElement {}\n customElements.define('test-roving-tabindex-el', TestEl);\n const el = new TestEl();\n const controller = new RovingTabindexController(\n el as LitElement & { shadowRoot: ShadowRoot }\n );\n expect(controller.direction).to.equal('both');\n expect(controller.focusInIndex).to.equal(0);\n expect(controller.isFocusableElement(el)).to.be.true;\n });\n});\n"]}