@oicl/openbridge-webcomponents-full-bundle 2.0.0-next.172 → 2.0.0-next.174

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.
Files changed (33) hide show
  1. package/bundle/openbridge-webcomponents.bundle.js +182 -35
  2. package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
  3. package/custom-elements.json +45 -5
  4. package/dist/components/accordion-card/accordion-card.css.js +61 -19
  5. package/dist/components/accordion-card/accordion-card.css.js.map +1 -1
  6. package/dist/components/accordion-card/accordion-card.d.ts +12 -3
  7. package/dist/components/accordion-card/accordion-card.d.ts.map +1 -1
  8. package/dist/components/accordion-card/accordion-card.js +23 -5
  9. package/dist/components/accordion-card/accordion-card.js.map +1 -1
  10. package/dist/components/accordion-item/accordion-item.css.js +40 -9
  11. package/dist/components/accordion-item/accordion-item.css.js.map +1 -1
  12. package/dist/components/accordion-item/accordion-item.d.ts +14 -5
  13. package/dist/components/accordion-item/accordion-item.d.ts.map +1 -1
  14. package/dist/components/accordion-item/accordion-item.js +23 -3
  15. package/dist/components/accordion-item/accordion-item.js.map +1 -1
  16. package/dist/internal/focus.d.ts +23 -0
  17. package/dist/internal/focus.d.ts.map +1 -1
  18. package/dist/internal/focus.js +38 -1
  19. package/dist/internal/focus.js.map +1 -1
  20. package/docs/GettingStarted.mdx +8 -3
  21. package/docs/MigrationGuide.mdx +18 -4
  22. package/docs/migration-guide/api-ar.md +9 -7
  23. package/docs/migration-guide/api-automation.md +0 -1
  24. package/docs/migration-guide/deprecated-members.md +9 -8
  25. package/package.json +1 -1
  26. package/src/components/accordion-card/accordion-card.css +57 -15
  27. package/src/components/accordion-card/accordion-card.spec.ts +171 -0
  28. package/src/components/accordion-card/accordion-card.ts +32 -12
  29. package/src/components/accordion-item/accordion-item.css +40 -9
  30. package/src/components/accordion-item/accordion-item.spec.ts +161 -0
  31. package/src/components/accordion-item/accordion-item.ts +34 -9
  32. package/src/internal/_test-utils.ts +3 -12
  33. package/src/internal/focus.ts +45 -0
@@ -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="container-content-additional">
244
- <slot name="expanded-content"></slot>
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,
@@ -2,6 +2,11 @@
2
2
  box-sizing: border-box;
3
3
  }
4
4
 
5
+ :host {
6
+ /* TODO(designer): confirm the expand duration and curve. */
7
+ --_expand-duration: var(--obc-accordion-expand-duration, 200ms);
8
+ }
9
+
5
10
  .wrapper {
6
11
  display: flex;
7
12
  flex-direction: column;
@@ -26,6 +31,9 @@
26
31
  cursor: pointer;
27
32
  overflow: hidden;
28
33
  position: relative;
34
+ /* The bottom corners square on open; without this they round again while
35
+ the panel is still sliding away. */
36
+ transition: border-radius var(--_expand-duration) ease;
29
37
  }
30
38
 
31
39
  .content {
@@ -87,7 +95,7 @@
87
95
  height: var(--menu-navigation-components-navigation-item-icon-size);
88
96
  flex-shrink: 0;
89
97
  position: relative;
90
- transition: transform 0.2s ease;
98
+ transition: transform var(--_expand-duration) ease;
91
99
  }
92
100
 
93
101
  .divider {
@@ -104,19 +112,29 @@
104
112
  transform: rotate(-180deg);
105
113
  }
106
114
 
107
- .content-container {
108
- display: flex;
109
- flex-direction: column;
115
+ .panel {
116
+ display: grid;
117
+ /* 0fr to 1fr is the only track that eases to content height in every engine. */
118
+ grid-template-rows: 0fr;
110
119
  width: 100%;
111
- flex-shrink: 0;
120
+ transition: grid-template-rows var(--_expand-duration) ease;
112
121
  }
113
122
 
114
- .wrapper.open-true .content-button {
115
- border-bottom-left-radius: 0;
116
- border-bottom-right-radius: 0;
123
+ .wrapper.open-true .panel {
124
+ grid-template-rows: 1fr;
125
+ }
126
+
127
+ .panel-inner {
128
+ /* The grid item cannot carry the frame: its border is left out of the open
129
+ track and clipped off. It clips here, the frame sits one level down. */
130
+ min-height: 0;
131
+ overflow: hidden;
117
132
  }
118
133
 
119
- .wrapper.open-true .content-container {
134
+ .content-container {
135
+ display: flex;
136
+ flex-direction: column;
137
+ width: 100%;
120
138
  background: var(--container-background-color);
121
139
  border: 1px solid var(--flat-enabled-border-color);
122
140
  border-top: none;
@@ -124,6 +142,11 @@
124
142
  border-bottom-right-radius: var(--ui-components-accordion-item-border-radius);
125
143
  }
126
144
 
145
+ .wrapper.open-true .content-button {
146
+ border-bottom-left-radius: 0;
147
+ border-bottom-right-radius: 0;
148
+ }
149
+
127
150
  .wrapper.state-disabled .content-button {
128
151
  cursor: not-allowed;
129
152
  }
@@ -132,3 +155,11 @@
132
155
  .wrapper.state-disabled .trailing-icon {
133
156
  color: var(--element-disabled-color);
134
157
  }
158
+
159
+ @media (prefers-reduced-motion: reduce) {
160
+ .panel,
161
+ .content-button,
162
+ .trailing-icon {
163
+ transition: none;
164
+ }
165
+ }
@@ -0,0 +1,161 @@
1
+ import {afterEach, describe, expect, it} from 'vitest';
2
+ import './accordion-item.js';
3
+ import type {ObcAccordionItem} from './accordion-item.js';
4
+
5
+ async function mount(setup: (el: ObcAccordionItem) => void = () => {}) {
6
+ const el = document.createElement('obc-accordion-item');
7
+ el.title = '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: ObcAccordionItem) => el.shadowRoot!;
29
+ const panel = (el: ObcAccordionItem) =>
30
+ sr(el).querySelector<HTMLElement>('.panel')!;
31
+
32
+ afterEach(() => {
33
+ document.body.innerHTML = '';
34
+ });
35
+
36
+ describe('obc-accordion-item expand animation', () => {
37
+ it('keeps the panel rendered while closed', 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.open = true));
52
+ expect(getComputedStyle(panel(el)).gridTemplateRows).not.toBe('0px');
53
+ });
54
+
55
+ it('hides the closed 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.open = true));
65
+ await frame();
66
+ await frame();
67
+ const inner = el.querySelector<HTMLButtonElement>('#inner')!;
68
+
69
+ el.open = 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 open', async () => {
81
+ const el = await mount((e) => (e.open = 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('still toggles and fires accordion-item-toggle', async () => {
96
+ const el = await mount();
97
+ const seen: boolean[] = [];
98
+ el.addEventListener('accordion-item-toggle', (e) =>
99
+ seen.push((e as CustomEvent<{open: boolean}>).detail.open)
100
+ );
101
+ sr(el).querySelector<HTMLButtonElement>('.content-button')!.click();
102
+ expect(el.open).toBe(true);
103
+ expect(seen).toEqual([true]);
104
+ });
105
+
106
+ it('returns focus to the header when it closes with focus inside', async () => {
107
+ const el = await mount((e) => (e.open = true));
108
+ const inner = el.querySelector<HTMLButtonElement>('#inner')!;
109
+ inner.focus();
110
+ expect(document.activeElement).toBe(inner);
111
+
112
+ el.open = false;
113
+ await el.updateComplete;
114
+ await frame();
115
+ await frame();
116
+
117
+ const header = sr(el).querySelector<HTMLButtonElement>('.content-button')!;
118
+ expect(sr(el).activeElement).toBe(header);
119
+ expect(document.activeElement).not.toBe(document.body);
120
+ });
121
+
122
+ it('leaves focus alone when it closes from the header', async () => {
123
+ const el = await mount((e) => (e.open = true));
124
+ const header = sr(el).querySelector<HTMLButtonElement>('.content-button')!;
125
+ header.focus();
126
+
127
+ header.click();
128
+ await el.updateComplete;
129
+ await frame();
130
+ await frame();
131
+
132
+ expect(sr(el).activeElement).toBe(header);
133
+ });
134
+
135
+ it('falls back to the wrapper when the header is disabled', async () => {
136
+ const el = await mount((e) => {
137
+ e.open = true;
138
+ e.disabled = true;
139
+ });
140
+ const inner = el.querySelector<HTMLButtonElement>('#inner')!;
141
+ inner.focus();
142
+ expect(document.activeElement).toBe(inner);
143
+
144
+ el.open = false;
145
+ await el.updateComplete;
146
+ await frame();
147
+ await frame();
148
+
149
+ // The disabled header cannot take focus, so the wrapper holds the place
150
+ // rather than letting it fall to <body>.
151
+ expect(sr(el).activeElement).toBe(sr(el).querySelector('.wrapper'));
152
+ expect(document.activeElement).not.toBe(document.body);
153
+ });
154
+
155
+ it('keeps the wrapper out of the tab order', async () => {
156
+ const el = await mount();
157
+ expect(sr(el).querySelector('.wrapper')!.getAttribute('tabindex')).toBe(
158
+ '-1'
159
+ );
160
+ });
161
+ });
@@ -1,5 +1,6 @@
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 componentStyle from './accordion-item.css?inline';
5
6
  import {property} from 'lit/decorators.js';
@@ -11,11 +12,10 @@ import '../../icons/icon-chevron-down-google.js';
11
12
  * 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.
12
13
  *
13
14
  * ### Features
14
- * - **Toggleable Expansion:** Click the header to expand or collapse the content area. The chevron icon visually indicates the current state.
15
+ * - **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.
15
16
  * - **Disabled State:** Prevents user interaction and visually indicates non-interactivity.
16
17
  * - **Customizable Content:** Slot for custom expanded content (`expanded-content`), supporting any HTML or component.
17
18
  * - **Optional Divider:** Can display a divider line below the item for visual separation in lists.
18
- * - **Show/Hide Content Area:** Optionally hide the expanded content area entirely (e.g., for header-only items).
19
19
  * - **Accessible:** Uses a button for the header with appropriate ARIA attributes for accessibility.
20
20
  *
21
21
  * ### Usage Guidelines
@@ -32,7 +32,7 @@ import '../../icons/icon-chevron-down-google.js';
32
32
  * ### Slots
33
33
  * | Slot Name | Renders When... | Purpose |
34
34
  * |-------------------|--------------------------|-------------------------------------------------|
35
- * | expanded-content | When `open` and `showContent` are true | Custom content displayed when expanded |
35
+ * | expanded-content | Always | Custom content revealed while the item is open |
36
36
  *
37
37
  * ### Events
38
38
  * - `accordion-item-toggle` – Fired when the item is toggled open or closed. Event detail: `{ open: boolean, title: string }`
@@ -57,8 +57,9 @@ import '../../icons/icon-chevron-down-google.js';
57
57
  * @property disabled - Disables the accordion item, preventing user interaction and dimming the appearance.
58
58
  * @property showDivider - Displays a divider line below the item for visual separation.
59
59
  * Useful when stacking multiple items in a list.
60
- * @slot expanded-content - Content displayed when the item is expanded and `showContent` is true.
60
+ * @slot expanded-content - Content revealed while the item is open.
61
61
  * @fires {CustomEvent<{open: boolean, title: string}>} accordion-item-toggle - Fired when the item is toggled open or closed.
62
+ * @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`.
62
63
  * @stable
63
64
  */
64
65
  @customElement('obc-accordion-item')
@@ -86,6 +87,26 @@ export class ObcAccordionItem extends LitElement {
86
87
  );
87
88
  }
88
89
 
90
+ /**
91
+ * Keeps the keyboard somewhere predictable when the panel closes.
92
+ *
93
+ * A collapsed panel is `inert`, and the browser drops focus out of anything
94
+ * it makes inert — onto `<body>`, two frames later. Clicking the header
95
+ * already leaves focus there; a consumer setting `open` while a slotted
96
+ * control has focus is the case that needs the transfer.
97
+ */
98
+ override willUpdate(changed: PropertyValues<this>) {
99
+ if (!changed.has('open') || this.open) return;
100
+
101
+ const panel = this.shadowRoot?.querySelector('.panel');
102
+ if (!panel) return;
103
+ releaseFocusBefore(
104
+ panel,
105
+ this.shadowRoot?.querySelector<HTMLButtonElement>('.content-button'),
106
+ this.shadowRoot?.querySelector<HTMLElement>('.wrapper')
107
+ );
108
+ }
109
+
89
110
  private renderContent() {
90
111
  return html`
91
112
  <div class="content">
@@ -102,11 +123,13 @@ export class ObcAccordionItem extends LitElement {
102
123
  }
103
124
 
104
125
  private renderExpandedContent() {
105
- if (!this.open) return '';
106
-
107
126
  return html`
108
- <div class="content-container">
109
- <slot name="expanded-content"></slot>
127
+ <div class="panel" id="accordion-content" ?inert=${!this.open}>
128
+ <div class="panel-inner">
129
+ <div class="content-container">
130
+ <slot name="expanded-content"></slot>
131
+ </div>
132
+ </div>
110
133
  </div>
111
134
  `;
112
135
  }
@@ -120,6 +143,7 @@ export class ObcAccordionItem extends LitElement {
120
143
  override render() {
121
144
  return html`
122
145
  <div
146
+ tabindex="-1"
123
147
  class=${classMap({
124
148
  wrapper: true,
125
149
  'state-disabled': this.disabled,
@@ -132,6 +156,7 @@ export class ObcAccordionItem extends LitElement {
132
156
  @click=${this.handleToggle}
133
157
  ?disabled=${this.disabled}
134
158
  aria-expanded=${this.open}
159
+ aria-controls="accordion-content"
135
160
  >
136
161
  ${this.renderContent()}
137
162
  </button>
@@ -1,5 +1,5 @@
1
1
  import {userEvent} from '@vitest/browser/context';
2
- import {deepActiveElement} from './focus.js';
2
+ import {composedContains, deepActiveElement} from './focus.js';
3
3
 
4
4
  /**
5
5
  * Focus and key helpers for keyboard specs.
@@ -12,20 +12,11 @@ import {deepActiveElement} from './focus.js';
12
12
  export {deepActiveElement};
13
13
 
14
14
  /**
15
- * Whether `node` sits under `ancestor`, crossing shadow boundaries.
15
+ * Whether `node` sits under `ancestor`, crossing shadow boundaries and slots.
16
16
  * `Element.contains()` stops at a shadow root, so a host never "contains"
17
17
  * the control it renders.
18
18
  */
19
- export function containsDeep(ancestor: Element, node: Node | null): boolean {
20
- let current: Node | null = node;
21
- while (current) {
22
- if (current === ancestor) return true;
23
- current =
24
- current.parentNode ??
25
- (current instanceof ShadowRoot ? current.host : null);
26
- }
27
- return false;
28
- }
19
+ export const containsDeep = composedContains;
29
20
 
30
21
  /** Presses Tab `count` times and records where focus lands each time. */
31
22
  export async function tabStops(count: number): Promise<(Element | null)[]> {