fix(pickers): repair data-slot selectors and align demos with the baseline

The CSS port prefixed data-slot attribute values with hv-, so the compiled
selectors never matched the DOM and the ComboBox trigger chevron never
rotated. Only class names get the prefix; slot values stay byte-identical.

Also commit typed text as the value when allowsCustomValue finds no record,
restore the baseline search-field shell in all 24 Autocomplete demos, and
correct both doc pages against the pinned upstream sources.
This commit is contained in:
maoyingjie
2026-10-25 17:46:32 +08:00
parent 5e688680e9
commit 3e9be13b19
40 changed files with 634 additions and 225 deletions
+22
View File
@@ -64,6 +64,28 @@ describe("Autocomplete docs and demos", () => {
}
});
it("uses the baseline search field shell and empty state in every demo", () => {
for (const name of previews) {
const source = readFileSync(
`apps/docs/demos/autocomplete-${name}.vue`,
"utf8",
);
// Upstream renders SearchField autoFocus name="search" variant="secondary"
// with a clear button; the popover filter must keep that whole shell.
const fields = [...source.matchAll(/<SearchField\b[^>]*>/g)];
expect(fields.length, name).toBeGreaterThan(0);
for (const [tag] of fields) {
expect(tag, name).toMatch(/\bvariant="secondary"/);
expect(tag, name).toMatch(/\bname="search"/);
expect(tag, name).toMatch(/\bauto-focus/);
}
expect(source, name).toContain("SearchFieldClearButton");
// The ported .hv-empty-state padding must not be overridden per demo.
expect(source, name).not.toMatch(/<EmptyState\s+class=/);
expect(source, name).not.toContain("alert(");
}
});
it("documents Vue props instead of React ones", () => {
const document = readFileSync(
"apps/docs/components/autocomplete.md",
+29
View File
@@ -1,5 +1,6 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { mount } from "@vue/test-utils";
import { readFileSync } from "node:fs";
import { defineComponent, h, nextTick, ref, type Component } from "vue";
import {
Autocomplete,
@@ -664,3 +665,31 @@ describe("Autocomplete composition", () => {
expect(valueText()).toBe("选择州/省");
});
});
describe("Autocomplete ported style hooks", () => {
it("emits the data-slot values the ported CSS targets", async () => {
const css = readFileSync(
"packages/styles/components/autocomplete.css",
"utf8",
);
// Only class names carry the hv- prefix: data-slot values are a DOM
// contract, so a prefixed value would leave the ported rules dead.
expect(css).not.toMatch(/data-slot="hv-/);
expect(css).toContain('&[data-slot="autocomplete-default-indicator"]');
expect(css).toContain('[data-slot="autocomplete-clear-button-icon"]');
track(shell({ defaultValue: "texas" }));
await nextTick();
await settle();
expect(
document.querySelector(
'[data-slot="autocomplete-indicator"] [data-slot="autocomplete-default-indicator"]',
),
).not.toBeNull();
expect(
document.querySelector('[data-slot="autocomplete-clear-button-icon"]'),
).not.toBeNull();
});
});
+59 -1
View File
@@ -1,5 +1,6 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { mount } from "@vue/test-utils";
import { readFileSync } from "node:fs";
import { defineComponent, h, nextTick, ref } from "vue";
import {
ComboBox,
@@ -216,7 +217,36 @@ describe("ComboBox input semantics", () => {
await press("ArrowDown");
await press("Enter");
await type("独角兽");
expect(onChange).not.toHaveBeenLastCalledWith(null);
// Typing a non-matching value must not clear the accepted custom text.
expect(onChange).toHaveBeenLastCalledWith("cat");
expect(input().value).toBe("独角兽");
});
it("commits a typed custom value with Enter", async () => {
const onChange = vi.fn();
mountCombo({ allowsCustomValue: true, onSelectionChange: onChange });
await nextTick();
input().focus();
await type("独角兽");
await press("Enter");
// The typed text itself becomes the value, like the baseline.
expect(onChange).toHaveBeenLastCalledWith("独角兽");
expect(input().value).toBe("独角兽");
expect(input().getAttribute("aria-expanded")).toBe("false");
});
it("commits the typed text when the filter excluded every record", async () => {
const onChange = vi.fn();
mountCombo({ allowsCustomValue: true, onSelectionChange: onChange });
await nextTick();
input().focus();
await press("ArrowDown");
// The accepted row is filtered out, so the custom text must still commit.
await type("独角兽");
await press("Enter");
expect(onChange).toHaveBeenLastCalledWith("独角兽");
expect(input().value).toBe("独角兽");
});
});
@@ -655,3 +685,31 @@ describe("ComboBox menu trigger", () => {
expect(input().getAttribute("aria-expanded")).toBe("true");
});
});
describe("ComboBox ported style hooks", () => {
it("emits the data-slot values the ported CSS targets", async () => {
const css = readFileSync(
"packages/styles/components/combo-box.css",
"utf8",
);
// Only class names carry the hv- prefix: data-slot values are a DOM
// contract, so a prefixed value would leave the ported rules dead.
expect(css).not.toMatch(/data-slot="hv-/);
expect(css).toContain(
'&[data-open="true"] [data-slot="combo-box-trigger-default-icon"]',
);
mountCombo();
await nextTick();
input().focus();
await nextTick();
await settle();
const trigger = document.querySelector('[data-slot="combo-box-trigger"]')!;
expect(trigger.getAttribute("data-open")).toBe("true");
expect(
trigger.querySelector('[data-slot="combo-box-trigger-default-icon"]'),
).not.toBeNull();
});
});