feat: migrate button groups and toggle buttons with focus regressions
This commit is contained in:
@@ -459,3 +459,74 @@ it("renders ScrollShadow and Tabs without browser globals and resolves initial p
|
||||
expect(controls).toBeTruthy();
|
||||
expect(html).toContain(`id="${controls}"`);
|
||||
});
|
||||
|
||||
it("renders ButtonGroup and Toggle families without browser globals", async () => {
|
||||
const {
|
||||
Button,
|
||||
ButtonGroup,
|
||||
ButtonGroupSeparator,
|
||||
ToggleButton,
|
||||
ToggleButtonGroup,
|
||||
ToggleButtonGroupSeparator,
|
||||
} = await import("../packages/vue/src");
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () => [
|
||||
h(ButtonGroup, { size: "sm", variant: "secondary" }, () => [
|
||||
h(Button, () => "First"),
|
||||
h(Button, () => [h(ButtonGroupSeparator), "Second"]),
|
||||
]),
|
||||
h(ToggleButton, { defaultSelected: true }, () => "Like"),
|
||||
h(
|
||||
ToggleButtonGroup,
|
||||
{ selectionMode: "multiple", defaultSelectedKeys: ["bold"] },
|
||||
() => [
|
||||
h(ToggleButton, { id: "bold" }, () => "Bold"),
|
||||
h(ToggleButton, { id: "italic" }, () => [
|
||||
h(ToggleButtonGroupSeparator),
|
||||
"Italic",
|
||||
]),
|
||||
],
|
||||
),
|
||||
],
|
||||
}),
|
||||
);
|
||||
expect(html).toContain('data-slot="button-group"');
|
||||
expect(html).toContain("hv-button--sm");
|
||||
expect(html).toContain("hv-button--secondary");
|
||||
expect(html).toContain('data-slot="button-group-separator"');
|
||||
expect(html).toContain('aria-pressed="true"');
|
||||
expect(html).toContain('data-slot="toggle-button-group"');
|
||||
expect(html).toContain('role="toolbar"');
|
||||
expect(html).toContain('data-selected="true"');
|
||||
expect(html).toContain('data-slot="toggle-button-group-separator"');
|
||||
});
|
||||
|
||||
it("keeps ToggleButton group keys out of DOM ids on the server", async () => {
|
||||
const { ToggleButton, ToggleButtonGroup } =
|
||||
await import("../packages/vue/src");
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(ToggleButtonGroup, { selectionMode: "multiple" }, () => [
|
||||
h(ToggleButton, { id: 1 }, () => "number"),
|
||||
h(ToggleButton, { id: "1" }, () => "string"),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
expect(html).not.toMatch(/id="1"/);
|
||||
expect(html).toContain("number");
|
||||
expect(html).toContain("string");
|
||||
const ids = [...html.matchAll(/id="([^"]+)"/g)].map((m) => m[1]);
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
});
|
||||
|
||||
it("keeps standalone ToggleButton DOM ids stable on the server", async () => {
|
||||
const { ToggleButton } = await import("../packages/vue/src");
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () => h(ToggleButton, { id: "like-toggle" }, () => "Like"),
|
||||
}),
|
||||
);
|
||||
expect(html).toContain('id="like-toggle"');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user