@oicl/openbridge-webcomponents-full-bundle 2.0.0-next.171 → 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.
Files changed (114) hide show
  1. package/bundle/openbridge-webcomponents.bundle.js +286 -105
  2. package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
  3. package/custom-elements.json +736 -46
  4. package/dist/automation/automation-button/abstract-automation-button-motorized.d.ts +11 -1
  5. package/dist/automation/automation-button/abstract-automation-button-motorized.d.ts.map +1 -1
  6. package/dist/automation/automation-button/abstract-automation-button-motorized.js +14 -4
  7. package/dist/automation/automation-button/abstract-automation-button-motorized.js.map +1 -1
  8. package/dist/automation/automation-button/abstract-automation-button-squared.d.ts +25 -1
  9. package/dist/automation/automation-button/abstract-automation-button-squared.d.ts.map +1 -1
  10. package/dist/automation/automation-button/abstract-automation-button-squared.js +27 -3
  11. package/dist/automation/automation-button/abstract-automation-button-squared.js.map +1 -1
  12. package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.d.ts +12 -0
  13. package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.d.ts.map +1 -1
  14. package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.js +8 -0
  15. package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.js.map +1 -1
  16. package/dist/automation/bipolar-transistor/bipolar-transistor.js +4 -4
  17. package/dist/automation/bipolar-transistor/bipolar-transistor.js.map +1 -1
  18. package/dist/automation/capacitor/capacitor.js +4 -4
  19. package/dist/automation/capacitor/capacitor.js.map +1 -1
  20. package/dist/automation/converter/converter.js +4 -4
  21. package/dist/automation/converter/converter.js.map +1 -1
  22. package/dist/automation/damper/damper.js +1 -1
  23. package/dist/automation/damper/damper.js.map +1 -1
  24. package/dist/automation/diodes/diodes.js +6 -6
  25. package/dist/automation/diodes/diodes.js.map +1 -1
  26. package/dist/automation/fan/fan.js +1 -1
  27. package/dist/automation/fan/fan.js.map +1 -1
  28. package/dist/automation/filter/filter.js +4 -4
  29. package/dist/automation/filter/filter.js.map +1 -1
  30. package/dist/automation/ground/ground.js +3 -3
  31. package/dist/automation/ground/ground.js.map +1 -1
  32. package/dist/automation/logic/logic.js +6 -6
  33. package/dist/automation/logic/logic.js.map +1 -1
  34. package/dist/automation/mosfet/mosfet.js +8 -8
  35. package/dist/automation/mosfet/mosfet.js.map +1 -1
  36. package/dist/automation/motor/motor.js +2 -2
  37. package/dist/automation/motor/motor.js.map +1 -1
  38. package/dist/automation/pump/pump.js +2 -2
  39. package/dist/automation/pump/pump.js.map +1 -1
  40. package/dist/automation/resistor/resistor.js +5 -5
  41. package/dist/automation/resistor/resistor.js.map +1 -1
  42. package/dist/automation/router/router.js +2 -2
  43. package/dist/automation/router/router.js.map +1 -1
  44. package/dist/automation/source/source.js +5 -5
  45. package/dist/automation/source/source.js.map +1 -1
  46. package/dist/automation/switch/switch.js +4 -4
  47. package/dist/automation/switch/switch.js.map +1 -1
  48. package/dist/automation/transformer/transformer.js +2 -2
  49. package/dist/automation/transformer/transformer.js.map +1 -1
  50. package/dist/components/accordion-card/accordion-card.css.js +61 -19
  51. package/dist/components/accordion-card/accordion-card.css.js.map +1 -1
  52. package/dist/components/accordion-card/accordion-card.d.ts +12 -3
  53. package/dist/components/accordion-card/accordion-card.d.ts.map +1 -1
  54. package/dist/components/accordion-card/accordion-card.js +23 -5
  55. package/dist/components/accordion-card/accordion-card.js.map +1 -1
  56. package/dist/components/accordion-item/accordion-item.css.js +40 -9
  57. package/dist/components/accordion-item/accordion-item.css.js.map +1 -1
  58. package/dist/components/accordion-item/accordion-item.d.ts +14 -5
  59. package/dist/components/accordion-item/accordion-item.d.ts.map +1 -1
  60. package/dist/components/accordion-item/accordion-item.js +23 -3
  61. package/dist/components/accordion-item/accordion-item.js.map +1 -1
  62. package/dist/internal/focus.d.ts +23 -0
  63. package/dist/internal/focus.d.ts.map +1 -1
  64. package/dist/internal/focus.js +38 -1
  65. package/dist/internal/focus.js.map +1 -1
  66. package/eslint.config.mjs +56 -0
  67. package/package.json +1 -1
  68. package/script/eslint-rules.test.ts +44 -0
  69. package/src/automation/automation-button/abstract-automation-button-motorized.ts +20 -4
  70. package/src/automation/automation-button/abstract-automation-button-squared.ts +33 -3
  71. package/src/automation/automation-button/abstract-automation-button-storybook-helpers.ts +2 -0
  72. package/src/automation/automation-button/turned-on.spec.ts +64 -0
  73. package/src/automation/bipolar-transistor/bipolar-transistor.stories.ts +2 -2
  74. package/src/automation/bipolar-transistor/bipolar-transistor.ts +4 -4
  75. package/src/automation/capacitor/capacitor.stories.ts +2 -2
  76. package/src/automation/capacitor/capacitor.ts +4 -4
  77. package/src/automation/converter/converter.stories.ts +2 -2
  78. package/src/automation/converter/converter.ts +4 -4
  79. package/src/automation/damper/damper.stories.ts +2 -2
  80. package/src/automation/damper/damper.ts +1 -1
  81. package/src/automation/diodes/diodes.stories.ts +2 -2
  82. package/src/automation/diodes/diodes.ts +6 -6
  83. package/src/automation/fan/fan.stories.ts +3 -3
  84. package/src/automation/fan/fan.ts +1 -1
  85. package/src/automation/filter/filter.stories.ts +2 -2
  86. package/src/automation/filter/filter.ts +4 -4
  87. package/src/automation/ground/ground.stories.ts +2 -2
  88. package/src/automation/ground/ground.ts +3 -3
  89. package/src/automation/logic/logic.stories.ts +2 -2
  90. package/src/automation/logic/logic.ts +6 -6
  91. package/src/automation/mosfet/mosfet.stories.ts +2 -2
  92. package/src/automation/mosfet/mosfet.ts +8 -8
  93. package/src/automation/motor/motor.stories.ts +7 -7
  94. package/src/automation/motor/motor.ts +2 -2
  95. package/src/automation/pump/pump.stories.ts +5 -5
  96. package/src/automation/pump/pump.ts +2 -2
  97. package/src/automation/resistor/resistor.stories.ts +2 -2
  98. package/src/automation/resistor/resistor.ts +5 -5
  99. package/src/automation/router/router.stories.ts +2 -2
  100. package/src/automation/router/router.ts +2 -2
  101. package/src/automation/source/source.stories.ts +2 -2
  102. package/src/automation/source/source.ts +5 -5
  103. package/src/automation/switch/switch.stories.ts +4 -4
  104. package/src/automation/switch/switch.ts +4 -4
  105. package/src/automation/transformer/transformer.stories.ts +2 -2
  106. package/src/automation/transformer/transformer.ts +2 -2
  107. package/src/components/accordion-card/accordion-card.css +57 -15
  108. package/src/components/accordion-card/accordion-card.spec.ts +171 -0
  109. package/src/components/accordion-card/accordion-card.ts +32 -12
  110. package/src/components/accordion-item/accordion-item.css +40 -9
  111. package/src/components/accordion-item/accordion-item.spec.ts +161 -0
  112. package/src/components/accordion-item/accordion-item.ts +34 -9
  113. package/src/internal/_test-utils.ts +3 -12
  114. package/src/internal/focus.ts +45 -0
@@ -34,12 +34,12 @@ type Story = StoryObj<ObcResistor>;
34
34
 
35
35
  export const On: Story = {
36
36
  args: {
37
- on: true,
37
+ turnedOn: true,
38
38
  },
39
39
  };
40
40
 
41
41
  export const Off: Story = {
42
42
  args: {
43
- on: false,
43
+ turnedOn: false,
44
44
  },
45
45
  };
@@ -32,7 +32,7 @@ export class ObcResistor extends ObcAbstractAutomationButtonSquared {
32
32
  override get icon() {
33
33
  switch (this.alternativeIcon) {
34
34
  case ResistorAlternativeIcon.resistor2:
35
- if (this.on) {
35
+ if (this.turnedOn) {
36
36
  return html`<obi-resistor-2-on
37
37
  usecsscolor
38
38
  slot="icon"
@@ -52,7 +52,7 @@ export class ObcResistor extends ObcAbstractAutomationButtonSquared {
52
52
  ></obi-resistor-2-off>`;
53
53
  }
54
54
  case ResistorAlternativeIcon.resistor3:
55
- if (this.on) {
55
+ if (this.turnedOn) {
56
56
  return html`<obi-resistor-3-on
57
57
  usecsscolor
58
58
  slot="icon"
@@ -72,7 +72,7 @@ export class ObcResistor extends ObcAbstractAutomationButtonSquared {
72
72
  ></obi-resistor-3-off>`;
73
73
  }
74
74
  case ResistorAlternativeIcon.resistor4:
75
- if (this.on) {
75
+ if (this.turnedOn) {
76
76
  return html`<obi-resistor-4-on
77
77
  usecsscolor
78
78
  slot="icon"
@@ -92,7 +92,7 @@ export class ObcResistor extends ObcAbstractAutomationButtonSquared {
92
92
  ></obi-resistor-4-off>`;
93
93
  }
94
94
  case ResistorAlternativeIcon.resistor5:
95
- if (this.on) {
95
+ if (this.turnedOn) {
96
96
  return html`<obi-resistor-5-on
97
97
  usecsscolor
98
98
  slot="icon"
@@ -112,7 +112,7 @@ export class ObcResistor extends ObcAbstractAutomationButtonSquared {
112
112
  ></obi-resistor-5-off>`;
113
113
  }
114
114
  default:
115
- if (this.on) {
115
+ if (this.turnedOn) {
116
116
  return html`<obi-resistor-1-on
117
117
  usecsscolor
118
118
  slot="icon"
@@ -34,12 +34,12 @@ type Story = StoryObj<ObcRouter>;
34
34
 
35
35
  export const On: Story = {
36
36
  args: {
37
- on: true,
37
+ turnedOn: true,
38
38
  },
39
39
  };
40
40
 
41
41
  export const Off: Story = {
42
42
  args: {
43
- on: false,
43
+ turnedOn: false,
44
44
  },
45
45
  };
@@ -23,7 +23,7 @@ export class ObcRouter extends ObcAbstractAutomationButtonSquared {
23
23
  override get icon() {
24
24
  switch (this.alternativeIcon) {
25
25
  case RouterAlternativeIcon.router2:
26
- if (this.on) {
26
+ if (this.turnedOn) {
27
27
  return html`<obi-router-2-on
28
28
  usecsscolor
29
29
  slot="icon"
@@ -43,7 +43,7 @@ export class ObcRouter extends ObcAbstractAutomationButtonSquared {
43
43
  ></obi-router-2-off>`;
44
44
  }
45
45
  default:
46
- if (this.on) {
46
+ if (this.turnedOn) {
47
47
  return html`<obi-router-on usecsscolor slot="icon"></obi-router-on>
48
48
  <obi-router-on usecsscolor slot="icon-silhouette"></obi-router-on>`;
49
49
  } else {
@@ -34,12 +34,12 @@ type Story = StoryObj<ObcSource>;
34
34
 
35
35
  export const On: Story = {
36
36
  args: {
37
- on: true,
37
+ turnedOn: true,
38
38
  },
39
39
  };
40
40
 
41
41
  export const Off: Story = {
42
42
  args: {
43
- on: false,
43
+ turnedOn: false,
44
44
  },
45
45
  };
@@ -32,7 +32,7 @@ export class ObcSource extends ObcAbstractAutomationButtonSquared {
32
32
  override get icon() {
33
33
  switch (this.alternativeIcon) {
34
34
  case SourceAlternativeIcon.sources02:
35
- if (this.on) {
35
+ if (this.turnedOn) {
36
36
  return html`<obi-sources-02-on
37
37
  usecsscolor
38
38
  slot="icon"
@@ -52,7 +52,7 @@ export class ObcSource extends ObcAbstractAutomationButtonSquared {
52
52
  ></obi-sources-02-off>`;
53
53
  }
54
54
  case SourceAlternativeIcon.sources03:
55
- if (this.on) {
55
+ if (this.turnedOn) {
56
56
  return html`<obi-sources-03-on
57
57
  usecsscolor
58
58
  slot="icon"
@@ -72,7 +72,7 @@ export class ObcSource extends ObcAbstractAutomationButtonSquared {
72
72
  ></obi-sources-03-off>`;
73
73
  }
74
74
  case SourceAlternativeIcon.sources04:
75
- if (this.on) {
75
+ if (this.turnedOn) {
76
76
  return html`<obi-sources-04-on
77
77
  usecsscolor
78
78
  slot="icon"
@@ -92,7 +92,7 @@ export class ObcSource extends ObcAbstractAutomationButtonSquared {
92
92
  ></obi-sources-04-off>`;
93
93
  }
94
94
  case SourceAlternativeIcon.sources05:
95
- if (this.on) {
95
+ if (this.turnedOn) {
96
96
  return html`<obi-sources-05-on
97
97
  usecsscolor
98
98
  slot="icon"
@@ -112,7 +112,7 @@ export class ObcSource extends ObcAbstractAutomationButtonSquared {
112
112
  ></obi-sources-05-off>`;
113
113
  }
114
114
  default:
115
- if (this.on) {
115
+ if (this.turnedOn) {
116
116
  return html`<obi-sources-01-on
117
117
  usecsscolor
118
118
  slot="icon"
@@ -39,26 +39,26 @@ type Story = StoryObj<ObcSwitch>;
39
39
 
40
40
  export const On: Story = {
41
41
  args: {
42
- on: true,
42
+ turnedOn: true,
43
43
  },
44
44
  };
45
45
 
46
46
  export const Off: Story = {
47
47
  args: {
48
- on: false,
48
+ turnedOn: false,
49
49
  },
50
50
  };
51
51
 
52
52
  export const OrientationVerticalRight: Story = {
53
53
  args: {
54
- on: false,
54
+ turnedOn: false,
55
55
  orientation: AutomationButtonOrientation.verticalRight,
56
56
  },
57
57
  };
58
58
 
59
59
  export const OrientationVerticalLeft: Story = {
60
60
  args: {
61
- on: false,
61
+ turnedOn: false,
62
62
  orientation: AutomationButtonOrientation.verticalLeft,
63
63
  },
64
64
  };
@@ -29,7 +29,7 @@ export class ObcSwitch extends ObcAbstractAutomationButtonSquared {
29
29
  override get icon() {
30
30
  switch (this.alternativeIcon) {
31
31
  case SwitchAlternativeIcon.s1:
32
- if (this.on) {
32
+ if (this.turnedOn) {
33
33
  return html`<obi-switch-01-on
34
34
  usecsscolor
35
35
  slot="icon"
@@ -49,7 +49,7 @@ export class ObcSwitch extends ObcAbstractAutomationButtonSquared {
49
49
  ></obi-switch-01-off>`;
50
50
  }
51
51
  case SwitchAlternativeIcon.s2:
52
- if (this.on) {
52
+ if (this.turnedOn) {
53
53
  return html`<obi-switch-02-on
54
54
  usecsscolor
55
55
  slot="icon"
@@ -69,7 +69,7 @@ export class ObcSwitch extends ObcAbstractAutomationButtonSquared {
69
69
  ></obi-switch-02-off>`;
70
70
  }
71
71
  case SwitchAlternativeIcon.s3:
72
- if (this.on) {
72
+ if (this.turnedOn) {
73
73
  return html`<obi-switch-03-on
74
74
  usecsscolor
75
75
  slot="icon"
@@ -89,7 +89,7 @@ export class ObcSwitch extends ObcAbstractAutomationButtonSquared {
89
89
  ></obi-switch-03-off>`;
90
90
  }
91
91
  default:
92
- if (this.on) {
92
+ if (this.turnedOn) {
93
93
  return html`<obi-switch-horizontal-on
94
94
  usecsscolor
95
95
  slot="icon"
@@ -34,12 +34,12 @@ type Story = StoryObj<ObcTransformer>;
34
34
 
35
35
  export const On: Story = {
36
36
  args: {
37
- on: true,
37
+ turnedOn: true,
38
38
  },
39
39
  };
40
40
 
41
41
  export const Off: Story = {
42
42
  args: {
43
- on: false,
43
+ turnedOn: false,
44
44
  },
45
45
  };
@@ -23,7 +23,7 @@ export class ObcTransformer extends ObcAbstractAutomationButtonSquared {
23
23
  override get icon() {
24
24
  switch (this.alternativeIcon) {
25
25
  case TransformerAlternativeIcon.transformer02:
26
- if (this.on) {
26
+ if (this.turnedOn) {
27
27
  return html`<obi-transformer-02-on
28
28
  usecsscolor
29
29
  slot="icon"
@@ -43,7 +43,7 @@ export class ObcTransformer extends ObcAbstractAutomationButtonSquared {
43
43
  ></obi-transformer-02-off>`;
44
44
  }
45
45
  default:
46
- if (this.on) {
46
+ if (this.turnedOn) {
47
47
  return html`<obi-transformer-01-on
48
48
  usecsscolor
49
49
  slot="icon"
@@ -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
- & .container-content-additional {
115
- color: var(--element-neutral-color);
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="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,