@spectrum-web-components/accordion 0.4.16 → 0.4.18

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.
@@ -155,7 +155,7 @@
155
155
  "privacy": "private",
156
156
  "return": {
157
157
  "type": {
158
- "text": "void"
158
+ "text": "Promise<void>"
159
159
  }
160
160
  },
161
161
  "parameters": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/accordion",
3
- "version": "0.4.16",
3
+ "version": "0.4.18",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -49,7 +49,7 @@
49
49
  "@spectrum-web-components/base": "^0.4.5",
50
50
  "@spectrum-web-components/icon": "^0.9.11",
51
51
  "@spectrum-web-components/icons-ui": "^0.6.11",
52
- "@spectrum-web-components/shared": "^0.12.8",
52
+ "@spectrum-web-components/shared": "^0.12.9",
53
53
  "tslib": "^2.0.0"
54
54
  },
55
55
  "devDependencies": {
@@ -60,5 +60,5 @@
60
60
  "sideEffects": [
61
61
  "./sp-*.js"
62
62
  ],
63
- "gitHead": "d7f2ca747a902cf8b632cc8491fa675419297180"
63
+ "gitHead": "e05c867a446189df8cfbceb201ec18cd502cfe26"
64
64
  }
package/src/Accordion.js CHANGED
@@ -92,20 +92,27 @@ export class Accordion extends Focusable {
92
92
  }
93
93
  nextItem.focus();
94
94
  }
95
- onToggle(event) {
95
+ async onToggle(event) {
96
+ // Let the event pass through the DOM so that it can be
97
+ // prevented from the outside if a user so desires.
98
+ await 0;
99
+ if (this.allowMultiple || event.defaultPrevented) {
100
+ // No toggling when `allowMultiple` or the user prevents it.
101
+ return;
102
+ }
96
103
  const target = event.target;
97
104
  const items = [...this.items];
98
105
  /* c8 ignore next 3 */
99
106
  if (items && !items.length) {
107
+ // no toggling when there aren't items.
100
108
  return;
101
109
  }
102
- if (!this.allowMultiple && !event.defaultPrevented) {
103
- items.forEach((item) => {
104
- if (item.open && item !== target) {
105
- item.open = false;
106
- }
107
- });
108
- }
110
+ items.forEach((item) => {
111
+ if (item !== target) {
112
+ // Close all the items that didn't dispatch the event.
113
+ item.open = false;
114
+ }
115
+ });
109
116
  }
110
117
  render() {
111
118
  return html `
@@ -1 +1 @@
1
- {"version":3,"file":"Accordion.js","sourceRoot":"","sources":["Accordion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EACH,IAAI,EAGJ,QAAQ,EAER,kBAAkB,GACrB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAE9E;;;GAGG;AACH,MAAM,OAAO,SAAU,SAAQ,SAAS;IAAxC;;QAKI;;WAEG;QAEI,kBAAa,GAAG,KAAK,CAAC;IA4GjC,CAAC;IApHU,MAAM,KAAK,MAAM;QACpB,OAAO,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;IAWD,IAAY,KAAK;QACb,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CACxC,CAAC,IAAiB,EAAE,EAAE,CAAC,OAAO,IAAI,CAAC,OAAO,KAAK,WAAW,CAC1C,CAAC;IACzB,CAAC;IAEM,KAAK;QACR,IAAI,IAAI,CAAC,YAAY,KAAK,IAAI,EAAE;YAC5B,OAAO;SACV;QAED,KAAK,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;IAED;;OAEG;IACH,IAAW,YAAY;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YACxB,OAAO,IAAI,CAAC;SACf;QACD,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,OAAO,KAAK,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,C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ACJ;AA5GG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC;gDAC3C;AAG7B;IADC,kBAAkB,EAAE;+CAC4B","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 html,\n CSSResultArray,\n TemplateResult,\n property,\n PropertyValues,\n queryAssignedNodes,\n} from '@spectrum-web-components/base';\n\nimport { AccordionItem } from './AccordionItem.js';\n\nimport styles from './accordion.css.js';\nimport { Focusable, getActiveElement } from '@spectrum-web-components/shared';\n\n/**\n * @element sp-accordion\n * @slot - The sp-accordion-item children to display.\n */\nexport class Accordion extends Focusable {\n public static get styles(): CSSResultArray {\n return [styles];\n }\n\n /**\n * Allows multiple accordion items to be opened at the same time\n */\n @property({ type: Boolean, reflect: true, attribute: 'allow-multiple' })\n public allowMultiple = false;\n\n @queryAssignedNodes()\n private defaultNodes!: NodeListOf<AccordionItem>;\n\n private get items(): AccordionItem[] {\n return [...(this.defaultNodes || [])].filter(\n (node: HTMLElement) => typeof node.tagName !== 'undefined'\n ) as AccordionItem[];\n }\n\n public focus(): void {\n if (this.focusElement === this) {\n return;\n }\n\n super.focus();\n }\n\n /**\n * @private\n */\n public get focusElement(): Accordion | AccordionItem {\n const items = this.items;\n if (items && !items.length) {\n return this;\n }\n let index = 0;\n while (index < items.length && items[index] && items[index].disabled) {\n index += 1;\n }\n if (items[index]) {\n return items[index];\n }\n /* c8 ignore next */\n return this;\n }\n\n public startListeningToKeyboard(): void {\n const items = this.items;\n /* c8 ignore next 3 */\n if (items && !items.length) {\n return;\n }\n this.addEventListener('keydown', this.handleKeydown);\n }\n\n public stopListeningToKeyboard(): void {\n this.removeEventListener('keydown', this.handleKeydown);\n }\n\n private handleKeydown(event: KeyboardEvent): void {\n const { code } = event;\n /* c8 ignore next 3 */\n if (code !== 'ArrowDown' && code !== 'ArrowUp') {\n return;\n }\n event.preventDefault();\n const direction = code === 'ArrowDown' ? 1 : -1;\n this.focusItemByOffset(direction);\n }\n\n private focusItemByOffset(direction: number): void {\n const items = this.items;\n const focused = items.indexOf(getActiveElement(this) as AccordionItem);\n let next = focused;\n let nextItem = items[next];\n // cycle through the available items in the directions of the offset to find the next non-disabled item\n while (nextItem && (nextItem.disabled || next === focused)) {\n next = (items.length + next + direction) % items.length;\n nextItem = items[next];\n }\n // if there are no non-disabled items, skip the work to focus a child\n if (!nextItem || nextItem.disabled || next === focused) {\n return;\n }\n nextItem.focus();\n }\n\n private onToggle(event: Event): void {\n const target = event.target as AccordionItem;\n const items = [...this.items] as AccordionItem[];\n /* c8 ignore next 3 */\n if (items && !items.length) {\n return;\n }\n if (!this.allowMultiple && !event.defaultPrevented) {\n items.forEach((item) => {\n if (item.open && item !== target) {\n item.open = false;\n }\n });\n }\n }\n\n protected render(): TemplateResult {\n return html`\n <slot></slot>\n `;\n }\n\n protected firstUpdated(changed: PropertyValues): void {\n super.firstUpdated(changed);\n\n this.addEventListener('focusin', this.startListeningToKeyboard);\n this.addEventListener('focusout', this.stopListeningToKeyboard);\n this.addEventListener('sp-accordion-item-toggle', this.onToggle);\n }\n}\n"]}
1
+ {"version":3,"file":"Accordion.js","sourceRoot":"","sources":["Accordion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EACH,IAAI,EAGJ,QAAQ,EAER,kBAAkB,GACrB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,M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DAAmD;QACnD,MAAM,CAAC,CAAC;QACR,IAAI,IAAI,CAAC,aAAa,IAAI,KAAK,CAAC,gBAAgB,EAAE;YAC9C,4DAA4D;YAC5D,OAAO;SACV;QACD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAuB,CAAC;QAC7C,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAoB,CAAC;QACjD,sBAAsB;QACtB,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YACxB,uCAAuC;YACvC,OAAO;SACV;QACD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACnB,IAAI,IAAI,KAAK,MAAM,EAAE;gBACjB,sDAAsD;gBACtD,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;aACrB;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAES,MAAM;QACZ,OAAO,IAAI,CAAA;;SAEV,CAAC;IACN,CAAC;IAES,YAAY,CAAC,OAAuB;QAC1C,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAE5B,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,wBAAwB,CAAC,CAAC;QAChE,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;QAChE,IAAI,CAAC,gBAAgB,CAAC,0BAA0B,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrE,CAAC;CACJ;AAnHG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC;gDAC3C;AAG7B;IADC,kBAAkB,EAAE;+CAC4B","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 html,\n CSSResultArray,\n TemplateResult,\n property,\n PropertyValues,\n queryAssignedNodes,\n} from '@spectrum-web-components/base';\n\nimport { AccordionItem } from './AccordionItem.js';\n\nimport styles from './accordion.css.js';\nimport { Focusable, getActiveElement } from '@spectrum-web-components/shared';\n\n/**\n * @element sp-accordion\n * @slot - The sp-accordion-item children to display.\n */\nexport class Accordion extends Focusable {\n public static get styles(): CSSResultArray {\n return [styles];\n }\n\n /**\n * Allows multiple accordion items to be opened at the same time\n */\n @property({ type: Boolean, reflect: true, attribute: 'allow-multiple' })\n public allowMultiple = false;\n\n @queryAssignedNodes()\n private defaultNodes!: NodeListOf<AccordionItem>;\n\n private get items(): AccordionItem[] {\n return [...(this.defaultNodes || [])].filter(\n (node: HTMLElement) => typeof node.tagName !== 'undefined'\n ) as AccordionItem[];\n }\n\n public focus(): void {\n if (this.focusElement === this) {\n return;\n }\n\n super.focus();\n }\n\n /**\n * @private\n */\n public get focusElement(): Accordion | AccordionItem {\n const items = this.items;\n if (items && !items.length) {\n return this;\n }\n let index = 0;\n while (index < items.length && items[index] && items[index].disabled) {\n index += 1;\n }\n if (items[index]) {\n return items[index];\n }\n /* c8 ignore next */\n return this;\n }\n\n public startListeningToKeyboard(): void {\n const items = this.items;\n /* c8 ignore next 3 */\n if (items && !items.length) {\n return;\n }\n this.addEventListener('keydown', this.handleKeydown);\n }\n\n public stopListeningToKeyboard(): void {\n this.removeEventListener('keydown', this.handleKeydown);\n }\n\n private handleKeydown(event: KeyboardEvent): void {\n const { code } = event;\n /* c8 ignore next 3 */\n if (code !== 'ArrowDown' && code !== 'ArrowUp') {\n return;\n }\n event.preventDefault();\n const direction = code === 'ArrowDown' ? 1 : -1;\n this.focusItemByOffset(direction);\n }\n\n private focusItemByOffset(direction: number): void {\n const items = this.items;\n const focused = items.indexOf(getActiveElement(this) as AccordionItem);\n let next = focused;\n let nextItem = items[next];\n // cycle through the available items in the directions of the offset to find the next non-disabled item\n while (nextItem && (nextItem.disabled || next === focused)) {\n next = (items.length + next + direction) % items.length;\n nextItem = items[next];\n }\n // if there are no non-disabled items, skip the work to focus a child\n if (!nextItem || nextItem.disabled || next === focused) {\n return;\n }\n nextItem.focus();\n }\n\n private async onToggle(event: Event): Promise<void> {\n // Let the event pass through the DOM so that it can be\n // prevented from the outside if a user so desires.\n await 0;\n if (this.allowMultiple || event.defaultPrevented) {\n // No toggling when `allowMultiple` or the user prevents it.\n return;\n }\n const target = event.target as AccordionItem;\n const items = [...this.items] as AccordionItem[];\n /* c8 ignore next 3 */\n if (items && !items.length) {\n // no toggling when there aren't items.\n return;\n }\n items.forEach((item) => {\n if (item !== target) {\n // Close all the items that didn't dispatch the event.\n item.open = false;\n }\n });\n }\n\n protected render(): TemplateResult {\n return html`\n <slot></slot>\n `;\n }\n\n protected firstUpdated(changed: PropertyValues): void {\n super.firstUpdated(changed);\n\n this.addEventListener('focusin', this.startListeningToKeyboard);\n this.addEventListener('focusout', this.stopListeningToKeyboard);\n this.addEventListener('sp-accordion-item-toggle', this.onToggle);\n }\n}\n"]}