@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.
- package/bundle/openbridge-webcomponents.bundle.js +286 -105
- package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
- package/custom-elements.json +736 -46
- package/dist/automation/automation-button/abstract-automation-button-motorized.d.ts +11 -1
- package/dist/automation/automation-button/abstract-automation-button-motorized.d.ts.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button-motorized.js +14 -4
- package/dist/automation/automation-button/abstract-automation-button-motorized.js.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button-squared.d.ts +25 -1
- package/dist/automation/automation-button/abstract-automation-button-squared.d.ts.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button-squared.js +27 -3
- package/dist/automation/automation-button/abstract-automation-button-squared.js.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.d.ts +12 -0
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.d.ts.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.js +8 -0
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.js.map +1 -1
- package/dist/automation/bipolar-transistor/bipolar-transistor.js +4 -4
- package/dist/automation/bipolar-transistor/bipolar-transistor.js.map +1 -1
- package/dist/automation/capacitor/capacitor.js +4 -4
- package/dist/automation/capacitor/capacitor.js.map +1 -1
- package/dist/automation/converter/converter.js +4 -4
- package/dist/automation/converter/converter.js.map +1 -1
- package/dist/automation/damper/damper.js +1 -1
- package/dist/automation/damper/damper.js.map +1 -1
- package/dist/automation/diodes/diodes.js +6 -6
- package/dist/automation/diodes/diodes.js.map +1 -1
- package/dist/automation/fan/fan.js +1 -1
- package/dist/automation/fan/fan.js.map +1 -1
- package/dist/automation/filter/filter.js +4 -4
- package/dist/automation/filter/filter.js.map +1 -1
- package/dist/automation/ground/ground.js +3 -3
- package/dist/automation/ground/ground.js.map +1 -1
- package/dist/automation/logic/logic.js +6 -6
- package/dist/automation/logic/logic.js.map +1 -1
- package/dist/automation/mosfet/mosfet.js +8 -8
- package/dist/automation/mosfet/mosfet.js.map +1 -1
- package/dist/automation/motor/motor.js +2 -2
- package/dist/automation/motor/motor.js.map +1 -1
- package/dist/automation/pump/pump.js +2 -2
- package/dist/automation/pump/pump.js.map +1 -1
- package/dist/automation/resistor/resistor.js +5 -5
- package/dist/automation/resistor/resistor.js.map +1 -1
- package/dist/automation/router/router.js +2 -2
- package/dist/automation/router/router.js.map +1 -1
- package/dist/automation/source/source.js +5 -5
- package/dist/automation/source/source.js.map +1 -1
- package/dist/automation/switch/switch.js +4 -4
- package/dist/automation/switch/switch.js.map +1 -1
- package/dist/automation/transformer/transformer.js +2 -2
- package/dist/automation/transformer/transformer.js.map +1 -1
- 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/eslint.config.mjs +56 -0
- package/package.json +1 -1
- package/script/eslint-rules.test.ts +44 -0
- package/src/automation/automation-button/abstract-automation-button-motorized.ts +20 -4
- package/src/automation/automation-button/abstract-automation-button-squared.ts +33 -3
- package/src/automation/automation-button/abstract-automation-button-storybook-helpers.ts +2 -0
- package/src/automation/automation-button/turned-on.spec.ts +64 -0
- package/src/automation/bipolar-transistor/bipolar-transistor.stories.ts +2 -2
- package/src/automation/bipolar-transistor/bipolar-transistor.ts +4 -4
- package/src/automation/capacitor/capacitor.stories.ts +2 -2
- package/src/automation/capacitor/capacitor.ts +4 -4
- package/src/automation/converter/converter.stories.ts +2 -2
- package/src/automation/converter/converter.ts +4 -4
- package/src/automation/damper/damper.stories.ts +2 -2
- package/src/automation/damper/damper.ts +1 -1
- package/src/automation/diodes/diodes.stories.ts +2 -2
- package/src/automation/diodes/diodes.ts +6 -6
- package/src/automation/fan/fan.stories.ts +3 -3
- package/src/automation/fan/fan.ts +1 -1
- package/src/automation/filter/filter.stories.ts +2 -2
- package/src/automation/filter/filter.ts +4 -4
- package/src/automation/ground/ground.stories.ts +2 -2
- package/src/automation/ground/ground.ts +3 -3
- package/src/automation/logic/logic.stories.ts +2 -2
- package/src/automation/logic/logic.ts +6 -6
- package/src/automation/mosfet/mosfet.stories.ts +2 -2
- package/src/automation/mosfet/mosfet.ts +8 -8
- package/src/automation/motor/motor.stories.ts +7 -7
- package/src/automation/motor/motor.ts +2 -2
- package/src/automation/pump/pump.stories.ts +5 -5
- package/src/automation/pump/pump.ts +2 -2
- package/src/automation/resistor/resistor.stories.ts +2 -2
- package/src/automation/resistor/resistor.ts +5 -5
- package/src/automation/router/router.stories.ts +2 -2
- package/src/automation/router/router.ts +2 -2
- package/src/automation/source/source.stories.ts +2 -2
- package/src/automation/source/source.ts +5 -5
- package/src/automation/switch/switch.stories.ts +4 -4
- package/src/automation/switch/switch.ts +4 -4
- package/src/automation/transformer/transformer.stories.ts +2 -2
- package/src/automation/transformer/transformer.ts +2 -2
- 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
|
@@ -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
|
|
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
|
-
.
|
|
108
|
-
display:
|
|
109
|
-
|
|
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
|
-
|
|
120
|
+
transition: grid-template-rows var(--_expand-duration) ease;
|
|
112
121
|
}
|
|
113
122
|
|
|
114
|
-
.wrapper.open-true .
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
.
|
|
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
|
|
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 |
|
|
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
|
|
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
|
|
109
|
-
<
|
|
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
|
|
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)[]> {
|
package/src/internal/focus.ts
CHANGED
|
@@ -19,6 +19,51 @@ export function deepActiveElement(): Element | null {
|
|
|
19
19
|
return active;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Whether `node` sits inside `root` in the composed tree.
|
|
24
|
+
*
|
|
25
|
+
* `Node.contains()` walks the DOM tree, where slotted light-DOM content is a
|
|
26
|
+
* child of the host and not of the slot — so it answers no for exactly the
|
|
27
|
+
* content a component projects into itself. This follows `assignedSlot` and
|
|
28
|
+
* shadow hosts as well.
|
|
29
|
+
*/
|
|
30
|
+
export function composedContains(root: Node, node: Node | null): boolean {
|
|
31
|
+
let current: Node | null = node;
|
|
32
|
+
while (current) {
|
|
33
|
+
if (current === root) return true;
|
|
34
|
+
current =
|
|
35
|
+
(current as Element).assignedSlot ??
|
|
36
|
+
current.parentNode ??
|
|
37
|
+
(current instanceof ShadowRoot ? current.host : null);
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Moves focus out of `hidden`, to the first fallback that will take it.
|
|
44
|
+
*
|
|
45
|
+
* Call it just before a region becomes `inert` or is taken out of the page.
|
|
46
|
+
* The browser blurs whatever it hides, and focus lands on `<body>` a frame or
|
|
47
|
+
* two later, so the next Tab press starts from the top of the document instead
|
|
48
|
+
* of where the user was.
|
|
49
|
+
*
|
|
50
|
+
* Each candidate is tried and then checked, rather than inspected first: a
|
|
51
|
+
* `disabled` button, a hidden one and an element with no tabindex all refuse
|
|
52
|
+
* focus for different reasons, and the only reliable question is whether focus
|
|
53
|
+
* actually left.
|
|
54
|
+
*/
|
|
55
|
+
export function releaseFocusBefore(
|
|
56
|
+
hidden: Node,
|
|
57
|
+
...fallbacks: (HTMLElement | null | undefined)[]
|
|
58
|
+
): void {
|
|
59
|
+
if (!composedContains(hidden, deepActiveElement())) return;
|
|
60
|
+
for (const candidate of fallbacks) {
|
|
61
|
+
if (!candidate) continue;
|
|
62
|
+
candidate.focus();
|
|
63
|
+
if (!composedContains(hidden, deepActiveElement())) return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
22
67
|
function isTabbable(element: Element): element is HTMLElement {
|
|
23
68
|
if (!element.matches(TABBABLE_SELECTOR)) return false;
|
|
24
69
|
if ((element as HTMLElement).tabIndex < 0) return false;
|