@oicl/openbridge-webcomponents-full-bundle 2.1.0 → 2.2.0-next.2
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 +59 -16
- package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
- package/custom-elements.json +121 -9
- package/dist/components/icon-button/icon-button.d.ts +2 -0
- package/dist/components/icon-button/icon-button.d.ts.map +1 -1
- package/dist/components/icon-button/icon-button.js +4 -0
- package/dist/components/icon-button/icon-button.js.map +1 -1
- package/dist/components/split-button/split-button.css.js +5 -0
- package/dist/components/split-button/split-button.css.js.map +1 -1
- package/dist/components/split-button/split-button.d.ts +35 -5
- package/dist/components/split-button/split-button.d.ts.map +1 -1
- package/dist/components/split-button/split-button.js +23 -5
- package/dist/components/split-button/split-button.js.map +1 -1
- package/dist/components/top-bar/top-bar.css.js +2 -2
- package/dist/components/top-bar/top-bar.css.js.map +1 -1
- package/dist/components/top-bar/top-bar.d.ts +23 -8
- package/dist/components/top-bar/top-bar.d.ts.map +1 -1
- package/dist/components/top-bar/top-bar.js +25 -9
- package/dist/components/top-bar/top-bar.js.map +1 -1
- package/package.json +1 -1
- package/src/components/icon-button/icon-button.ts +5 -0
- package/src/components/split-button/split-button.css +7 -0
- package/src/components/split-button/split-button.spec.ts +241 -0
- package/src/components/split-button/split-button.stories.ts +118 -2
- package/src/components/split-button/split-button.ts +53 -9
- package/src/components/textarea-field/textarea-field.spec.ts +30 -0
- package/src/components/top-bar/top-bar-more-button.spec.ts +60 -0
- package/src/components/top-bar/top-bar.css +2 -2
- package/src/components/top-bar/top-bar.ts +47 -14
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import {describe, expect, it} from 'vitest';
|
|
2
|
+
import {render} from 'vitest-browser-lit';
|
|
3
|
+
import {userEvent} from '@vitest/browser/context';
|
|
4
|
+
import {html, type TemplateResult} from 'lit';
|
|
5
|
+
import '../../main.css';
|
|
6
|
+
import './split-button.js';
|
|
7
|
+
import '../../icons/icon-command-request.js';
|
|
8
|
+
import type {ObcSplitButton} from './split-button.js';
|
|
9
|
+
import type {ObcButton} from '../button/button.js';
|
|
10
|
+
import type {ObcIconButton} from '../icon-button/icon-button.js';
|
|
11
|
+
import type {ObcContextMenuInput} from '../context-menu-input/context-menu-input.js';
|
|
12
|
+
import {containsDeep, deepActiveElement} from '../../internal/_test-utils.js';
|
|
13
|
+
|
|
14
|
+
const options = [
|
|
15
|
+
{value: 'a', label: 'Alpha'},
|
|
16
|
+
{value: 'b', label: 'Bravo'},
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
async function setup(template: TemplateResult) {
|
|
20
|
+
const screen = render(template);
|
|
21
|
+
const el = screen.container.querySelector(
|
|
22
|
+
'obc-split-button'
|
|
23
|
+
) as ObcSplitButton;
|
|
24
|
+
await el.updateComplete;
|
|
25
|
+
const primary = el.shadowRoot!.querySelector('obc-button') as ObcButton;
|
|
26
|
+
const dropdown = el.shadowRoot!.querySelector(
|
|
27
|
+
'obc-icon-button'
|
|
28
|
+
) as ObcIconButton;
|
|
29
|
+
await primary.updateComplete;
|
|
30
|
+
await dropdown.updateComplete;
|
|
31
|
+
return {screen, el, primary, dropdown};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function menuOf(el: ObcSplitButton) {
|
|
35
|
+
return el.shadowRoot!.querySelector(
|
|
36
|
+
'obc-context-menu-input'
|
|
37
|
+
) as ObcContextMenuInput | null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function openMenu(el: ObcSplitButton, dropdown: ObcIconButton) {
|
|
41
|
+
await userEvent.click(dropdown.shadowRoot!.querySelector('button')!);
|
|
42
|
+
await el.updateComplete;
|
|
43
|
+
const menu = menuOf(el)!;
|
|
44
|
+
await menu.updateComplete;
|
|
45
|
+
return menu;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const nextTask = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A key on the dropdown's native button. The split button listens on the
|
|
52
|
+
* icon button's host, so the event has to be composed to cross its shadow
|
|
53
|
+
* root, as a real key press is.
|
|
54
|
+
*/
|
|
55
|
+
async function pressOnDropdown(
|
|
56
|
+
el: ObcSplitButton,
|
|
57
|
+
dropdown: ObcIconButton,
|
|
58
|
+
key: string
|
|
59
|
+
) {
|
|
60
|
+
dropdown
|
|
61
|
+
.shadowRoot!.querySelector('button')!
|
|
62
|
+
.dispatchEvent(
|
|
63
|
+
new KeyboardEvent('keydown', {key, bubbles: true, composed: true})
|
|
64
|
+
);
|
|
65
|
+
await el.updateComplete;
|
|
66
|
+
await nextTask();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe('obc-split-button dropdown icon', () => {
|
|
70
|
+
it('renders the chevron when nothing fills the dropdown-icon slot', async () => {
|
|
71
|
+
const {el} = await setup(
|
|
72
|
+
html`<obc-split-button .options=${options}></obc-split-button>`
|
|
73
|
+
);
|
|
74
|
+
const slot = el.shadowRoot!.querySelector<HTMLSlotElement>(
|
|
75
|
+
'slot[name="dropdown-icon"]'
|
|
76
|
+
)!;
|
|
77
|
+
|
|
78
|
+
expect(slot.assignedElements()).toHaveLength(0);
|
|
79
|
+
expect(slot.querySelector('obi-arrow-flyout-google')).not.toBeNull();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('shows a slotted icon inside the dropdown button instead of the chevron', async () => {
|
|
83
|
+
const {dropdown} = await setup(
|
|
84
|
+
html`<obc-split-button .options=${options}>
|
|
85
|
+
<obi-command-request slot="dropdown-icon"></obi-command-request>
|
|
86
|
+
</obc-split-button>`
|
|
87
|
+
);
|
|
88
|
+
const iconSlot =
|
|
89
|
+
dropdown.shadowRoot!.querySelector<HTMLSlotElement>('slot:not([name])')!;
|
|
90
|
+
const shown = iconSlot
|
|
91
|
+
.assignedElements({flatten: true})
|
|
92
|
+
.map((node) => node.tagName.toLowerCase());
|
|
93
|
+
|
|
94
|
+
expect(shown).toEqual(['obi-command-request']);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('obc-split-button halves disabled separately', () => {
|
|
99
|
+
it('primaryDisabled disables the primary half and keeps the menu usable', async () => {
|
|
100
|
+
const {el, primary, dropdown} = await setup(
|
|
101
|
+
html`<obc-split-button
|
|
102
|
+
.options=${options}
|
|
103
|
+
primaryDisabled
|
|
104
|
+
></obc-split-button>`
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
expect(primary.disabled).toBe(true);
|
|
108
|
+
expect(primary.shadowRoot!.querySelector('button')!.disabled).toBe(true);
|
|
109
|
+
expect(dropdown.disabled).toBe(false);
|
|
110
|
+
|
|
111
|
+
await openMenu(el, dropdown);
|
|
112
|
+
expect(menuOf(el)).not.toBeNull();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('dropdownDisabled disables the dropdown half and keeps the primary action', async () => {
|
|
116
|
+
const clicks: string[] = [];
|
|
117
|
+
const {el, primary, dropdown} = await setup(
|
|
118
|
+
html`<obc-split-button
|
|
119
|
+
.options=${options}
|
|
120
|
+
dropdownDisabled
|
|
121
|
+
@click=${(event: CustomEvent<{action: string}>) =>
|
|
122
|
+
clicks.push(event.detail.action)}
|
|
123
|
+
></obc-split-button>`
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
expect(dropdown.disabled).toBe(true);
|
|
127
|
+
expect(primary.disabled).toBe(false);
|
|
128
|
+
|
|
129
|
+
await userEvent.click(primary.shadowRoot!.querySelector('button')!);
|
|
130
|
+
expect(clicks).toEqual(['primary']);
|
|
131
|
+
|
|
132
|
+
await pressOnDropdown(el, dropdown, 'ArrowDown');
|
|
133
|
+
expect(menuOf(el)).toBeNull();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('disabled still disables both halves', async () => {
|
|
137
|
+
const {primary, dropdown} = await setup(
|
|
138
|
+
html`<obc-split-button .options=${options} disabled></obc-split-button>`
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
expect(primary.disabled).toBe(true);
|
|
142
|
+
expect(dropdown.disabled).toBe(true);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('Tab skips the disabled half', async () => {
|
|
146
|
+
const {screen, dropdown} = await setup(
|
|
147
|
+
html`<button id="before">before</button>
|
|
148
|
+
<obc-split-button
|
|
149
|
+
.options=${options}
|
|
150
|
+
primaryDisabled
|
|
151
|
+
></obc-split-button>`
|
|
152
|
+
);
|
|
153
|
+
screen.container.querySelector<HTMLElement>('#before')!.focus();
|
|
154
|
+
|
|
155
|
+
await userEvent.tab();
|
|
156
|
+
|
|
157
|
+
expect(containsDeep(dropdown, deepActiveElement())).toBe(true);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
describe('obc-split-button keyboard', () => {
|
|
162
|
+
it('ArrowDown on the dropdown opens the menu on its first item', async () => {
|
|
163
|
+
const {el, dropdown} = await setup(
|
|
164
|
+
html`<obc-split-button .options=${options}></obc-split-button>`
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
await pressOnDropdown(el, dropdown, 'ArrowDown');
|
|
168
|
+
|
|
169
|
+
const menu = menuOf(el);
|
|
170
|
+
expect(menu).not.toBeNull();
|
|
171
|
+
expect(containsDeep(menu!, deepActiveElement())).toBe(true);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('Escape closes the menu and returns focus to the dropdown half', async () => {
|
|
175
|
+
const {el, dropdown} = await setup(
|
|
176
|
+
html`<obc-split-button .options=${options}></obc-split-button>`
|
|
177
|
+
);
|
|
178
|
+
const menu = await openMenu(el, dropdown);
|
|
179
|
+
await nextTask();
|
|
180
|
+
expect(containsDeep(menu, deepActiveElement())).toBe(true);
|
|
181
|
+
|
|
182
|
+
await userEvent.keyboard('{Escape}');
|
|
183
|
+
await el.updateComplete;
|
|
184
|
+
await nextTask();
|
|
185
|
+
|
|
186
|
+
expect(menuOf(el)).toBeNull();
|
|
187
|
+
expect(containsDeep(dropdown, deepActiveElement())).toBe(true);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe('obc-split-button menu placement', () => {
|
|
192
|
+
const rightAligned = (inner: TemplateResult) =>
|
|
193
|
+
html`<div style="display: flex; justify-content: flex-end; width: 600px">
|
|
194
|
+
${inner}
|
|
195
|
+
</div>`;
|
|
196
|
+
|
|
197
|
+
it('starts the menu at the dropdown half by default', async () => {
|
|
198
|
+
const {el, dropdown} = await setup(
|
|
199
|
+
rightAligned(
|
|
200
|
+
html`<obc-split-button .options=${options}></obc-split-button>`
|
|
201
|
+
)
|
|
202
|
+
);
|
|
203
|
+
const menu = await openMenu(el, dropdown);
|
|
204
|
+
|
|
205
|
+
const menuRect = menu.getBoundingClientRect();
|
|
206
|
+
expect(menuRect.left).toBeCloseTo(dropdown.getBoundingClientRect().left, 0);
|
|
207
|
+
expect(menuRect.top).toBeCloseTo(el.getBoundingClientRect().bottom, 0);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('openLeft ends the menu at the right edge of the button', async () => {
|
|
211
|
+
const {el, dropdown} = await setup(
|
|
212
|
+
rightAligned(
|
|
213
|
+
html`<obc-split-button .options=${options} openLeft></obc-split-button>`
|
|
214
|
+
)
|
|
215
|
+
);
|
|
216
|
+
const menu = await openMenu(el, dropdown);
|
|
217
|
+
|
|
218
|
+
const menuRect = menu.getBoundingClientRect();
|
|
219
|
+
expect(menuRect.right).toBeCloseTo(el.getBoundingClientRect().right, 0);
|
|
220
|
+
expect(menuRect.top).toBeCloseTo(el.getBoundingClientRect().bottom, 0);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('openLeft and openTop combine', async () => {
|
|
224
|
+
const {el, dropdown} = await setup(
|
|
225
|
+
html`<div style="padding-top: 300px">
|
|
226
|
+
${rightAligned(
|
|
227
|
+
html`<obc-split-button
|
|
228
|
+
.options=${options}
|
|
229
|
+
openLeft
|
|
230
|
+
openTop
|
|
231
|
+
></obc-split-button>`
|
|
232
|
+
)}
|
|
233
|
+
</div>`
|
|
234
|
+
);
|
|
235
|
+
const menu = await openMenu(el, dropdown);
|
|
236
|
+
|
|
237
|
+
const menuRect = menu.getBoundingClientRect();
|
|
238
|
+
expect(menuRect.right).toBeCloseTo(el.getBoundingClientRect().right, 0);
|
|
239
|
+
expect(menuRect.bottom).toBeCloseTo(el.getBoundingClientRect().top, 0);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import type {Meta, StoryObj} from '@storybook/web-components-vite';
|
|
2
|
+
import {expect, waitFor} from 'storybook/test';
|
|
2
3
|
import {ObcSplitButton} from './split-button.js';
|
|
3
4
|
import './split-button.js';
|
|
4
|
-
import {html} from 'lit';
|
|
5
|
+
import {html, nothing, type TemplateResult} from 'lit';
|
|
5
6
|
import '../../icons/icon-placeholder.js';
|
|
7
|
+
import '../../icons/icon-command-request.js';
|
|
6
8
|
import {ContextMenuType} from '../context-menu-input/context-menu-input.js';
|
|
7
9
|
|
|
8
|
-
const
|
|
10
|
+
const renderSplitButton = (
|
|
11
|
+
args: StoryObj<ObcSplitButton>['args'],
|
|
12
|
+
dropdownIcon: TemplateResult | typeof nothing = nothing
|
|
13
|
+
) => html`
|
|
9
14
|
<obc-split-button
|
|
10
15
|
.label=${args?.label || ''}
|
|
11
16
|
.hasIcon=${args?.hasIcon || false}
|
|
@@ -19,13 +24,47 @@ const renderWithIcon = (args: StoryObj<ObcSplitButton>['args']) => html`
|
|
|
19
24
|
.menuTitle=${args?.menuTitle || ''}
|
|
20
25
|
.fullWidth=${args?.fullWidth || false}
|
|
21
26
|
.disabled=${args?.disabled || false}
|
|
27
|
+
.primaryDisabled=${args?.primaryDisabled || false}
|
|
28
|
+
.dropdownDisabled=${args?.dropdownDisabled || false}
|
|
22
29
|
.openTop=${args?.openTop || false}
|
|
30
|
+
.openLeft=${args?.openLeft || false}
|
|
23
31
|
.columnGroups=${args?.columnGroups || []}
|
|
24
32
|
>
|
|
25
33
|
<obi-placeholder slot="icon"></obi-placeholder>
|
|
34
|
+
${dropdownIcon}
|
|
26
35
|
</obc-split-button>
|
|
27
36
|
`;
|
|
28
37
|
|
|
38
|
+
const renderWithIcon = (args: StoryObj<ObcSplitButton>['args']) =>
|
|
39
|
+
renderSplitButton(args);
|
|
40
|
+
|
|
41
|
+
const renderWithDropdownIcon = (args: StoryObj<ObcSplitButton>['args']) =>
|
|
42
|
+
renderSplitButton(
|
|
43
|
+
args,
|
|
44
|
+
html`<obi-command-request slot="dropdown-icon"></obi-command-request>`
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
/** A toolbar end: the button sits on the right edge of its container. */
|
|
48
|
+
const rightAligned = (inner: TemplateResult) =>
|
|
49
|
+
html`<div style="display: flex; justify-content: flex-end">${inner}</div>`;
|
|
50
|
+
|
|
51
|
+
/** Opens the menu and checks that it ends on the button's right edge. */
|
|
52
|
+
const openLeftPlay: Story['play'] = async ({canvasElement, userEvent}) => {
|
|
53
|
+
const el = canvasElement.querySelector('obc-split-button')!;
|
|
54
|
+
const dropdown = el
|
|
55
|
+
.shadowRoot!.querySelector('obc-icon-button')!
|
|
56
|
+
.shadowRoot!.querySelector('button')!;
|
|
57
|
+
await userEvent.click(dropdown);
|
|
58
|
+
await waitFor(() =>
|
|
59
|
+
expect(el.shadowRoot!.querySelector('.positioned-menu')).not.toBeNull()
|
|
60
|
+
);
|
|
61
|
+
const menu = el.shadowRoot!.querySelector<HTMLElement>('.positioned-menu')!;
|
|
62
|
+
await expect(menu.getBoundingClientRect().right).toBeCloseTo(
|
|
63
|
+
el.getBoundingClientRect().right,
|
|
64
|
+
0
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
29
68
|
const meta: Meta<ObcSplitButton> = {
|
|
30
69
|
title: 'UI Components/Buttons/Split Button',
|
|
31
70
|
tags: ['autodocs', '6.0', 'beta'],
|
|
@@ -67,10 +106,22 @@ const meta: Meta<ObcSplitButton> = {
|
|
|
67
106
|
description: 'Make button fill container width',
|
|
68
107
|
},
|
|
69
108
|
disabled: {control: 'boolean', description: 'Disable both buttons'},
|
|
109
|
+
primaryDisabled: {
|
|
110
|
+
control: 'boolean',
|
|
111
|
+
description: 'Disable the primary button alone',
|
|
112
|
+
},
|
|
113
|
+
dropdownDisabled: {
|
|
114
|
+
control: 'boolean',
|
|
115
|
+
description: 'Disable the dropdown button alone',
|
|
116
|
+
},
|
|
70
117
|
openTop: {
|
|
71
118
|
control: 'boolean',
|
|
72
119
|
description: 'Open the dropdown above the button',
|
|
73
120
|
},
|
|
121
|
+
openLeft: {
|
|
122
|
+
control: 'boolean',
|
|
123
|
+
description: 'Extend the dropdown to the left of the button',
|
|
124
|
+
},
|
|
74
125
|
selectPerGroup: {
|
|
75
126
|
control: 'boolean',
|
|
76
127
|
description:
|
|
@@ -93,7 +144,10 @@ const meta: Meta<ObcSplitButton> = {
|
|
|
93
144
|
menuTitle: '',
|
|
94
145
|
fullWidth: false,
|
|
95
146
|
disabled: false,
|
|
147
|
+
primaryDisabled: false,
|
|
148
|
+
dropdownDisabled: false,
|
|
96
149
|
openTop: false,
|
|
150
|
+
openLeft: false,
|
|
97
151
|
selectPerGroup: false,
|
|
98
152
|
},
|
|
99
153
|
} satisfies Meta<ObcSplitButton>;
|
|
@@ -179,6 +233,68 @@ export const Disabled: Story = {
|
|
|
179
233
|
render: renderWithIcon,
|
|
180
234
|
};
|
|
181
235
|
|
|
236
|
+
/** Only the primary action is disabled; the menu stays in use. */
|
|
237
|
+
export const PrimaryDisabled: Story = {
|
|
238
|
+
args: {
|
|
239
|
+
label: 'Primary Disabled',
|
|
240
|
+
hasIcon: true,
|
|
241
|
+
primaryDisabled: true,
|
|
242
|
+
},
|
|
243
|
+
render: renderWithIcon,
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/** Only the dropdown is disabled; the primary action stays in use. */
|
|
247
|
+
export const DropdownDisabled: Story = {
|
|
248
|
+
args: {
|
|
249
|
+
label: 'Dropdown Disabled',
|
|
250
|
+
hasIcon: true,
|
|
251
|
+
dropdownDisabled: true,
|
|
252
|
+
},
|
|
253
|
+
render: renderWithIcon,
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
/** A slotted icon replaces the chevron on the dropdown button. */
|
|
257
|
+
export const DropdownIcon: Story = {
|
|
258
|
+
args: {
|
|
259
|
+
label: 'Dropdown Icon',
|
|
260
|
+
},
|
|
261
|
+
render: renderWithDropdownIcon,
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The menu extends to the left, ending on the button's right edge, so a button
|
|
266
|
+
* at the right edge of its container keeps the whole menu on screen.
|
|
267
|
+
*/
|
|
268
|
+
export const OpenLeft: Story = {
|
|
269
|
+
args: {
|
|
270
|
+
label: 'Open Left',
|
|
271
|
+
hasIcon: true,
|
|
272
|
+
openLeft: true,
|
|
273
|
+
},
|
|
274
|
+
render: (args) => rightAligned(renderWithIcon(args)),
|
|
275
|
+
play: openLeftPlay,
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Access control at the end of a toolbar: the action is disabled while the
|
|
280
|
+
* user lacks the access it needs, and the dropdown, with its own icon, offers
|
|
281
|
+
* the ways to request it (#1381).
|
|
282
|
+
*/
|
|
283
|
+
export const CommandAccess: Story = {
|
|
284
|
+
args: {
|
|
285
|
+
label: 'Set Heading',
|
|
286
|
+
hasIcon: true,
|
|
287
|
+
primaryDisabled: true,
|
|
288
|
+
openLeft: true,
|
|
289
|
+
options: [
|
|
290
|
+
{value: 'button', label: 'Request access to button'},
|
|
291
|
+
{value: 'page', label: 'Request access to page'},
|
|
292
|
+
],
|
|
293
|
+
},
|
|
294
|
+
render: (args) => rightAligned(renderWithDropdownIcon(args)),
|
|
295
|
+
play: openLeftPlay,
|
|
296
|
+
};
|
|
297
|
+
|
|
182
298
|
/** Complex flyout menu example. */
|
|
183
299
|
export const FlyoutMenu: Story = {
|
|
184
300
|
args: {
|
|
@@ -37,10 +37,11 @@ export type ObcSplitButtonChangeEvent = CustomEvent<{
|
|
|
37
37
|
* - **Multi-select and group selection:** Allows single or multiple selections in the dropdown, with optional grouping and per-group selection logic.
|
|
38
38
|
* - **Customizable menu content:** Accepts an array of options or column groups, supports icons, subtitles, and multi-column layouts for complex menus.
|
|
39
39
|
* - **Optional icon in primary button:** Add a leading icon to the main button using the `hasIcon` property and `icon` slot.
|
|
40
|
+
* - **Replaceable dropdown icon:** The dropdown button shows a chevron; fill the `dropdown-icon` slot to show another symbol, for example one that says what the menu holds.
|
|
40
41
|
* - **Title bar and menu title:** Optionally display a title bar with close button and custom title text in the dropdown.
|
|
41
42
|
* - **Full width mode:** Can stretch to fill its container using the `fullWidth` property.
|
|
42
|
-
* - **Disabled state:**
|
|
43
|
-
* - **Dropdown positioning:**
|
|
43
|
+
* - **Disabled state:** `disabled` disables both halves; `primaryDisabled` and `dropdownDisabled` disable one half each, so the primary action can be unavailable while the menu stays in use.
|
|
44
|
+
* - **Dropdown positioning:** The menu opens below the button and extends to the right. `openTop` opens it above and `openLeft` extends it to the left, for a button near the bottom or the right edge of its container.
|
|
44
45
|
* - **Selection persistence:** Optionally keeps the selected state visually persistent in the menu.
|
|
45
46
|
* - **Keyboard and pointer accessibility:** Follows standard button and menu accessibility patterns.
|
|
46
47
|
*
|
|
@@ -62,14 +63,25 @@ export type ObcSplitButtonChangeEvent = CustomEvent<{
|
|
|
62
63
|
* - **TODO(designer):** Confirm best practices for when to use multi-select vs. single-select, and any recommended limits on number of options or columns.
|
|
63
64
|
*
|
|
64
65
|
* ### Slots
|
|
65
|
-
* | Slot Name
|
|
66
|
-
*
|
|
67
|
-
* | `icon`
|
|
66
|
+
* | Slot Name | Renders When... | Purpose |
|
|
67
|
+
* |-----------------|---------------------|-----------------------------------------------------|
|
|
68
|
+
* | `icon` | `hasIcon` is true | Leading icon in the primary button (e.g., `<obi-placeholder></obi-placeholder>`) |
|
|
69
|
+
* | `dropdown-icon` | Always | Icon of the dropdown button; the chevron when empty |
|
|
68
70
|
*
|
|
69
71
|
* ### Events
|
|
70
72
|
* - `click` – Fired when either the primary or dropdown button is clicked. The event detail includes `{action: 'primary' | 'dropdown'}` to distinguish which part was activated.
|
|
71
73
|
* - `change` – Fired when the menu selection changes. The event detail includes `{selectedValues, selectedOptions}`.
|
|
72
74
|
*
|
|
75
|
+
* ### Keyboard
|
|
76
|
+
* The primary half is a plain button. The dropdown half follows the
|
|
77
|
+
* [APG Menu Button](https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/):
|
|
78
|
+
* `Enter` and `Space` open the menu, `ArrowDown` and `Home` open it on the
|
|
79
|
+
* first item, `ArrowUp` and `End` on the last, and `Escape` closes it and
|
|
80
|
+
* returns focus to the dropdown half. The menu is `obc-context-menu-input`.
|
|
81
|
+
*
|
|
82
|
+
* Left out: `Enter` and `Space` land on the selected item rather than the
|
|
83
|
+
* first, so a reopened selection menu starts where the user left it.
|
|
84
|
+
*
|
|
73
85
|
* ### Best Practices & Constraints
|
|
74
86
|
* - Only use multi-select when the menu type and use case require it; otherwise, prefer single selection for clarity.
|
|
75
87
|
* - Keep the primary action clear and distinct from dropdown actions.
|
|
@@ -120,13 +132,23 @@ export type ObcSplitButtonChangeEvent = CustomEvent<{
|
|
|
120
132
|
* When true, the component stretches horizontally.
|
|
121
133
|
* @property disabled - Whether both parts of the button are disabled.
|
|
122
134
|
* When true, disables both the primary and dropdown buttons.
|
|
135
|
+
* @property primaryDisabled - Disables the primary button alone, for an action the user
|
|
136
|
+
* cannot take right now while the menu stays in use, for example to ask for the access
|
|
137
|
+
* the action needs.
|
|
138
|
+
* @availableWhen primaryDisabled disabled==false
|
|
139
|
+
* @property dropdownDisabled - Disables the dropdown button alone, leaving the primary action.
|
|
140
|
+
* @availableWhen dropdownDisabled disabled==false
|
|
123
141
|
* @property openTop - Open context menu dropdown above (`true`) or below (`false`) the button.
|
|
124
142
|
* Useful for placement near the bottom of the viewport.
|
|
143
|
+
* @property openLeft - Extend the menu to the left of the dropdown button (`true`), its right
|
|
144
|
+
* edge on the button's right edge, instead of to the right. For a button near the right
|
|
145
|
+
* edge of its container; combines with `openTop`.
|
|
125
146
|
* @property columnGroups - Array of column group definitions for multi-column/grouped menus.
|
|
126
147
|
* Use instead of `options` for grouped or subtitle layouts.
|
|
127
148
|
* @availableWhen columnGroups menuType==MultiWithSubtitles
|
|
128
149
|
* @property dropdownLabel - Accessible name of the dropdown button; the chevron carries none.
|
|
129
150
|
* @slot icon - Leading icon for the primary button (shown when `hasIcon` is true)
|
|
151
|
+
* @slot dropdown-icon - Icon of the dropdown button; the chevron when empty.
|
|
130
152
|
* @fires {ObcSplitButtonClickEvent} click - Fired when the primary or dropdown button is clicked.
|
|
131
153
|
* @fires {ObcSplitButtonChangeEvent} change - Fired when the dropdown menu selection changes.
|
|
132
154
|
* @beta
|
|
@@ -159,8 +181,14 @@ export class ObcSplitButton extends LitElement {
|
|
|
159
181
|
|
|
160
182
|
@property({type: Boolean}) disabled = false;
|
|
161
183
|
|
|
184
|
+
@property({type: Boolean}) primaryDisabled = false;
|
|
185
|
+
|
|
186
|
+
@property({type: Boolean}) dropdownDisabled = false;
|
|
187
|
+
|
|
162
188
|
@property({type: Boolean}) openTop = false;
|
|
163
189
|
|
|
190
|
+
@property({type: Boolean}) openLeft = false;
|
|
191
|
+
|
|
164
192
|
@property({type: Array}) columnGroups: ColumnGroup[] = [];
|
|
165
193
|
|
|
166
194
|
@state() private isDropdownOpen = false;
|
|
@@ -173,6 +201,14 @@ export class ObcSplitButton extends LitElement {
|
|
|
173
201
|
|
|
174
202
|
@query('.dropdown-button') private dropdownButton?: HTMLElement;
|
|
175
203
|
|
|
204
|
+
private get isPrimaryDisabled(): boolean {
|
|
205
|
+
return this.disabled || this.primaryDisabled;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private get isDropdownDisabled(): boolean {
|
|
209
|
+
return this.disabled || this.dropdownDisabled;
|
|
210
|
+
}
|
|
211
|
+
|
|
176
212
|
private handlePrimaryClick = (e: Event) => {
|
|
177
213
|
e.stopPropagation();
|
|
178
214
|
this.dispatchEvent(
|
|
@@ -200,6 +236,9 @@ export class ObcSplitButton extends LitElement {
|
|
|
200
236
|
|
|
201
237
|
private async focusMenuAfterOpen() {
|
|
202
238
|
await this.updateComplete;
|
|
239
|
+
// The menu is created on open; its items can take focus only once it has
|
|
240
|
+
// rendered them, which this host's own update does not wait for.
|
|
241
|
+
await this.menu?.updateComplete;
|
|
203
242
|
if (!this.isDropdownOpen) return;
|
|
204
243
|
|
|
205
244
|
if (this.menuFocusStrategy === 'last') {
|
|
@@ -214,7 +253,7 @@ export class ObcSplitButton extends LitElement {
|
|
|
214
253
|
}
|
|
215
254
|
|
|
216
255
|
private handleDropdownKeydown = (event: KeyboardEvent) => {
|
|
217
|
-
if (this.
|
|
256
|
+
if (this.isDropdownDisabled) return;
|
|
218
257
|
|
|
219
258
|
switch (event.key) {
|
|
220
259
|
case 'ArrowDown':
|
|
@@ -334,6 +373,7 @@ export class ObcSplitButton extends LitElement {
|
|
|
334
373
|
'full-width': this.fullWidth,
|
|
335
374
|
'is-open': this.isDropdownOpen,
|
|
336
375
|
'open-top': this.openTop,
|
|
376
|
+
'open-left': this.openLeft,
|
|
337
377
|
})}
|
|
338
378
|
>
|
|
339
379
|
<obc-button
|
|
@@ -341,7 +381,7 @@ export class ObcSplitButton extends LitElement {
|
|
|
341
381
|
.variant=${'normal'}
|
|
342
382
|
.segmentPosition=${segmentPosition.start}
|
|
343
383
|
.showLeadingIcon=${this.hasIcon}
|
|
344
|
-
.disabled=${this.
|
|
384
|
+
.disabled=${this.isPrimaryDisabled}
|
|
345
385
|
@click=${this.handlePrimaryClick}
|
|
346
386
|
.fullWidth=${this.fullWidth}
|
|
347
387
|
>
|
|
@@ -357,7 +397,7 @@ export class ObcSplitButton extends LitElement {
|
|
|
357
397
|
class="dropdown-button"
|
|
358
398
|
.variant=${'normal'}
|
|
359
399
|
.cornerRight=${true}
|
|
360
|
-
.disabled=${this.
|
|
400
|
+
.disabled=${this.isDropdownDisabled}
|
|
361
401
|
.activated=${this.isDropdownOpen}
|
|
362
402
|
aria-label=${this.dropdownLabel}
|
|
363
403
|
@click=${this.handleDropdownClick}
|
|
@@ -365,7 +405,11 @@ export class ObcSplitButton extends LitElement {
|
|
|
365
405
|
aria-expanded=${this.isDropdownOpen}
|
|
366
406
|
aria-haspopup="menu"
|
|
367
407
|
>
|
|
368
|
-
<
|
|
408
|
+
<slot name="dropdown-icon">
|
|
409
|
+
<obi-arrow-flyout-google
|
|
410
|
+
aria-hidden="true"
|
|
411
|
+
></obi-arrow-flyout-google>
|
|
412
|
+
</slot>
|
|
369
413
|
</obc-icon-button>
|
|
370
414
|
|
|
371
415
|
<!-- Context Menu -->
|
|
@@ -3,6 +3,7 @@ import './textarea-field.js';
|
|
|
3
3
|
import {ObcTextareaField} from './textarea-field.js';
|
|
4
4
|
import {render} from 'vitest-browser-lit';
|
|
5
5
|
import {html} from 'lit';
|
|
6
|
+
import {containsDeep, deepActiveElement} from '../../internal/_test-utils.js';
|
|
6
7
|
|
|
7
8
|
describe('obc-textarea-field', () => {
|
|
8
9
|
let el: ObcTextareaField;
|
|
@@ -131,4 +132,33 @@ describe('obc-textarea-field', () => {
|
|
|
131
132
|
expect(changeHandler).toHaveBeenCalled();
|
|
132
133
|
});
|
|
133
134
|
});
|
|
135
|
+
|
|
136
|
+
describe('recording focus', () => {
|
|
137
|
+
// The hand-off runs a frame after the update, then the focused control
|
|
138
|
+
// sits inside the icon button's shadow root.
|
|
139
|
+
const afterFrame = () =>
|
|
140
|
+
new Promise((resolve) =>
|
|
141
|
+
requestAnimationFrame(() => setTimeout(resolve))
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
it('moves focus to the first action button when recording starts, and back to the textarea when it ends', async () => {
|
|
145
|
+
el.showVoiceRecording = true;
|
|
146
|
+
el.recording = true;
|
|
147
|
+
await el.updateComplete;
|
|
148
|
+
await afterFrame();
|
|
149
|
+
|
|
150
|
+
const firstAction = el.shadowRoot!.querySelector(
|
|
151
|
+
'.action-container obc-icon-button'
|
|
152
|
+
)!;
|
|
153
|
+
expect(containsDeep(firstAction, deepActiveElement())).toBe(true);
|
|
154
|
+
|
|
155
|
+
el.recording = false;
|
|
156
|
+
await el.updateComplete;
|
|
157
|
+
await afterFrame();
|
|
158
|
+
|
|
159
|
+
expect(deepActiveElement()).toBe(
|
|
160
|
+
el.shadowRoot!.querySelector('.input-field')
|
|
161
|
+
);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
134
164
|
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {afterEach, describe, expect, it} from 'vitest';
|
|
2
|
+
import './top-bar.js';
|
|
3
|
+
import type {ObcTopBar} from './top-bar.js';
|
|
4
|
+
|
|
5
|
+
const cleanup: Array<() => void> = [];
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
while (cleanup.length) cleanup.pop()!();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
async function mount(init: (bar: ObcTopBar) => void = () => {}) {
|
|
11
|
+
const bar = document.createElement('obc-top-bar') as ObcTopBar;
|
|
12
|
+
init(bar);
|
|
13
|
+
document.body.append(bar);
|
|
14
|
+
cleanup.push(() => bar.remove());
|
|
15
|
+
await bar.updateComplete;
|
|
16
|
+
const button = bar.shadowRoot!.querySelector<HTMLElement>('.more-button')!;
|
|
17
|
+
return {bar, button};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('obc-top-bar more button', () => {
|
|
21
|
+
it('fires more-button-clicked and the deprecated left-more-button-clicked', async () => {
|
|
22
|
+
const {bar, button} = await mount();
|
|
23
|
+
const events: string[] = [];
|
|
24
|
+
bar.addEventListener('more-button-clicked', () =>
|
|
25
|
+
events.push('more-button-clicked')
|
|
26
|
+
);
|
|
27
|
+
bar.addEventListener('left-more-button-clicked', () =>
|
|
28
|
+
events.push('left-more-button-clicked')
|
|
29
|
+
);
|
|
30
|
+
button.click();
|
|
31
|
+
expect(events).toEqual(['more-button-clicked', 'left-more-button-clicked']);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('exposes both the more-button and the deprecated left-more-button part', async () => {
|
|
35
|
+
const {button} = await mount();
|
|
36
|
+
expect(button.part.contains('more-button')).toBe(true);
|
|
37
|
+
expect(button.part.contains('left-more-button')).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('moreButtonActivated activates the button', async () => {
|
|
41
|
+
const {bar, button} = await mount((bar) => {
|
|
42
|
+
bar.moreButtonActivated = true;
|
|
43
|
+
});
|
|
44
|
+
expect(button.hasAttribute('activated')).toBe(true);
|
|
45
|
+
bar.moreButtonActivated = false;
|
|
46
|
+
await bar.updateComplete;
|
|
47
|
+
expect(button.hasAttribute('activated')).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('the deprecated leftMoreButtonActivated still activates the button', async () => {
|
|
51
|
+
const {bar, button} = await mount((bar) => {
|
|
52
|
+
bar.setAttribute('leftMoreButtonActivated', '');
|
|
53
|
+
});
|
|
54
|
+
expect(bar.moreButtonActivated).toBe(true);
|
|
55
|
+
expect(button.hasAttribute('activated')).toBe(true);
|
|
56
|
+
bar.leftMoreButtonActivated = false;
|
|
57
|
+
await bar.updateComplete;
|
|
58
|
+
expect(button.hasAttribute('activated')).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
/* Controls never shrink: a squeeze reaches the texts, then overflows the end */
|
|
68
68
|
.menu-button,
|
|
69
69
|
.app-icon,
|
|
70
|
-
.
|
|
70
|
+
.more-button,
|
|
71
71
|
.dimming-button,
|
|
72
72
|
.user-button,
|
|
73
73
|
.apps-button,
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
@mixin font-body-active;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
.
|
|
112
|
+
.more-button {
|
|
113
113
|
display: none;
|
|
114
114
|
}
|
|
115
115
|
|