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
+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();
});
});