@oicl/openbridge-webcomponents-full-bundle 2.0.0-next.172 → 2.0.0-next.173
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/bundle/openbridge-webcomponents.bundle.js +182 -35
- package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
- package/custom-elements.json +45 -5
- package/dist/components/accordion-card/accordion-card.css.js +61 -19
- package/dist/components/accordion-card/accordion-card.css.js.map +1 -1
- package/dist/components/accordion-card/accordion-card.d.ts +12 -3
- package/dist/components/accordion-card/accordion-card.d.ts.map +1 -1
- package/dist/components/accordion-card/accordion-card.js +23 -5
- package/dist/components/accordion-card/accordion-card.js.map +1 -1
- package/dist/components/accordion-item/accordion-item.css.js +40 -9
- package/dist/components/accordion-item/accordion-item.css.js.map +1 -1
- package/dist/components/accordion-item/accordion-item.d.ts +14 -5
- package/dist/components/accordion-item/accordion-item.d.ts.map +1 -1
- package/dist/components/accordion-item/accordion-item.js +23 -3
- package/dist/components/accordion-item/accordion-item.js.map +1 -1
- package/dist/internal/focus.d.ts +23 -0
- package/dist/internal/focus.d.ts.map +1 -1
- package/dist/internal/focus.js +38 -1
- package/dist/internal/focus.js.map +1 -1
- package/package.json +1 -1
- package/src/components/accordion-card/accordion-card.css +57 -15
- package/src/components/accordion-card/accordion-card.spec.ts +171 -0
- package/src/components/accordion-card/accordion-card.ts +32 -12
- package/src/components/accordion-item/accordion-item.css +40 -9
- package/src/components/accordion-item/accordion-item.spec.ts +161 -0
- package/src/components/accordion-item/accordion-item.ts +34 -9
- package/src/internal/_test-utils.ts +3 -12
- package/src/internal/focus.ts +45 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LitElement } from 'lit';
|
|
1
|
+
import { LitElement, PropertyValues } from 'lit';
|
|
2
2
|
import '../../icons/icon-chevron-down-google.js';
|
|
3
3
|
/**
|
|
4
4
|
* `<obc-accordion-item>` – A collapsible section component for toggling the visibility of content panels (commonly known as an accordion item, expandable panel, or disclosure).
|
|
@@ -6,11 +6,10 @@ import '../../icons/icon-chevron-down-google.js';
|
|
|
6
6
|
* Provides a single expandable/collapsible section with a clickable header and an optional content area. Useful for organizing related information in a compact, vertically stacked layout, allowing users to reveal or hide details as needed.
|
|
7
7
|
*
|
|
8
8
|
* ### Features
|
|
9
|
-
* - **Toggleable Expansion:** Click the header to expand or collapse the content area. The
|
|
9
|
+
* - **Toggleable Expansion:** Click the header to expand or collapse the content area. The panel slides open and closed, and the chevron turns with it; `prefers-reduced-motion: reduce` switches instantly instead.
|
|
10
10
|
* - **Disabled State:** Prevents user interaction and visually indicates non-interactivity.
|
|
11
11
|
* - **Customizable Content:** Slot for custom expanded content (`expanded-content`), supporting any HTML or component.
|
|
12
12
|
* - **Optional Divider:** Can display a divider line below the item for visual separation in lists.
|
|
13
|
-
* - **Show/Hide Content Area:** Optionally hide the expanded content area entirely (e.g., for header-only items).
|
|
14
13
|
* - **Accessible:** Uses a button for the header with appropriate ARIA attributes for accessibility.
|
|
15
14
|
*
|
|
16
15
|
* ### Usage Guidelines
|
|
@@ -27,7 +26,7 @@ import '../../icons/icon-chevron-down-google.js';
|
|
|
27
26
|
* ### Slots
|
|
28
27
|
* | Slot Name | Renders When... | Purpose |
|
|
29
28
|
* |-------------------|--------------------------|-------------------------------------------------|
|
|
30
|
-
* | expanded-content |
|
|
29
|
+
* | expanded-content | Always | Custom content revealed while the item is open |
|
|
31
30
|
*
|
|
32
31
|
* ### Events
|
|
33
32
|
* - `accordion-item-toggle` – Fired when the item is toggled open or closed. Event detail: `{ open: boolean, title: string }`
|
|
@@ -52,8 +51,9 @@ import '../../icons/icon-chevron-down-google.js';
|
|
|
52
51
|
* @property disabled - Disables the accordion item, preventing user interaction and dimming the appearance.
|
|
53
52
|
* @property showDivider - Displays a divider line below the item for visual separation.
|
|
54
53
|
* Useful when stacking multiple items in a list.
|
|
55
|
-
* @slot expanded-content - Content
|
|
54
|
+
* @slot expanded-content - Content revealed while the item is open.
|
|
56
55
|
* @fires {CustomEvent<{open: boolean, title: string}>} accordion-item-toggle - Fired when the item is toggled open or closed.
|
|
56
|
+
* @cssprop [--obc-accordion-expand-duration=200ms] - How long the panel takes to open and close. The chevron and the header's corners follow it. Ignored under `prefers-reduced-motion: reduce`.
|
|
57
57
|
* @stable
|
|
58
58
|
*/
|
|
59
59
|
export declare class ObcAccordionItem extends LitElement {
|
|
@@ -66,6 +66,15 @@ export declare class ObcAccordionItem extends LitElement {
|
|
|
66
66
|
/** Displays a divider line below the item for visual separation. Useful when stacking multiple items in a list. */
|
|
67
67
|
showDivider: boolean;
|
|
68
68
|
private handleToggle;
|
|
69
|
+
/**
|
|
70
|
+
* Keeps the keyboard somewhere predictable when the panel closes.
|
|
71
|
+
*
|
|
72
|
+
* A collapsed panel is `inert`, and the browser drops focus out of anything
|
|
73
|
+
* it makes inert — onto `<body>`, two frames later. Clicking the header
|
|
74
|
+
* already leaves focus there; a consumer setting `open` while a slotted
|
|
75
|
+
* control has focus is the case that needs the transfer.
|
|
76
|
+
*/
|
|
77
|
+
willUpdate(changed: PropertyValues<this>): void;
|
|
69
78
|
private renderContent;
|
|
70
79
|
private renderExpandedContent;
|
|
71
80
|
private renderDivider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accordion-item.d.ts","sourceRoot":"","sources":["../../../src/components/accordion-item/accordion-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"accordion-item.d.ts","sourceRoot":"","sources":["../../../src/components/accordion-item/accordion-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAmB,KAAK,cAAc,EAAC,MAAM,KAAK,CAAC;AAMrE,OAAO,yCAAyC,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,qBACa,gBAAiB,SAAQ,UAAU;IACX,KAAK,SAAM;IAEnB,IAAI,UAAS;IAEb,QAAQ,UAAS;IAEjB,WAAW,UAAS;IAE/C,OAAO,CAAC,YAAY;IAepB;;;;;;;OAOG;IACM,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;IAYjD,OAAO,CAAC,aAAa;IAerB,OAAO,CAAC,qBAAqB;IAY7B,OAAO,CAAC,aAAa;IAMZ,MAAM;IA0Bf,OAAgB,MAAM,0BAA6B;CACpD;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,oBAAoB,EAAE,gBAAgB,CAAC;KACxC;CACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { customElement } from "../../decorator.js";
|
|
2
2
|
import __decorate from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/decorate.js";
|
|
3
3
|
import "../../icons/icon-chevron-down-google.js";
|
|
4
|
+
import { releaseFocusBefore } from "../../internal/focus.js";
|
|
4
5
|
import accordion_item_default from "./accordion-item.css.js";
|
|
5
6
|
import { LitElement, html, unsafeCSS } from "lit";
|
|
6
7
|
import { property } from "lit/decorators.js";
|
|
@@ -22,6 +23,20 @@ var ObcAccordionItem = class ObcAccordionItem extends LitElement {
|
|
|
22
23
|
title: this.title
|
|
23
24
|
} }));
|
|
24
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Keeps the keyboard somewhere predictable when the panel closes.
|
|
28
|
+
*
|
|
29
|
+
* A collapsed panel is `inert`, and the browser drops focus out of anything
|
|
30
|
+
* it makes inert — onto `<body>`, two frames later. Clicking the header
|
|
31
|
+
* already leaves focus there; a consumer setting `open` while a slotted
|
|
32
|
+
* control has focus is the case that needs the transfer.
|
|
33
|
+
*/
|
|
34
|
+
willUpdate(changed) {
|
|
35
|
+
if (!changed.has("open") || this.open) return;
|
|
36
|
+
const panel = this.shadowRoot?.querySelector(".panel");
|
|
37
|
+
if (!panel) return;
|
|
38
|
+
releaseFocusBefore(panel, this.shadowRoot?.querySelector(".content-button"), this.shadowRoot?.querySelector(".wrapper"));
|
|
39
|
+
}
|
|
25
40
|
renderContent() {
|
|
26
41
|
return html`
|
|
27
42
|
<div class="content">
|
|
@@ -37,10 +52,13 @@ var ObcAccordionItem = class ObcAccordionItem extends LitElement {
|
|
|
37
52
|
`;
|
|
38
53
|
}
|
|
39
54
|
renderExpandedContent() {
|
|
40
|
-
if (!this.open) return "";
|
|
41
55
|
return html`
|
|
42
|
-
<div class="content
|
|
43
|
-
<
|
|
56
|
+
<div class="panel" id="accordion-content" ?inert=${!this.open}>
|
|
57
|
+
<div class="panel-inner">
|
|
58
|
+
<div class="content-container">
|
|
59
|
+
<slot name="expanded-content"></slot>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
44
62
|
</div>
|
|
45
63
|
`;
|
|
46
64
|
}
|
|
@@ -51,6 +69,7 @@ var ObcAccordionItem = class ObcAccordionItem extends LitElement {
|
|
|
51
69
|
render() {
|
|
52
70
|
return html`
|
|
53
71
|
<div
|
|
72
|
+
tabindex="-1"
|
|
54
73
|
class=${classMap({
|
|
55
74
|
wrapper: true,
|
|
56
75
|
"state-disabled": this.disabled,
|
|
@@ -63,6 +82,7 @@ var ObcAccordionItem = class ObcAccordionItem extends LitElement {
|
|
|
63
82
|
@click=${this.handleToggle}
|
|
64
83
|
?disabled=${this.disabled}
|
|
65
84
|
aria-expanded=${this.open}
|
|
85
|
+
aria-controls="accordion-content"
|
|
66
86
|
>
|
|
67
87
|
${this.renderContent()}
|
|
68
88
|
</button>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accordion-item.js","names":[],"sources":["../../../src/components/accordion-item/accordion-item.ts"],"sourcesContent":["import {LitElement, html, unsafeCSS} from 'lit';\nimport {customElement} from '../../decorator.js';\nimport {classMap} from 'lit/directives/class-map.js';\nimport componentStyle from './accordion-item.css?inline';\nimport {property} from 'lit/decorators.js';\nimport '../../icons/icon-chevron-down-google.js';\n\n/**\n * `<obc-accordion-item>` – A collapsible section component for toggling the visibility of content panels (commonly known as an accordion item, expandable panel, or disclosure).\n *\n * Provides a single expandable/collapsible section with a clickable header and an optional content area. Useful for organizing related information in a compact, vertically stacked layout, allowing users to reveal or hide details as needed.\n *\n * ### Features\n * - **Toggleable Expansion:** Click the header to expand or collapse the content area. The
|
|
1
|
+
{"version":3,"file":"accordion-item.js","names":[],"sources":["../../../src/components/accordion-item/accordion-item.ts"],"sourcesContent":["import {LitElement, html, unsafeCSS, type PropertyValues} from 'lit';\nimport {customElement} from '../../decorator.js';\nimport {releaseFocusBefore} from '../../internal/focus.js';\nimport {classMap} from 'lit/directives/class-map.js';\nimport componentStyle from './accordion-item.css?inline';\nimport {property} from 'lit/decorators.js';\nimport '../../icons/icon-chevron-down-google.js';\n\n/**\n * `<obc-accordion-item>` – A collapsible section component for toggling the visibility of content panels (commonly known as an accordion item, expandable panel, or disclosure).\n *\n * Provides a single expandable/collapsible section with a clickable header and an optional content area. Useful for organizing related information in a compact, vertically stacked layout, allowing users to reveal or hide details as needed.\n *\n * ### Features\n * - **Toggleable Expansion:** Click the header to expand or collapse the content area. The panel slides open and closed, and the chevron turns with it; `prefers-reduced-motion: reduce` switches instantly instead.\n * - **Disabled State:** Prevents user interaction and visually indicates non-interactivity.\n * - **Customizable Content:** Slot for custom expanded content (`expanded-content`), supporting any HTML or component.\n * - **Optional Divider:** Can display a divider line below the item for visual separation in lists.\n * - **Accessible:** Uses a button for the header with appropriate ARIA attributes for accessibility.\n *\n * ### Usage Guidelines\n * Use `obc-accordion-item` to organize content into expandable sections, such as FAQs, settings panels, or grouped lists. Ideal when you want to let users scan section titles and expand only those relevant to them. For multi-item accordions, stack several `obc-accordion-item` components vertically.\n *\n * - Use the `title` property for the section label.\n * - Place any custom content (text, forms, components) in the `expanded-content` slot.\n * - Use the `disabled` property to prevent interaction for items that should not be toggled.\n * - Use the `showDivider` property to visually separate items in a list.\n * - If you need a persistent panel (not collapsible), use a different container component.\n *\n * **TODO(designer):** Confirm if there are recommended patterns for managing open/close state in multi-item accordions (e.g., only one open at a time), or if this is left to the developer.\n *\n * ### Slots\n * | Slot Name | Renders When... | Purpose |\n * |-------------------|--------------------------|-------------------------------------------------|\n * | expanded-content | Always | Custom content revealed while the item is open |\n *\n * ### Events\n * - `accordion-item-toggle` – Fired when the item is toggled open or closed. Event detail: `{ open: boolean, title: string }`\n *\n * ### Best Practices\n * - Keep section titles concise for easy scanning.\n * - Avoid placing interactive controls in the header area to prevent accidental toggling.\n * - For accessibility, ensure each item’s title is unique within a group.\n *\n * **Example:**\n * ```\n * <obc-accordion-item title=\"Details\" .open=${false}>\n * <div slot=\"expanded-content\">\n * <p>Additional information goes here.</p>\n * </div>\n * </obc-accordion-item>\n * ```\n *\n * @property title - The label displayed in the header of the accordion item.\n * @property open - Whether the item is expanded (shows the content area).\n * Set to `true` to expand, `false` to collapse.\n * @property disabled - Disables the accordion item, preventing user interaction and dimming the appearance.\n * @property showDivider - Displays a divider line below the item for visual separation.\n * Useful when stacking multiple items in a list.\n * @slot expanded-content - Content revealed while the item is open.\n * @fires {CustomEvent<{open: boolean, title: string}>} accordion-item-toggle - Fired when the item is toggled open or closed.\n * @cssprop [--obc-accordion-expand-duration=200ms] - How long the panel takes to open and close. The chevron and the header's corners follow it. Ignored under `prefers-reduced-motion: reduce`.\n * @stable\n */\n@customElement('obc-accordion-item')\nexport class ObcAccordionItem extends LitElement {\n @property({type: String}) override title = '';\n\n @property({type: Boolean}) open = false;\n\n @property({type: Boolean}) disabled = false;\n\n @property({type: Boolean}) showDivider = false;\n\n private handleToggle() {\n if (this.disabled) return;\n\n this.open = !this.open;\n\n this.dispatchEvent(\n new CustomEvent('accordion-item-toggle', {\n detail: {\n open: this.open,\n title: this.title,\n },\n })\n );\n }\n\n /**\n * Keeps the keyboard somewhere predictable when the panel closes.\n *\n * A collapsed panel is `inert`, and the browser drops focus out of anything\n * it makes inert — onto `<body>`, two frames later. Clicking the header\n * already leaves focus there; a consumer setting `open` while a slotted\n * control has focus is the case that needs the transfer.\n */\n override willUpdate(changed: PropertyValues<this>) {\n if (!changed.has('open') || this.open) return;\n\n const panel = this.shadowRoot?.querySelector('.panel');\n if (!panel) return;\n releaseFocusBefore(\n panel,\n this.shadowRoot?.querySelector<HTMLButtonElement>('.content-button'),\n this.shadowRoot?.querySelector<HTMLElement>('.wrapper')\n );\n }\n\n private renderContent() {\n return html`\n <div class=\"content\">\n <div class=\"leading-content-container\">\n <div class=\"label-frame\">\n <div class=\"title\">${this.title}</div>\n </div>\n </div>\n <div class=\"trailing-icon\">\n <obi-chevron-down-google></obi-chevron-down-google>\n </div>\n </div>\n `;\n }\n\n private renderExpandedContent() {\n return html`\n <div class=\"panel\" id=\"accordion-content\" ?inert=${!this.open}>\n <div class=\"panel-inner\">\n <div class=\"content-container\">\n <slot name=\"expanded-content\"></slot>\n </div>\n </div>\n </div>\n `;\n }\n\n private renderDivider() {\n if (!this.showDivider) return '';\n\n return html`<div class=\"divider\"></div>`;\n }\n\n override render() {\n return html`\n <div\n tabindex=\"-1\"\n class=${classMap({\n wrapper: true,\n 'state-disabled': this.disabled,\n 'open-true': this.open,\n 'open-false': !this.open,\n })}\n >\n <button\n class=\"content-button\"\n @click=${this.handleToggle}\n ?disabled=${this.disabled}\n aria-expanded=${this.open}\n aria-controls=\"accordion-content\"\n >\n ${this.renderContent()}\n </button>\n\n ${this.renderExpandedContent()} ${this.renderDivider()}\n </div>\n `;\n }\n\n static override styles = unsafeCSS(componentStyle);\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'obc-accordion-item': ObcAccordionItem;\n }\n}\n"],"mappings":";;;;;;;;;AAiEO,IAAM,mBAAN,MAAM,yBAAyB,WAAW;;;EACJ,KAAA,QAAA;EAET,KAAA,OAAA;EAEI,KAAA,WAAA;EAEG,KAAA,cAAA;;CAEzC,eAAuB;EACrB,IAAI,KAAK,UAAU;EAEnB,KAAK,OAAO,CAAC,KAAK;EAElB,KAAK,cACH,IAAI,YAAY,yBAAyB,EACvC,QAAQ;GACN,MAAM,KAAK;GACX,OAAO,KAAK;EACd,EACF,CAAC,CACH;CACF;;;;;;;;;CAUA,WAAoB,SAA+B;EACjD,IAAI,CAAC,QAAQ,IAAI,MAAM,KAAK,KAAK,MAAM;EAEvC,MAAM,QAAQ,KAAK,YAAY,cAAc,QAAQ;EACrD,IAAI,CAAC,OAAO;EACZ,mBACE,OACA,KAAK,YAAY,cAAiC,iBAAiB,GACnE,KAAK,YAAY,cAA2B,UAAU,CACxD;CACF;CAEA,gBAAwB;EACtB,OAAO,IAAI;;;;iCAIkB,KAAK,MAAM;;;;;;;;CAQ1C;CAEA,wBAAgC;EAC9B,OAAO,IAAI;yDAC0C,CAAC,KAAK,KAAK;;;;;;;;CAQlE;CAEA,gBAAwB;EACtB,IAAI,CAAC,KAAK,aAAa,OAAO;EAE9B,OAAO,IAAI;CACb;CAEA,SAAkB;EAChB,OAAO,IAAI;;;gBAGC,SAAS;GACf,SAAS;GACT,kBAAkB,KAAK;GACvB,aAAa,KAAK;GAClB,cAAc,CAAC,KAAK;EACtB,CAAC,EAAE;;;;mBAIQ,KAAK,aAAa;sBACf,KAAK,SAAS;0BACV,KAAK,KAAK;;;YAGxB,KAAK,cAAc,EAAE;;;UAGvB,KAAK,sBAAsB,EAAE,GAAG,KAAK,cAAc,EAAE;;;CAG7D;;EAEyB,KAAA,SAAA,UAAU,sBAAc;;AACnD;AAvGG,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,iBAAA,WAAA,SAAA,KAAA,CAAA;AAEvB,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,iBAAA,WAAA,QAAA,KAAA,CAAA;AAExB,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,iBAAA,WAAA,YAAA,KAAA,CAAA;AAExB,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,iBAAA,WAAA,eAAA,KAAA,CAAA;AAR1B,mBAAA,WAAA,CAAA,cAAc,oBAAoB,CAAA,GAAA,gBAAA"}
|
package/dist/internal/focus.d.ts
CHANGED
|
@@ -8,6 +8,29 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/** The focused element, following every open shadow root down. */
|
|
10
10
|
export declare function deepActiveElement(): Element | null;
|
|
11
|
+
/**
|
|
12
|
+
* Whether `node` sits inside `root` in the composed tree.
|
|
13
|
+
*
|
|
14
|
+
* `Node.contains()` walks the DOM tree, where slotted light-DOM content is a
|
|
15
|
+
* child of the host and not of the slot — so it answers no for exactly the
|
|
16
|
+
* content a component projects into itself. This follows `assignedSlot` and
|
|
17
|
+
* shadow hosts as well.
|
|
18
|
+
*/
|
|
19
|
+
export declare function composedContains(root: Node, node: Node | null): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Moves focus out of `hidden`, to the first fallback that will take it.
|
|
22
|
+
*
|
|
23
|
+
* Call it just before a region becomes `inert` or is taken out of the page.
|
|
24
|
+
* The browser blurs whatever it hides, and focus lands on `<body>` a frame or
|
|
25
|
+
* two later, so the next Tab press starts from the top of the document instead
|
|
26
|
+
* of where the user was.
|
|
27
|
+
*
|
|
28
|
+
* Each candidate is tried and then checked, rather than inspected first: a
|
|
29
|
+
* `disabled` button, a hidden one and an element with no tabindex all refuse
|
|
30
|
+
* focus for different reasons, and the only reliable question is whether focus
|
|
31
|
+
* actually left.
|
|
32
|
+
*/
|
|
33
|
+
export declare function releaseFocusBefore(hidden: Node, ...fallbacks: (HTMLElement | null | undefined)[]): void;
|
|
11
34
|
/**
|
|
12
35
|
* The elements under `root` a Tab press could land on, in rendered order:
|
|
13
36
|
* shadow children before light children, light children only where a slot
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focus.d.ts","sourceRoot":"","sources":["../../src/internal/focus.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,kEAAkE;AAClE,wBAAgB,iBAAiB,IAAI,OAAO,GAAG,IAAI,CAMlD;AASD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,EAAE,CAkB3D"}
|
|
1
|
+
{"version":3,"file":"focus.d.ts","sourceRoot":"","sources":["../../src/internal/focus.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,kEAAkE;AAClE,wBAAgB,iBAAiB,IAAI,OAAO,GAAG,IAAI,CAMlD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,CAUvE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,IAAI,EACZ,GAAG,SAAS,EAAE,CAAC,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,GAC/C,IAAI,CAON;AASD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,EAAE,CAkB3D"}
|
package/dist/internal/focus.js
CHANGED
|
@@ -14,6 +14,43 @@ function deepActiveElement() {
|
|
|
14
14
|
while (active?.shadowRoot?.activeElement) active = active.shadowRoot.activeElement;
|
|
15
15
|
return active;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Whether `node` sits inside `root` in the composed tree.
|
|
19
|
+
*
|
|
20
|
+
* `Node.contains()` walks the DOM tree, where slotted light-DOM content is a
|
|
21
|
+
* child of the host and not of the slot — so it answers no for exactly the
|
|
22
|
+
* content a component projects into itself. This follows `assignedSlot` and
|
|
23
|
+
* shadow hosts as well.
|
|
24
|
+
*/
|
|
25
|
+
function composedContains(root, node) {
|
|
26
|
+
let current = node;
|
|
27
|
+
while (current) {
|
|
28
|
+
if (current === root) return true;
|
|
29
|
+
current = current.assignedSlot ?? current.parentNode ?? (current instanceof ShadowRoot ? current.host : null);
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Moves focus out of `hidden`, to the first fallback that will take it.
|
|
35
|
+
*
|
|
36
|
+
* Call it just before a region becomes `inert` or is taken out of the page.
|
|
37
|
+
* The browser blurs whatever it hides, and focus lands on `<body>` a frame or
|
|
38
|
+
* two later, so the next Tab press starts from the top of the document instead
|
|
39
|
+
* of where the user was.
|
|
40
|
+
*
|
|
41
|
+
* Each candidate is tried and then checked, rather than inspected first: a
|
|
42
|
+
* `disabled` button, a hidden one and an element with no tabindex all refuse
|
|
43
|
+
* focus for different reasons, and the only reliable question is whether focus
|
|
44
|
+
* actually left.
|
|
45
|
+
*/
|
|
46
|
+
function releaseFocusBefore(hidden, ...fallbacks) {
|
|
47
|
+
if (!composedContains(hidden, deepActiveElement())) return;
|
|
48
|
+
for (const candidate of fallbacks) {
|
|
49
|
+
if (!candidate) continue;
|
|
50
|
+
candidate.focus();
|
|
51
|
+
if (!composedContains(hidden, deepActiveElement())) return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
17
54
|
function isTabbable(element) {
|
|
18
55
|
if (!element.matches(TABBABLE_SELECTOR)) return false;
|
|
19
56
|
if (element.tabIndex < 0) return false;
|
|
@@ -45,6 +82,6 @@ function composedTabbables(root) {
|
|
|
45
82
|
return found;
|
|
46
83
|
}
|
|
47
84
|
//#endregion
|
|
48
|
-
export { composedTabbables, deepActiveElement };
|
|
85
|
+
export { composedContains, composedTabbables, deepActiveElement, releaseFocusBefore };
|
|
49
86
|
|
|
50
87
|
//# sourceMappingURL=focus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focus.js","names":[],"sources":["../../src/internal/focus.ts"],"sourcesContent":["/**\n * Focus queries that see through open shadow roots.\n *\n * `document.activeElement` and `querySelectorAll` both stop at a shadow\n * boundary, so a component that focuses a control it renders reads as\n * unfocused from outside, and a dialog cannot find the controls it has to\n * cycle between. These walk the composed tree instead.\n */\n\nconst TABBABLE_SELECTOR =\n 'a[href], button, input, select, textarea, [tabindex], [contenteditable=\"true\"]';\n\n/** The focused element, following every open shadow root down. */\nexport function deepActiveElement(): Element | null {\n let active = document.activeElement;\n while (active?.shadowRoot?.activeElement) {\n active = active.shadowRoot.activeElement;\n }\n return active;\n}\n\nfunction isTabbable(element: Element): element is HTMLElement {\n if (!element.matches(TABBABLE_SELECTOR)) return false;\n if ((element as HTMLElement).tabIndex < 0) return false;\n if ((element as HTMLButtonElement).disabled) return false;\n return element.getClientRects().length > 0;\n}\n\n/**\n * The elements under `root` a Tab press could land on, in rendered order:\n * shadow children before light children, light children only where a slot\n * places them.\n */\nexport function composedTabbables(root: Node): HTMLElement[] {\n const found: HTMLElement[] = [];\n const visit = (node: Node) => {\n if (node instanceof HTMLSlotElement) {\n node.assignedNodes({flatten: true}).forEach(visit);\n return;\n }\n if (node instanceof Element) {\n if (isTabbable(node)) found.push(node);\n if (node.shadowRoot) {\n Array.from(node.shadowRoot.childNodes).forEach(visit);\n return;\n }\n }\n Array.from(node.childNodes).forEach(visit);\n };\n visit(root);\n return found;\n}\n"],"mappings":";;;;;;;;;AASA,IAAM,oBACJ;;AAGF,SAAgB,oBAAoC;CAClD,IAAI,SAAS,SAAS;CACtB,OAAO,QAAQ,YAAY,eACzB,SAAS,OAAO,WAAW;CAE7B,OAAO;AACT;AAEA,SAAS,WAAW,SAA0C;CAC5D,IAAI,CAAC,QAAQ,QAAQ,iBAAiB,GAAG,OAAO;CAChD,IAAK,QAAwB,WAAW,GAAG,OAAO;CAClD,IAAK,QAA8B,UAAU,OAAO;CACpD,OAAO,QAAQ,eAAe,CAAC,CAAC,SAAS;AAC3C;;;;;;AAOA,SAAgB,kBAAkB,MAA2B;CAC3D,MAAM,QAAuB,CAAC;CAC9B,MAAM,SAAS,SAAe;EAC5B,IAAI,gBAAgB,iBAAiB;GACnC,KAAK,cAAc,EAAC,SAAS,KAAI,CAAC,CAAC,CAAC,QAAQ,KAAK;GACjD;EACF;EACA,IAAI,gBAAgB,SAAS;GAC3B,IAAI,WAAW,IAAI,GAAG,MAAM,KAAK,IAAI;GACrC,IAAI,KAAK,YAAY;IACnB,MAAM,KAAK,KAAK,WAAW,UAAU,CAAC,CAAC,QAAQ,KAAK;IACpD;GACF;EACF;EACA,MAAM,KAAK,KAAK,UAAU,CAAC,CAAC,QAAQ,KAAK;CAC3C;CACA,MAAM,IAAI;CACV,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"focus.js","names":[],"sources":["../../src/internal/focus.ts"],"sourcesContent":["/**\n * Focus queries that see through open shadow roots.\n *\n * `document.activeElement` and `querySelectorAll` both stop at a shadow\n * boundary, so a component that focuses a control it renders reads as\n * unfocused from outside, and a dialog cannot find the controls it has to\n * cycle between. These walk the composed tree instead.\n */\n\nconst TABBABLE_SELECTOR =\n 'a[href], button, input, select, textarea, [tabindex], [contenteditable=\"true\"]';\n\n/** The focused element, following every open shadow root down. */\nexport function deepActiveElement(): Element | null {\n let active = document.activeElement;\n while (active?.shadowRoot?.activeElement) {\n active = active.shadowRoot.activeElement;\n }\n return active;\n}\n\n/**\n * Whether `node` sits inside `root` in the composed tree.\n *\n * `Node.contains()` walks the DOM tree, where slotted light-DOM content is a\n * child of the host and not of the slot — so it answers no for exactly the\n * content a component projects into itself. This follows `assignedSlot` and\n * shadow hosts as well.\n */\nexport function composedContains(root: Node, node: Node | null): boolean {\n let current: Node | null = node;\n while (current) {\n if (current === root) return true;\n current =\n (current as Element).assignedSlot ??\n current.parentNode ??\n (current instanceof ShadowRoot ? current.host : null);\n }\n return false;\n}\n\n/**\n * Moves focus out of `hidden`, to the first fallback that will take it.\n *\n * Call it just before a region becomes `inert` or is taken out of the page.\n * The browser blurs whatever it hides, and focus lands on `<body>` a frame or\n * two later, so the next Tab press starts from the top of the document instead\n * of where the user was.\n *\n * Each candidate is tried and then checked, rather than inspected first: a\n * `disabled` button, a hidden one and an element with no tabindex all refuse\n * focus for different reasons, and the only reliable question is whether focus\n * actually left.\n */\nexport function releaseFocusBefore(\n hidden: Node,\n ...fallbacks: (HTMLElement | null | undefined)[]\n): void {\n if (!composedContains(hidden, deepActiveElement())) return;\n for (const candidate of fallbacks) {\n if (!candidate) continue;\n candidate.focus();\n if (!composedContains(hidden, deepActiveElement())) return;\n }\n}\n\nfunction isTabbable(element: Element): element is HTMLElement {\n if (!element.matches(TABBABLE_SELECTOR)) return false;\n if ((element as HTMLElement).tabIndex < 0) return false;\n if ((element as HTMLButtonElement).disabled) return false;\n return element.getClientRects().length > 0;\n}\n\n/**\n * The elements under `root` a Tab press could land on, in rendered order:\n * shadow children before light children, light children only where a slot\n * places them.\n */\nexport function composedTabbables(root: Node): HTMLElement[] {\n const found: HTMLElement[] = [];\n const visit = (node: Node) => {\n if (node instanceof HTMLSlotElement) {\n node.assignedNodes({flatten: true}).forEach(visit);\n return;\n }\n if (node instanceof Element) {\n if (isTabbable(node)) found.push(node);\n if (node.shadowRoot) {\n Array.from(node.shadowRoot.childNodes).forEach(visit);\n return;\n }\n }\n Array.from(node.childNodes).forEach(visit);\n };\n visit(root);\n return found;\n}\n"],"mappings":";;;;;;;;;AASA,IAAM,oBACJ;;AAGF,SAAgB,oBAAoC;CAClD,IAAI,SAAS,SAAS;CACtB,OAAO,QAAQ,YAAY,eACzB,SAAS,OAAO,WAAW;CAE7B,OAAO;AACT;;;;;;;;;AAUA,SAAgB,iBAAiB,MAAY,MAA4B;CACvE,IAAI,UAAuB;CAC3B,OAAO,SAAS;EACd,IAAI,YAAY,MAAM,OAAO;EAC7B,UACG,QAAoB,gBACrB,QAAQ,eACP,mBAAmB,aAAa,QAAQ,OAAO;CACpD;CACA,OAAO;AACT;;;;;;;;;;;;;;AAeA,SAAgB,mBACd,QACA,GAAG,WACG;CACN,IAAI,CAAC,iBAAiB,QAAQ,kBAAkB,CAAC,GAAG;CACpD,KAAK,MAAM,aAAa,WAAW;EACjC,IAAI,CAAC,WAAW;EAChB,UAAU,MAAM;EAChB,IAAI,CAAC,iBAAiB,QAAQ,kBAAkB,CAAC,GAAG;CACtD;AACF;AAEA,SAAS,WAAW,SAA0C;CAC5D,IAAI,CAAC,QAAQ,QAAQ,iBAAiB,GAAG,OAAO;CAChD,IAAK,QAAwB,WAAW,GAAG,OAAO;CAClD,IAAK,QAA8B,UAAU,OAAO;CACpD,OAAO,QAAQ,eAAe,CAAC,CAAC,SAAS;AAC3C;;;;;;AAOA,SAAgB,kBAAkB,MAA2B;CAC3D,MAAM,QAAuB,CAAC;CAC9B,MAAM,SAAS,SAAe;EAC5B,IAAI,gBAAgB,iBAAiB;GACnC,KAAK,cAAc,EAAC,SAAS,KAAI,CAAC,CAAC,CAAC,QAAQ,KAAK;GACjD;EACF;EACA,IAAI,gBAAgB,SAAS;GAC3B,IAAI,WAAW,IAAI,GAAG,MAAM,KAAK,IAAI;GACrC,IAAI,KAAK,YAAY;IACnB,MAAM,KAAK,KAAK,WAAW,UAAU,CAAC,CAAC,QAAQ,KAAK;IACpD;GACF;EACF;EACA,MAAM,KAAK,KAAK,UAAU,CAAC,CAAC,QAAQ,KAAK;CAC3C;CACA,MAAM,IAAI;CACV,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
:host {
|
|
6
6
|
display: block;
|
|
7
|
+
|
|
8
|
+
/* TODO(designer): confirm the expand duration and curve. */
|
|
9
|
+
--_expand-duration: var(--obc-accordion-expand-duration, 200ms);
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
.wrapper {
|
|
@@ -19,6 +22,12 @@
|
|
|
19
22
|
align-items: center;
|
|
20
23
|
align-self: stretch;
|
|
21
24
|
height: fit-content;
|
|
25
|
+
border-radius: var(--ui-components-accordion-border-radius);
|
|
26
|
+
/* The card surface is what the closing panel slides over; snapping it away
|
|
27
|
+
would drop the content onto the page background mid-slide. */
|
|
28
|
+
transition:
|
|
29
|
+
background-color var(--_expand-duration) ease,
|
|
30
|
+
box-shadow var(--_expand-duration) ease;
|
|
22
31
|
}
|
|
23
32
|
|
|
24
33
|
.content-button {
|
|
@@ -32,6 +41,11 @@
|
|
|
32
41
|
padding: 0;
|
|
33
42
|
border: 0;
|
|
34
43
|
overflow: hidden;
|
|
44
|
+
/* The bottom corners square on open; without this they round again while
|
|
45
|
+
the panel is still sliding away. */
|
|
46
|
+
transition:
|
|
47
|
+
border-radius var(--_expand-duration) ease,
|
|
48
|
+
box-shadow var(--_expand-duration) ease;
|
|
35
49
|
}
|
|
36
50
|
|
|
37
51
|
.header-container {
|
|
@@ -110,26 +124,45 @@
|
|
|
110
124
|
flex-shrink: 0;
|
|
111
125
|
}
|
|
112
126
|
|
|
127
|
+
.trailing-icon {
|
|
128
|
+
transition: transform var(--_expand-duration) ease;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
&.state-expanded .trailing-icon {
|
|
132
|
+
transform: rotate(-180deg);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.panel {
|
|
136
|
+
display: grid;
|
|
137
|
+
/* 0fr to 1fr is the only track that eases to content height in every engine. */
|
|
138
|
+
grid-template-rows: 0fr;
|
|
139
|
+
align-self: stretch;
|
|
140
|
+
transition: grid-template-rows var(--_expand-duration) ease;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.panel-inner {
|
|
144
|
+
/* The grid item cannot carry the inset: padding holds the track open at
|
|
145
|
+
16px when closed. It clips here, the padding sits one level down. */
|
|
146
|
+
min-height: 0;
|
|
147
|
+
overflow: hidden;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.container-content-additional {
|
|
151
|
+
color: var(--element-neutral-color);
|
|
152
|
+
@mixin font-body;
|
|
153
|
+
display: flex;
|
|
154
|
+
flex-direction: column;
|
|
155
|
+
align-items: center;
|
|
156
|
+
padding: 0 16px 16px 16px;
|
|
157
|
+
}
|
|
158
|
+
|
|
113
159
|
&.state-expanded {
|
|
114
|
-
& .
|
|
115
|
-
|
|
116
|
-
@mixin font-body;
|
|
117
|
-
display: flex;
|
|
118
|
-
flex-direction: column;
|
|
119
|
-
align-items: center;
|
|
120
|
-
flex: 1 0 0;
|
|
121
|
-
align-self: stretch;
|
|
122
|
-
height: 100%;
|
|
123
|
-
padding: 0 16px 16px 16px;
|
|
160
|
+
& .panel {
|
|
161
|
+
grid-template-rows: 1fr;
|
|
124
162
|
}
|
|
125
163
|
|
|
126
164
|
& .card-container {
|
|
127
|
-
display: flex;
|
|
128
|
-
flex-direction: column;
|
|
129
|
-
align-items: center;
|
|
130
165
|
flex: 1 0 0;
|
|
131
|
-
align-self: stretch;
|
|
132
|
-
border-radius: var(--ui-components-accordion-border-radius);
|
|
133
166
|
background: var(--container-background-color);
|
|
134
167
|
box-shadow: 0px 1px 1px 0px rgba(0, 0, 0, 0.2);
|
|
135
168
|
}
|
|
@@ -239,3 +272,12 @@
|
|
|
239
272
|
z-index: 1;
|
|
240
273
|
}
|
|
241
274
|
}
|
|
275
|
+
|
|
276
|
+
@media (prefers-reduced-motion: reduce) {
|
|
277
|
+
.wrapper .panel,
|
|
278
|
+
.wrapper .card-container,
|
|
279
|
+
.wrapper .content-button,
|
|
280
|
+
.wrapper .trailing-icon {
|
|
281
|
+
transition: none;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import {afterEach, describe, expect, it} from 'vitest';
|
|
2
|
+
import './accordion-card.js';
|
|
3
|
+
import type {ObcAccordionCard} from './accordion-card.js';
|
|
4
|
+
|
|
5
|
+
async function mount(setup: (el: ObcAccordionCard) => void = () => {}) {
|
|
6
|
+
const el = document.createElement('obc-accordion-card');
|
|
7
|
+
el.cardTitle = 'Title';
|
|
8
|
+
const content = document.createElement('div');
|
|
9
|
+
content.slot = 'expanded-content';
|
|
10
|
+
content.innerHTML = '<button id="inner">Inner</button>';
|
|
11
|
+
el.appendChild(content);
|
|
12
|
+
setup(el);
|
|
13
|
+
document.body.appendChild(el);
|
|
14
|
+
await el.updateComplete;
|
|
15
|
+
return el;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const frame = () => new Promise((r) => requestAnimationFrame(() => r(null)));
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Whether the panel transitions at all. Under `prefers-reduced-motion: reduce`
|
|
22
|
+
* the track snaps, so there is no mid-slide moment to observe — the focus half
|
|
23
|
+
* of that test still has to hold in both modes.
|
|
24
|
+
*/
|
|
25
|
+
const animates = () =>
|
|
26
|
+
!window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
27
|
+
|
|
28
|
+
const sr = (el: ObcAccordionCard) => el.shadowRoot!;
|
|
29
|
+
const panel = (el: ObcAccordionCard) =>
|
|
30
|
+
sr(el).querySelector<HTMLElement>('.panel')!;
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
document.body.innerHTML = '';
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('obc-accordion-card expand animation', () => {
|
|
37
|
+
it('keeps the panel rendered while collapsed', async () => {
|
|
38
|
+
const el = await mount();
|
|
39
|
+
expect(panel(el)).not.toBeNull();
|
|
40
|
+
expect(
|
|
41
|
+
panel(el).querySelector('slot[name="expanded-content"]')
|
|
42
|
+
).not.toBeNull();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('collapses the panel to a zero-height grid track', async () => {
|
|
46
|
+
const el = await mount();
|
|
47
|
+
expect(getComputedStyle(panel(el)).gridTemplateRows).toBe('0px');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('sizes the track to the content when open', async () => {
|
|
51
|
+
const el = await mount((e) => (e.expanded = true));
|
|
52
|
+
expect(getComputedStyle(panel(el)).gridTemplateRows).not.toBe('0px');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('hides the collapsed panel from the tab order', async () => {
|
|
56
|
+
const el = await mount();
|
|
57
|
+
expect(panel(el).hasAttribute('inert')).toBe(true);
|
|
58
|
+
const inner = el.querySelector<HTMLButtonElement>('#inner')!;
|
|
59
|
+
inner.focus();
|
|
60
|
+
expect(document.activeElement).not.toBe(inner);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('drops keyboard access as soon as it starts closing', async () => {
|
|
64
|
+
const el = await mount((e) => (e.expanded = true));
|
|
65
|
+
await frame();
|
|
66
|
+
await frame();
|
|
67
|
+
const inner = el.querySelector<HTMLButtonElement>('#inner')!;
|
|
68
|
+
|
|
69
|
+
el.expanded = false;
|
|
70
|
+
await el.updateComplete;
|
|
71
|
+
await frame();
|
|
72
|
+
|
|
73
|
+
if (animates()) {
|
|
74
|
+
expect(getComputedStyle(panel(el)).gridTemplateRows).not.toBe('0px');
|
|
75
|
+
}
|
|
76
|
+
inner.focus();
|
|
77
|
+
expect(document.activeElement).not.toBe(inner);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('reveals the panel when expanded', async () => {
|
|
81
|
+
const el = await mount((e) => (e.expanded = true));
|
|
82
|
+
expect(panel(el).hasAttribute('inert')).toBe(false);
|
|
83
|
+
const inner = el.querySelector<HTMLButtonElement>('#inner')!;
|
|
84
|
+
inner.focus();
|
|
85
|
+
expect(document.activeElement).toBe(inner);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('points aria-controls at the panel', async () => {
|
|
89
|
+
const el = await mount();
|
|
90
|
+
const button = sr(el).querySelector<HTMLButtonElement>('.content-button')!;
|
|
91
|
+
expect(button.getAttribute('aria-controls')).toBe(panel(el).id);
|
|
92
|
+
expect(panel(el).id).not.toBe('');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('rotates one chevron instead of swapping two', async () => {
|
|
96
|
+
const el = await mount();
|
|
97
|
+
expect(sr(el).querySelectorAll('obi-chevron-down-google')).toHaveLength(1);
|
|
98
|
+
expect(sr(el).querySelector('obi-chevron-up-google')).toBeNull();
|
|
99
|
+
el.expanded = true;
|
|
100
|
+
await el.updateComplete;
|
|
101
|
+
expect(sr(el).querySelectorAll('obi-chevron-down-google')).toHaveLength(1);
|
|
102
|
+
expect(sr(el).querySelector('obi-chevron-up-google')).toBeNull();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('still toggles and fires accordion-toggle', async () => {
|
|
106
|
+
const el = await mount();
|
|
107
|
+
const seen: boolean[] = [];
|
|
108
|
+
el.addEventListener('accordion-toggle', (e) =>
|
|
109
|
+
seen.push((e as CustomEvent<{expanded: boolean}>).detail.expanded)
|
|
110
|
+
);
|
|
111
|
+
sr(el).querySelector<HTMLButtonElement>('.content-button')!.click();
|
|
112
|
+
expect(el.expanded).toBe(true);
|
|
113
|
+
expect(seen).toEqual([true]);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('returns focus to the header when it closes with focus inside', async () => {
|
|
117
|
+
const el = await mount((e) => (e.expanded = true));
|
|
118
|
+
const inner = el.querySelector<HTMLButtonElement>('#inner')!;
|
|
119
|
+
inner.focus();
|
|
120
|
+
expect(document.activeElement).toBe(inner);
|
|
121
|
+
|
|
122
|
+
el.expanded = false;
|
|
123
|
+
await el.updateComplete;
|
|
124
|
+
await frame();
|
|
125
|
+
await frame();
|
|
126
|
+
|
|
127
|
+
const header = sr(el).querySelector<HTMLButtonElement>('.content-button')!;
|
|
128
|
+
expect(sr(el).activeElement).toBe(header);
|
|
129
|
+
expect(document.activeElement).not.toBe(document.body);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('leaves focus alone when it closes from the header', async () => {
|
|
133
|
+
const el = await mount((e) => (e.expanded = true));
|
|
134
|
+
const header = sr(el).querySelector<HTMLButtonElement>('.content-button')!;
|
|
135
|
+
header.focus();
|
|
136
|
+
|
|
137
|
+
header.click();
|
|
138
|
+
await el.updateComplete;
|
|
139
|
+
await frame();
|
|
140
|
+
await frame();
|
|
141
|
+
|
|
142
|
+
expect(sr(el).activeElement).toBe(header);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('falls back to the wrapper when the header is disabled', async () => {
|
|
146
|
+
const el = await mount((e) => {
|
|
147
|
+
e.expanded = true;
|
|
148
|
+
e.disabled = true;
|
|
149
|
+
});
|
|
150
|
+
const inner = el.querySelector<HTMLButtonElement>('#inner')!;
|
|
151
|
+
inner.focus();
|
|
152
|
+
expect(document.activeElement).toBe(inner);
|
|
153
|
+
|
|
154
|
+
el.expanded = false;
|
|
155
|
+
await el.updateComplete;
|
|
156
|
+
await frame();
|
|
157
|
+
await frame();
|
|
158
|
+
|
|
159
|
+
// The disabled header cannot take focus, so the wrapper holds the place
|
|
160
|
+
// rather than letting it fall to <body>.
|
|
161
|
+
expect(sr(el).activeElement).toBe(sr(el).querySelector('.wrapper'));
|
|
162
|
+
expect(document.activeElement).not.toBe(document.body);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('keeps the wrapper out of the tab order', async () => {
|
|
166
|
+
const el = await mount();
|
|
167
|
+
expect(sr(el).querySelector('.wrapper')!.getAttribute('tabindex')).toBe(
|
|
168
|
+
'-1'
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {LitElement, html, unsafeCSS} from 'lit';
|
|
1
|
+
import {LitElement, html, unsafeCSS, type PropertyValues} from 'lit';
|
|
2
2
|
import {customElement} from '../../decorator.js';
|
|
3
|
+
import {releaseFocusBefore} from '../../internal/focus.js';
|
|
3
4
|
import {classMap} from 'lit/directives/class-map.js';
|
|
4
5
|
import compentStyle from './accordion-card.css?inline';
|
|
5
6
|
import {property} from 'lit/decorators.js';
|
|
6
|
-
import '../../icons/icon-chevron-up-google.js';
|
|
7
7
|
import '../../icons/icon-chevron-down-google.js';
|
|
8
8
|
import '../alert-frame/alert-frame.js';
|
|
9
9
|
import {
|
|
@@ -30,7 +30,7 @@ export enum Position {
|
|
|
30
30
|
* Provides a summary row with optional icon, title, description, and status label. Expands to reveal additional content on click/tap, supporting both single-line and large layouts. Can display an alert overlay for contextual warnings or notifications.
|
|
31
31
|
*
|
|
32
32
|
* ### Features
|
|
33
|
-
* - **Expandable/collapsible:** Click/tap toggles between collapsed and expanded states, revealing or hiding additional content.
|
|
33
|
+
* - **Expandable/collapsible:** Click/tap toggles between collapsed and expanded states, revealing or hiding additional content. The panel slides open and closed, and the chevron turns with it; `prefers-reduced-motion: reduce` switches instantly instead.
|
|
34
34
|
* - **Variants:**
|
|
35
35
|
* - **Single-line:** Compact header with only title (and optional icon/status).
|
|
36
36
|
* - **Large:** Header includes a description beneath the title for more detail.
|
|
@@ -131,6 +131,7 @@ export enum Position {
|
|
|
131
131
|
* @slot alert-label - Label text for the alert overlay (used when `hasAlert` is true)
|
|
132
132
|
* @slot alert-timer - Timer/duration text for the alert overlay (used when `hasAlert` is true)
|
|
133
133
|
* @fires {CustomEvent<{expanded: boolean, cardTitle: string}>} accordion-toggle - Fired when the accordion is expanded or collapsed
|
|
134
|
+
* @cssprop [--obc-accordion-expand-duration=200ms] - How long the panel takes to open and close. The chevron and the card's corners follow it. Ignored under `prefers-reduced-motion: reduce`.
|
|
134
135
|
* @stable
|
|
135
136
|
*/
|
|
136
137
|
@customElement('obc-accordion-card')
|
|
@@ -192,6 +193,26 @@ export class ObcAccordionCard extends LitElement {
|
|
|
192
193
|
);
|
|
193
194
|
}
|
|
194
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Keeps the keyboard somewhere predictable when the panel closes.
|
|
198
|
+
*
|
|
199
|
+
* A collapsed panel is `inert`, and the browser drops focus out of anything
|
|
200
|
+
* it makes inert — onto `<body>`, two frames later. Clicking the header
|
|
201
|
+
* already leaves focus there; a consumer setting `expanded` while a slotted
|
|
202
|
+
* control has focus is the case that needs the transfer.
|
|
203
|
+
*/
|
|
204
|
+
override willUpdate(changed: PropertyValues<this>) {
|
|
205
|
+
if (!changed.has('expanded') || this.expanded) return;
|
|
206
|
+
|
|
207
|
+
const panel = this.shadowRoot?.querySelector('.panel');
|
|
208
|
+
if (!panel) return;
|
|
209
|
+
releaseFocusBefore(
|
|
210
|
+
panel,
|
|
211
|
+
this.shadowRoot?.querySelector<HTMLButtonElement>('.content-button'),
|
|
212
|
+
this.shadowRoot?.querySelector<HTMLElement>('.wrapper')
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
195
216
|
private renderContentMain() {
|
|
196
217
|
return html`
|
|
197
218
|
<div class="header-container">
|
|
@@ -225,11 +246,7 @@ export class ObcAccordionCard extends LitElement {
|
|
|
225
246
|
: ''
|
|
226
247
|
}
|
|
227
248
|
<div class="trailing-icon">
|
|
228
|
-
|
|
229
|
-
this.expanded
|
|
230
|
-
? html`<obi-chevron-up-google></obi-chevron-up-google>`
|
|
231
|
-
: html`<obi-chevron-down-google></obi-chevron-down-google>`
|
|
232
|
-
}
|
|
249
|
+
<obi-chevron-down-google></obi-chevron-down-google>
|
|
233
250
|
</div>
|
|
234
251
|
</div>
|
|
235
252
|
</div>
|
|
@@ -237,11 +254,13 @@ export class ObcAccordionCard extends LitElement {
|
|
|
237
254
|
}
|
|
238
255
|
|
|
239
256
|
private renderContentAdditional() {
|
|
240
|
-
if (!this.expanded) return '';
|
|
241
|
-
|
|
242
257
|
return html`
|
|
243
|
-
<div class="
|
|
244
|
-
<
|
|
258
|
+
<div class="panel" id="accordion-content" ?inert=${!this.expanded}>
|
|
259
|
+
<div class="panel-inner">
|
|
260
|
+
<div class="container-content-additional">
|
|
261
|
+
<slot name="expanded-content"></slot>
|
|
262
|
+
</div>
|
|
263
|
+
</div>
|
|
245
264
|
</div>
|
|
246
265
|
`;
|
|
247
266
|
}
|
|
@@ -258,6 +277,7 @@ export class ObcAccordionCard extends LitElement {
|
|
|
258
277
|
override render() {
|
|
259
278
|
return html`
|
|
260
279
|
<div
|
|
280
|
+
tabindex="-1"
|
|
261
281
|
class=${classMap({
|
|
262
282
|
wrapper: true,
|
|
263
283
|
'state-expanded': this.expanded,
|