fix: disable link navigation and align breadcrumb actions and date focus

This commit is contained in:
maoyingjie
2026-10-29 09:03:52 +08:00
parent 680a592e7b
commit 68d45c66f9
27 changed files with 983 additions and 44 deletions
@@ -2,6 +2,7 @@ import { describe, it, expect, vi, afterEach } from "vitest";
import { mount } from "@vue/test-utils";
import { defineComponent, h, nextTick, ref } from "vue";
import {
ConfigProvider,
Breadcrumbs,
BreadcrumbsItem,
EmptyState,
@@ -799,3 +800,84 @@ describe("Breadcrumbs", () => {
w.unmount();
});
});
it("localizes breadcrumb labels dynamically while explicit names take precedence", async () => {
const locale = ref("en-US"),
label = ref<string>();
const w = mount(
defineComponent({
render: () =>
h(ConfigProvider, { locale: locale.value }, () =>
h(Breadcrumbs, { "aria-label": label.value }, () =>
h(BreadcrumbsItem, {}, () => "current"),
),
),
}),
);
try {
expect(w.get("ol").attributes("aria-label")).toBe("Breadcrumbs");
locale.value = "zh-CN";
await nextTick();
expect(w.get("ol").attributes("aria-label")).toBe("导航栏");
label.value = "自定义路径";
await nextTick();
locale.value = "fr-FR";
await nextTick();
expect(w.get("ol").attributes("aria-label")).toBe("自定义路径");
label.value = "";
await nextTick();
expect(w.get("ol").attributes("aria-label")).toBe("Chemin de navigation");
} finally {
w.unmount();
}
});
it("emits one breadcrumb action preserving zero/empty identities, respecting cancellation and disabled/current items", async () => {
const action = vi.fn(),
disabled = ref(false),
cancel = ref(false);
const w = mount(
defineComponent({
render: () =>
h(Breadcrumbs, { isDisabled: disabled.value, onAction: action }, () => [
h(
BreadcrumbsItem,
{
key: 0,
onClick: (e: Event) => {
if (cancel.value) e.preventDefault();
},
},
() => "zero",
),
h(BreadcrumbsItem, { key: "" }, () => "empty"),
h(
BreadcrumbsItem,
{ key: "string-key", id: "0" },
() => "string zero",
),
h(BreadcrumbsItem, { key: "current" }, () => "current"),
]),
}),
{ attachTo: document.body },
);
try {
const links = () => w.findAll('[data-slot="link"]');
await links()[0].trigger("click");
expect(action).toHaveBeenLastCalledWith(0);
await links()[1].trigger("keydown", { key: "Enter" });
expect(action).toHaveBeenLastCalledWith("");
await links()[2].trigger("click");
expect(action).toHaveBeenLastCalledWith("0");
expect(action).toHaveBeenCalledTimes(3);
cancel.value = true;
await nextTick();
await links()[0].trigger("click");
await links()[3].trigger("click");
disabled.value = true;
await nextTick();
await links()[1].trigger("click");
expect(action).toHaveBeenCalledTimes(3);
} finally {
w.unmount();
}
});